# ContingentClaims.Core.Util.Recursion¶

This module collects a set of utilities used to execute recursion schemes. The morphisms ending in ‘M’ are monadic variants, allowing to interleave, e.g., `Update` or `Script`. `cataM` after Tim Williams’ talk, https://www.youtube.com/watch?v=Zw9KeP3OzpU.

## Functions¶

paraM

: (Monad m, Traversable f, Recursive b f) => (f (b, a) -> m a) -> b -> m a

anaM

: (Monad m, Traversable f, Corecursive b f) => (a -> m (f a)) -> a -> m b

apoM

: (Monad m, Traversable f, Corecursive b f) => (a -> m (f (Either b a))) -> a -> m b

futuM

: (Monad m, Traversable f, Corecursive b f) => (a -> m (f (Free f a))) -> a -> m b

apoCataM

: (Monad m, Traversable f, Corecursive b f) => (f b -> b) -> (a -> m (f (Either b a))) -> a -> m b

Monadic lazy unfold (apoM) followed by a fold (cata). This Specialised lazy re-fold is used by `lifecycle`.

hyloM

: (Traversable f, Monad n) => (f b -> b) -> (a -> n (f a)) -> a -> n b

A modified `hylo` (refold), whith an interleaved monad effect (typically `Update`).

ghyloM

: (Comonad w, Traversable f, Monad m, Traversable m, Monad n) => (f (w c) -> w (f c)) -> (m (f d) -> f (m d)) -> (f (w b) -> b) -> (a -> n (f (m a))) -> a -> n b

funzip

: Functor f => f (a, b) -> (f a, f b)

Functor unzip.

synthesize

: (Functor f, Recursive b f) => (f attr -> attr) -> b -> Cofree f attr

Annotate a recursive type bottom-up.

inherit

: (Functor f, Corecursive b f, Recursive b f) => (b -> attr -> attr) -> attr -> b -> Cofree f attr

Annotate a recursive type top-down.