This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
1.0.0 1.0.1
README

Either

A simple module providing an Either type.

Types

type Either a b = Left a | Right b

For when you want a function that needs to take/return values of two different types and you don't want to define a whole type.

Maps

mapLeft : (a -> a') -> Either a b -> Either a' b

There's only one possible implementation of this function! Try to guess what it is.

mapRight : (b -> b') -> Either a b -> Either a b'

There's only one possible implementation of this function! Try to guess what it is.

mapBoth : (a -> a') -> (b -> b') -> Either a b -> Either a' b'

There's only one possible implementation of this function! Try to guess what it is.

Elimination

elim : (a -> c) -> (b -> c) -> Either a b -> c

There's only one possible implementation of this function! Try to guess what it is.

isLeft : Either a b -> Bool
isRight : Either a b -> Bool
module Either exposing (..)

{-| A simple module providing an Either type.

# Types
@docs Either

# Maps
@docs mapLeft, mapRight, mapBoth

# Elimination
@docs elim, isLeft, isRight
-}

{-| For when you want a function that needs to take/return values of
    two different types and you don't want to define a whole type. -}
type Either a b
  = Left a
  | Right b

{-| There's only one possible implementation of this function! Try to guess
    what it is. -}
mapRight : (b -> b') -> Either a b -> Either a b'
mapRight f ex = case ex of
  Left a  -> Left a
  Right b -> Right (f b)

{-| There's only one possible implementation of this function! Try to guess
    what it is. -}
mapLeft : (a -> a') -> Either a b -> Either a' b
mapLeft f ex = case ex of
  Left a  -> Left (f a)
  Right b -> Right b

{-| There's only one possible implementation of this function! Try to guess
    what it is. -}
mapBoth : (a -> a') -> (b -> b') -> Either a b -> Either a' b'
mapBoth f g ex = case ex of
  Left a  -> Left (f a)
  Right b -> Right (g b)

{-| There's only one possible implementation of this function! Try to guess
    what it is. -}
elim : (a -> c) -> (b -> c) -> Either a b -> c
elim f g ex = case ex of
  Left a  -> f a
  Right b -> g b

{-| -}
isLeft : Either a b -> Bool
isLeft ex = case ex of
  Left _ -> True
  _      -> False
  
{-| -}
isRight : Either a b -> Bool
isRight ex = case ex of
  Right _ -> True
  _       -> False