Last active
May 8, 2020 20:17
-
-
Save chiroptical/2a921faa08976f6a176557fe57bb6021 to your computer and use it in GitHub Desktop.
Find first `Just` embedded in `[m (Maybe a)]`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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