Here is my attempt to implement Maybe monad in elisp. It it function composition that breaks on first nil. However value
is always 13
. Where is my error?
(defun .compose-maybe (&rest funcs)
"Monad Maybe function composition with nil as Nothing."
(lambda (arg)
(if funcs
(let ((value (funcall (apply #'.compose-maybe (cdr funcs)) arg)))
(message "%s" value)
(when value (funcall (car funcs) value))))
arg))
(funcall (.compose-maybe (lambda (x) (* x 5)) (lambda (x) (+ 100 x))) 13)