Module

Data.Either.Nested

Package
purescript-either
Repository
purescript/purescript-either

Utilities for n-eithers: sums types with more than two terms built from nested eithers.

Nested eithers arise naturally in sum combinators. You shouldn't represent sum data using nested eithers, but if combinators you're working with create them, utilities in this module will allow to to more easily work with them, including translating to and from more traditional sum types.

data Color = Red Number | Green Number | Blue Number

fromEither3 :: Either3 Number Number Number -> Color
fromEither3 = either3 Red Green Blue

toEither3 :: Color -> Either3 Number Number Number
toEither3 (Red   v) = in1 v
toEither3 (Green v) = in2 v
toEither3 (Blue  v) = in3 v

#type (\/) Source

Operator alias for Data.Either.Either (right-associative / precedence 6)

#(\/) Source

Operator alias for Data.Either.either (right-associative / precedence 6)

The \/ operator alias for the either function allows easy matching on nested Eithers. For example, consider the function

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

f :: (Int \/ String \/ Boolean) -> String
f = show \/ identity \/ if _ then "Yes" else "No"

#in1 Source

in1 :: forall a z. a -> a \/ z

#in2 Source

in2 :: forall a b z. b -> a \/ b \/ z

#in3 Source

in3 :: forall a b c z. c -> a \/ b \/ c \/ z

#in4 Source

in4 :: forall a b c d z. d -> a \/ b \/ c \/ d \/ z

#in5 Source

in5 :: forall a b c d e z. e -> a \/ b \/ c \/ d \/ e \/ z

#in6 Source

in6 :: forall a b c d e f z. f -> a \/ b \/ c \/ d \/ e \/ f \/ z

#in7 Source

in7 :: forall a b c d e f g z. g -> a \/ b \/ c \/ d \/ e \/ f \/ g \/ z

#in8 Source

in8 :: forall a b c d e f g h z. h -> a \/ b \/ c \/ d \/ e \/ f \/ g \/ h \/ z

#in9 Source

in9 :: forall a b c d e f g h i z. i -> a \/ b \/ c \/ d \/ e \/ f \/ g \/ h \/ i \/ z

#in10 Source

in10 :: forall a b c d e f g h i j z. j -> a \/ b \/ c \/ d \/ e \/ f \/ g \/ h \/ i \/ j \/ z

#at1 Source

at1 :: forall r a z. r -> (a -> r) -> a \/ z -> r

#at2 Source

at2 :: forall r a b z. r -> (b -> r) -> a \/ b \/ z -> r

#at3 Source

at3 :: forall r a b c z. r -> (c -> r) -> a \/ b \/ c \/ z -> r

#at4 Source

at4 :: forall r a b c d z. r -> (d -> r) -> a \/ b \/ c \/ d \/ z -> r

#at5 Source

at5 :: forall r a b c d e z. r -> (e -> r) -> a \/ b \/ c \/ d \/ e \/ z -> r

#at6 Source

at6 :: forall r a b c d e f z. r -> (f -> r) -> a \/ b \/ c \/ d \/ e \/ f \/ z -> r

#at7 Source

at7 :: forall r a b c d e f g z. r -> (g -> r) -> a \/ b \/ c \/ d \/ e \/ f \/ g \/ z -> r

#at8 Source

at8 :: forall r a b c d e f g h z. r -> (h -> r) -> a \/ b \/ c \/ d \/ e \/ f \/ g \/ h \/ z -> r

#at9 Source

at9 :: forall r a b c d e f g h i z. r -> (i -> r) -> a \/ b \/ c \/ d \/ e \/ f \/ g \/ h \/ i \/ z -> r

#at10 Source

at10 :: forall r a b c d e f g h i j z. r -> (j -> r) -> a \/ b \/ c \/ d \/ e \/ f \/ g \/ h \/ i \/ j \/ z -> r

#Either1 Source

type Either1 a = a \/ Void

#Either2 Source

type Either2 a b = a \/ b \/ Void

#Either3 Source

type Either3 a b c = a \/ b \/ c \/ Void

#Either4 Source

type Either4 a b c d = a \/ b \/ c \/ d \/ Void

#Either5 Source

type Either5 a b c d e = a \/ b \/ c \/ d \/ e \/ Void

#Either6 Source

type Either6 a b c d e f = a \/ b \/ c \/ d \/ e \/ f \/ Void

#Either7 Source

type Either7 a b c d e f g = a \/ b \/ c \/ d \/ e \/ f \/ g \/ Void

#Either8 Source

type Either8 a b c d e f g h = a \/ b \/ c \/ d \/ e \/ f \/ g \/ h \/ Void

#Either9 Source

type Either9 a b c d e f g h i = a \/ b \/ c \/ d \/ e \/ f \/ g \/ h \/ i \/ Void

#Either10 Source

type Either10 a b c d e f g h i j = a \/ b \/ c \/ d \/ e \/ f \/ g \/ h \/ i \/ j \/ Void

#either1 Source

either1 :: forall a. Either1 a -> a

#either2 Source

either2 :: forall r a b. (a -> r) -> (b -> r) -> Either2 a b -> r

#either3 Source

either3 :: forall r a b c. (a -> r) -> (b -> r) -> (c -> r) -> Either3 a b c -> r

#either4 Source

either4 :: forall r a b c d. (a -> r) -> (b -> r) -> (c -> r) -> (d -> r) -> Either4 a b c d -> r

#either5 Source

either5 :: forall r a b c d e. (a -> r) -> (b -> r) -> (c -> r) -> (d -> r) -> (e -> r) -> Either5 a b c d e -> r

#either6 Source

either6 :: forall r a b c d e f. (a -> r) -> (b -> r) -> (c -> r) -> (d -> r) -> (e -> r) -> (f -> r) -> Either6 a b c d e f -> r

#either7 Source

either7 :: forall r a b c d e f g. (a -> r) -> (b -> r) -> (c -> r) -> (d -> r) -> (e -> r) -> (f -> r) -> (g -> r) -> Either7 a b c d e f g -> r

#either8 Source

either8 :: forall r a b c d e f g h. (a -> r) -> (b -> r) -> (c -> r) -> (d -> r) -> (e -> r) -> (f -> r) -> (g -> r) -> (h -> r) -> Either8 a b c d e f g h -> r

#either9 Source

either9 :: forall r a b c d e f g h i. (a -> r) -> (b -> r) -> (c -> r) -> (d -> r) -> (e -> r) -> (f -> r) -> (g -> r) -> (h -> r) -> (i -> r) -> Either9 a b c d e f g h i -> r

#either10 Source

either10 :: forall r a b c d e f g h i j. (a -> r) -> (b -> r) -> (c -> r) -> (d -> r) -> (e -> r) -> (f -> r) -> (g -> r) -> (h -> r) -> (i -> r) -> (j -> r) -> Either10 a b c d e f g h i j -> r