Data.Pointed.Smash
- Package
- purescript-pointed
- Repository
- vladciobanu/purescript-pointed
This module defines the Smash
type, along with instances and functions that
help use this type. Generally, Smash
is used when the data is isomorphic
to Maybe (Tuple a b)
.
#Smash Source
data Smash a b
Smash
a
b
can hold either no values or an a
and a b
. The type is
isomorphic with Maybe (Tuple a b)
.
Constructors
Instances
(Eq a, Eq b) => Eq (Smash a b)
(Ord a, Ord b) => Ord (Smash a b)
Generic (Smash a b) _
Functor (Smash a)
(Semigroup a, Semigroup b) => Semigroup (Smash a b)
(Semigroup a, Semigroup b) => Monoid (Smash a b)
Bifunctor Smash
Biapply Smash
Biapplicative Smash
Bifoldable Smash
Bitraversable Smash
(Semigroup a) => Apply (Smash a)
(Monoid a) => Applicative (Smash a)
(Monoid a) => Bind (Smash a)
(Monoid a) => Monad (Smash a)
Foldable (Smash a)
Traversable (Smash a)
#smash Source
smash :: forall c b a. c -> (a -> b -> c) -> Smash a b -> c
Smash
catamorphism (fold). Takes an input for each possible constructor and
translates it to c
.
For example, we can go from some s :: Smash a b
to a
Maybe (Tuple a b)
using:
> smash Nothing (\a b -> Just (Tuple a b)) (Non :: Smash String Int)
Nothing
> smash Nothing (\a b -> Just (Tuple a b)) (Two "hello" 43 :: Smash String Int)
Just (Tuple "hello" 42)
#curry Source
curry :: forall c b a. (Smash a b -> Maybe c) -> Maybe a -> Maybe b -> Maybe c
Expand a Smash a b
to a Maybe a
and a Maybe b
. Note that the tuple
Tuple (Maybe a) (Maybe b)
has more information that we can store in a
Smash a b
.
Nothing, Nothing ~ Non
Just a , Nothing ~ Non
Nothing, Just b ~ Non
Just a , Just b ~ Two a b
#partition Source
partition :: forall b a t f. Foldable t => Alternative f => t (Smash a b) -> Tuple (f a) (f b)
Grab all a
and b
values from a Foldable
Smash a b
and combine them
each into an Alternative
f
tuple.
> partition [Non, Two "hello" 42, Two "world" 1] :: Tuple (List String) (List Int)
Tuple (Cons "hello" (Cons "world" Nil)) (Cons 42 (Cons 1 Nil))
#partitionMap Source
partitionMap :: forall c b a t f. Alternative f => Traversable t => (a -> Smash b c) -> t a -> Tuple (f b) (f c)
Maps Smash
es over a Traversable
and partitions the values by their
position in the Smash
.
> partitionMap (\i -> if i < 3 then Non else Two i (i*10)) [1, 2, 3, 4, 5] :: Tuple (Array Int) (Array Int)
Tuple [3, 4, 5] [30, 40, 50]