flatmap   xtlang


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

Implementation

;; also known as bind in haskell
(bind-func flatmap:[List{!b}*,List{!a}*,[List{!b}*,!a]*]*
  (lambda (M f)
    ;; alternative 'direct' implementation
    ;; (Cons$ M (x xs) (append (f x) (flatmap xs f)) (Nil))))
    (join (fmap f M))))


Back to Index

Similar Entries