Created
December 13, 2018 03:49
-
-
Save gregberns/12c1f674c52e7ae01b53db1f20054555 to your computer and use it in GitHub Desktop.
An implementation of the Either 'rights' function that is slow
This file contains hidden or 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Article on why this is slow.
https://medium.com/@gregberns/purescript-performance-with-foldl-to-get-rights-845118bf87e5