Skip to content

Instantly share code, notes, and snippets.

@PiDelport
Last active August 18, 2016 13:47
Show Gist options
  • Save PiDelport/f24f1a92e58f21f73c38a85d15781302 to your computer and use it in GitHub Desktop.
Save PiDelport/f24f1a92e58f21f73c38a85d15781302 to your computer and use it in GitHub Desktop.

Revisions

  1. PiDelport revised this gist Aug 13, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sequenceRights.hs
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ sequenceRights [] = pure (pure [])
    sequenceRights (x:xs) = handle =<< x
    where
    handle (Left e) = pure (Left e)
    handle (Right t) = (t:) <<$>> blah xs
    handle (Right t) = (t:) <<$>> sequenceRights xs


    -- This should be in a standard library somewhere.
  2. PiDelport created this gist Aug 13, 2016.
    13 changes: 13 additions & 0 deletions sequenceRights.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    -- Sequence a list of Either-yielding monadic actions.
    -- Sequencing stops on the first Left value, or yields a list successful Right values.
    sequenceRights :: Monad m => [m (Either e t)] -> m (Either e [t])
    sequenceRights [] = pure (pure [])
    sequenceRights (x:xs) = handle =<< x
    where
    handle (Left e) = pure (Left e)
    handle (Right t) = (t:) <<$>> blah xs


    -- This should be in a standard library somewhere.
    (<<$>>) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b)
    (<<$>>) = fmap . fmap