sanctuary-pair
Pair is the canonical product type: a value of type Pair a b
always
contains exactly two values: one of type a
; one of type b
.
Pair a b
satisfies the following Fantasy Land specifications:
> const Useless = > const isTypeClass = type x === 'sanctuary-type-classes/TypeClass@1' > S S 'Setoid ✅ * ' // if ‘a’ and ‘b’ satisfy Setoid 'Ord ✅ * ' // if ‘a’ and ‘b’ satisfy Ord 'Semigroupoid ✅ ' 'Category ❌ ' 'Semigroup ✅ * ' // if ‘a’ and ‘b’ satisfy Semigroup 'Monoid ❌ ' 'Group ❌ ' 'Filterable ❌ ' 'Functor ✅ ' 'Bifunctor ✅ ' 'Profunctor ❌ ' 'Apply ✅ * ' // if ‘a’ satisfies Semigroup 'Applicative ❌ ' 'Chain ✅ * ' // if ‘a’ satisfies Semigroup 'ChainRec ❌ ' 'Monad ❌ ' 'Alt ❌ ' 'Plus ❌ ' 'Alternative ❌ ' 'Foldable ✅ ' 'Traversable ✅ ' 'Extend ✅ ' 'Comonad ✅ ' 'Contravariant ❌ '
Pair :: a -> b -> Pair a b
Pair's sole data constructor. Additionally, it serves as the Pair type representative.
> 2 2
Pair.fst :: Pair a b -> a
fst (Pair (x) (y))
is equivalent to x
.
> Pair'abc'
Pair.snd :: Pair a b -> b
snd (Pair (x) (y))
is equivalent to y
.
> Pair1 2 3
Pair.swap :: Pair a b -> Pair b a
swap (Pair (x) (y))
is equivalent to Pair (y) (x)
.
> Pair 'abc'
Pair#@@show :: (Showable a, Showable b) => Pair a b ~> () -> String
show (Pair (x) (y))
is equivalent to
'Pair (' + show (x) + ') (' + show (y) + ')'
.
> 'Pair ("abc") ([1, 2, 3])'
Pair#fantasy-land/equals :: (Setoid a, Setoid b) => Pair a b ~> Pair a b -> Boolean
Pair (x) (y)
is equal to Pair (v) (w)
iff x
is equal to v
and y
is equal to w
according to Z.equals
.
> S 1 2 3true > S 3 2 1false
Pair#fantasy-land/lte :: (Ord a, Ord b) => Pair a b ~> Pair a b -> Boolean
Pair (x) (y)
is less than or equal to Pair (v) (w)
iff x
is
less than v
or x
is equal to v
and y
is less than or equal to
w
according to Z.lte
.
> S 1 2 3 1 2 3 1 2 3 1 2 3 1 2
Pair#fantasy-land/compose :: Pair a b ~> Pair b c -> Pair a c
compose (Pair (x) (y)) (Pair (v) (w))
is equivalent to Pair (v) (y)
.
> S 'b' 0
Pair#fantasy-land/concat :: (Semigroup a, Semigroup b) => Pair a b ~> Pair a b -> Pair a b
concat (Pair (x) (y)) (Pair (v) (w))
is equivalent to
Pair (concat (x) (v)) (concat (y) (w))
.
> S 4 5 6 1 2 3 4 5 6
Pair#fantasy-land/map :: Pair a b ~> (b -> c) -> Pair a c
map (f) (Pair (x) (y))
is equivalent to Pair (x) (f (y))
.
> S 256 16
Pair#fantasy-land/bimap :: Pair a c ~> (a -> b, c -> d) -> Pair b d
bimap (f) (g) (Pair (x) (y))
is equivalent to Pair (f (x)) (g (y))
.
> S Mathsqrt 256 16
Pair#fantasy-land/ap :: Semigroup a => Pair a b ~> Pair a (b -> c) -> Pair a c
ap (Pair (v) (f)) (Pair (x) (y))
is equivalent to
Pair (concat (v) (x)) (f (y))
.
> S 256 16
Pair#fantasy-land/chain :: Semigroup a => Pair a b ~> (b -> Pair a c) -> Pair a c
chain (f) (Pair (x) (y))
is equivalent to
Pair (concat (x) (fst (f (y)))) (snd (f (y)))
.
> S 256 16
Pair#fantasy-land/reduce :: Pair a b ~> ((c, b) -> c, c) -> c
reduce (f) (x) (Pair (v) (w))
is equivalent to f (x) (w)
.
> S 1 2 3 4 5 61 2 3 4 5 6
Pair#fantasy-land/traverse :: Applicative f => Pair a b ~> (TypeRep f, b -> f c) -> f (Pair a c)
traverse (_) (f) (Pair (x) (y))
is equivalent to
map (Pair (x)) (f (y))
.
> S Swords 'foo bar baz' 'foo' 'bar' 'baz'
Pair#fantasy-land/extend :: Pair a b ~> (Pair a b -> c) -> Pair a c
extend (f) (Pair (x) (y))
is equivalent to
Pair (x) (f (Pair (x) (y)))
.
> S 99 100
Pair#fantasy-land/extract :: Pair a b ~> () -> b
extract (Pair (x) (y))
is equivalent to y
.
> S1 2 3