Skip to content

Instantly share code, notes, and snippets.

@chiroptical
Last active May 8, 2020 20:17
Show Gist options
  • Save chiroptical/2a921faa08976f6a176557fe57bb6021 to your computer and use it in GitHub Desktop.
Save chiroptical/2a921faa08976f6a176557fe57bb6021 to your computer and use it in GitHub Desktop.
Find first `Just` embedded in `[m (Maybe a)]`
{-# LANGUAGE LambdaCase #-}
module FindJust ( findJust ) where
import Control.Monad ( foldM )
findJust :: Monad m => [m (Maybe a)] -> m (Maybe a)
findJust = foldM (\acc x -> maybe x (pure . Just) acc) Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment