Skip to content

Instantly share code, notes, and snippets.

@dmwit
Created February 19, 2019 15:54
Show Gist options
  • Save dmwit/44afc00dd3e58609084f43357db4003d to your computer and use it in GitHub Desktop.
Save dmwit/44afc00dd3e58609084f43357db4003d to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleInstances #-}
import Data.Functor.Compose
import Control.Monad
joinEntry :: Maybe [Maybe [a]] -> Maybe [a]
joinEntry = fmap join . join . fmap sequenceA
instance Monad (Compose Maybe []) where
-- or use liberal applications of coerce to avoid the calls to Compose and getCompose
x >>= f = Compose . joinEntry . getCompose . fmap (getCompose . f) $ x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment