Skip to content

add \/ alias for either function #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"test": "pulp test"
},
"devDependencies": {
"pulp": "^12.2.0",
"purescript-psa": "^0.6.0",
"rimraf": "^2.6.2"
"pulp": "^15.0.0",
"purescript-psa": "^0.7.3",
"rimraf": "^3.0.2"
}
}
21 changes: 19 additions & 2 deletions src/Data/Either/Nested.purs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,35 @@
-- | toEither3 (Blue v) = in3 v
-- | ```
module Data.Either.Nested
( type (\/)
( type (\/), (\/)
, in1, in2, in3, in4, in5, in6, in7, in8, in9, in10
, at1, at2, at3, at4, at5, at6, at7, at8, at9, at10
, Either1, Either2, Either3, Either4, Either5, Either6, Either7, Either8, Either9, Either10
, either1, either2, either3, either4, either5, either6, either7, either8, either9, either10
) where

import Data.Either (Either(..))
import Data.Either (Either(..), either)
import Data.Void (Void, absurd)

infixr 6 type Either as \/

-- | The `\/` operator alias for the `either` function allows easy matching on nested Eithers. For example, consider the function
-- |
-- | ```purescript
-- | f :: (Int \/ String \/ Boolean) -> String
-- | f (Left x) = show x
-- | f (Right (Left y)) = y
-- | f (Right (Right z)) = if z then "Yes" else "No"
-- | ```
-- |
-- | The `\/` operator alias allows us to rewrite this function as
-- |
-- | ```purescript
-- | f :: (Int \/ String \/ Boolean) -> String
-- | f = show \/ identity \/ if _ then "Yes" else "No"
-- | ```
infixr 6 either as \/

type Either1 a = a \/ Void
type Either2 a b = a \/ b \/ Void
type Either3 a b c = a \/ b \/ c \/ Void
Expand Down