Skip to content

Instantly share code, notes, and snippets.

@Solonarv
Created January 11, 2016 18:42
Show Gist options
  • Save Solonarv/b9c4a0ed2ee061e81d15 to your computer and use it in GitHub Desktop.
Save Solonarv/b9c4a0ed2ee061e81d15 to your computer and use it in GitHub Desktop.
-- formulate in standard style, as a mental crutch
tryUntilSuccess :: [a -> Either e b] -> a -> Either [e] b
tryUntilSuccess fs x = let ys = map ($ x) fs
in case dropWhile isLeft ys of
[] -> Left $ lefts $ takeWhile isLeft ys
(Right y):_ -> Right y
-- Formulate in simply polymorphic CPS next
-- This is the signature of the... thing... I'm trying to write
tryUntilSuccessCPS :: [a -> (Either f b -> c) -> c] -> ((a -> (Either [f] b -> e) -> e) -> d) -> d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment