Skip to content

Instantly share code, notes, and snippets.

@mankyKitty
Last active January 7, 2016 10:42
Show Gist options
  • Save mankyKitty/30503fcaa11b0d1e8f45 to your computer and use it in GitHub Desktop.
Save mankyKitty/30503fcaa11b0d1e8f45 to your computer and use it in GitHub Desktop.
An effect permitting unfold ???
import Control.Lens.Cons (Cons (..), cons, (<|))
import Data.Maybe (maybe)
import Data.Monoid (Monoid)
unfoldM :: (Cons s s a a, Monoid s, Monad m) => (b -> m (Maybe (a,b))) -> b -> m s
unfoldM f b = maybe (return mempty) (\(a,b') -> cons a <$> unfoldM f b') =<< f b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment