Skip to content

Instantly share code, notes, and snippets.

@gregberns
Created December 13, 2018 03:49
Show Gist options
  • Save gregberns/12c1f674c52e7ae01b53db1f20054555 to your computer and use it in GitHub Desktop.
Save gregberns/12c1f674c52e7ae01b53db1f20054555 to your computer and use it in GitHub Desktop.
An implementation of the Either 'rights' function that is slow
import Data.Array (snoc)
import Data.Either (Either(..))
rights :: forall a b. Array (Either a b) -> Array b
rights array =
let
f (Left _) accumulator = accumulator
f (Right value) accumulator = snoc accumulator value
in
foldr f [] array
-- See this gist for the fast implementation
-- https://gist.github.com/gregberns/58c5a5701e545aa757d8a54bf61bebc2
@gregberns
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment