Created
December 13, 2018 03:49
-
-
Save gregberns/58c5a5701e545aa757d8a54bf61bebc2 to your computer and use it in GitHub Desktop.
A implementation of the Either 'rights' and 'lefts' functions
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.Either (Either(..), either, hush) | |
import Data.Array (mapMaybe) | |
import Data.Maybe (Maybe(..)) | |
rights :: forall a b. Array (Either a b) -> Array b | |
rights array = mapMaybe hush array | |
-- Also the Lefts implementation | |
lefts :: forall a b. Array (Either a b) -> Array a | |
lefts array = mapMaybe (either Just (const Nothing)) array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Article discussing a bit more.
https://medium.com/@gregberns/purescript-performance-with-foldl-to-get-rights-845118bf87e5