Skip to content

Instantly share code, notes, and snippets.

@gregberns
Created December 13, 2018 03:49
Show Gist options
  • Save gregberns/58c5a5701e545aa757d8a54bf61bebc2 to your computer and use it in GitHub Desktop.
Save gregberns/58c5a5701e545aa757d8a54bf61bebc2 to your computer and use it in GitHub Desktop.
A implementation of the Either 'rights' and 'lefts' functions
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
@gregberns
Copy link
Author

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