flatmap   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/examples/contrib/algebraic_data_types.xtm

Implementation

;; also known as bind
;; it's more convenient to have the function in last arg position
(bind-func flatmap:[Option{!b}*,Option{!a}*,[Option{!b}*,!a]*]*
  (lambda (M f)
    ;; (join (fmap f M)))) ;; alternate using join & fmap
    (Some$ M (x) (f x) (None))))


Back to Index

Similar Entries