Search results
imap :: forall f a b. Invariant f => (a -> b) -> (b -> a) -> f a -> f b
imapF :: forall f a b. Functor f => (a -> b) -> (b -> a) -> f a -> f b
As all Functors are also trivially Invariant, this function can be
used as the imap implementation for any types that has an existing
Functor instance.
imapC :: forall f a b. Contravariant f => (a -> b) -> (b -> a) -> f a -> f b
As all Contravariant functors are also trivially Invariant, this function can be used as the imap implementation for any types that have an existing Contravariant instance.
under :: forall t a s b. Newtype t a => Newtype s b => (a -> t) -> (t -> s) -> a -> b
The opposite of over: lowers a function that operates on Newtyped
values to operate on the wrapped value instead.
newtype Degrees = Degrees Number
derive instance newtypeDegrees :: Newtype Degrees _
newtype NormalDegrees = NormalDegrees Number
derive instance newtypeNormalDegrees :: Newtype NormalDegrees _
normaliseDegrees :: Degrees -> NormalDegrees
normaliseDegrees (Degrees deg) = NormalDegrees (deg % 360.0)
asNormalDegrees :: Number -> Number
asNormalDegrees = under Degrees normaliseDegrees
As with over the Newtype is polymorphic, as illustrated in the example
above - both Degrees and NormalDegrees are instances of Newtype,
so even though normaliseDegrees changes the result type we can still put
a Number in and get a Number out via under.
compose :: forall c b a. (b -> c) -> (a -> b) -> (a -> c)
Returns a new function that calls the first function with the result of calling the second.
let addTwo x = x + 2
let double x = x * 2
let addTwoThenDouble x = addTwo :compose double
addTwoThenDouble 3 -- 10
This is function composition.
memoCompose :: forall a b c. (a -> b) -> (b -> c) -> a -> c
Memoize the composition of two functions
fold :: forall f z xs r fproxy kproxy lproxy. Fold f z xs r => fproxy f -> kproxy z -> lproxy xs -> kproxy r
foldr :: forall f z xs r fproxy kproxy lproxy. Foldr f z xs r => fproxy f -> kproxy z -> lproxy xs -> kproxy r
clamp1 :: forall f a. Ord1 f => f a -> f a -> f a -> f a
rgetOrAlt :: forall f g s l r v r' i h. RGetOrAlt f g s l r => Alternative h => Cons s v r' r => RLProxying i l => i l -> g s -> f r -> h v
over :: forall t a s b. Newtype t a => Newtype s b => (a -> t) -> (a -> b) -> t -> s
Lifts a function operate over newtypes. This can be used to lift a
function to manipulate the contents of a single newtype, somewhat like
map does for a Functor:
newtype Label = Label String
derive instance newtypeLabel :: Newtype Label _
toUpperLabel :: Label -> Label
toUpperLabel = over Label String.toUpper
But the result newtype is polymorphic, meaning the result can be returned as an alternative newtype:
newtype UppercaseLabel = UppercaseLabel String
derive instance newtypeUppercaseLabel :: Newtype UppercaseLabel _
toUpperLabel' :: Label -> UppercaseLabel
toUpperLabel' = over Label String.toUpper
between :: forall a close open m. Apply m => m open -> m close -> m a -> m a
on :: forall @sym f1 f2 a b r1 r2. Newtype f2 (Variant r2) => Newtype f1 (Variant r1) => Cons sym a r1 r2 => IsSymbol sym => (a -> b) -> (f1 -> b) -> f2 -> b
intercalateMap :: forall f m a. Foldable1 f => Semigroup m => m -> (a -> m) -> f a -> m
Fold a data structure, accumulating values in some Semigroup,
combining adjacent elements using the specified separator.
surroundMap :: forall f a m. Foldable f => Semigroup m => m -> (a -> m) -> f a -> m
foldMap but with each element surrounded by some fixed value.
For example:
> surroundMap "*" show []
= "*"
> surroundMap "*" show [1]
= "*1*"
> surroundMap "*" show [1, 2]
= "*1*2*"
> surroundMap "*" show [1, 2, 3]
= "*1*2*3*"
lerp :: forall f a. Additive f => Ring a => a -> f a -> f a -> f a
Linear interpolation: lerp t a b = a + t * (b - a)
lerp 0.0 a b = alerp 1.0 a b = b
substitute :: forall f a. Monad f => Eq a => a -> f a -> f a -> f a
rget :: forall f g s l r v r' h. RGet f g s l r => Cons s v r' r => RLProxying h l => h l -> g s -> f r -> v
substituteVar :: forall f a. Functor f => Eq a => a -> a -> f a -> f a
liftA1 :: forall f a b. Applicative f => (a -> b) -> f a -> f b
liftA1 provides a default implementation of (<$>) for any
Applicative functor, without using (<$>) as provided
by the Functor-Applicative superclass
relationship.
liftA1 can therefore be used to write Functor instances
as follows:
instance functorF :: Functor F where
map = liftA1
liftM1 :: forall m a b. Monad m => (a -> b) -> m a -> m b
liftM1 provides a default implementation of (<$>) for any
Monad, without using (<$>) as provided by the
Functor-Monad superclass relationship.
liftM1 can therefore be used to write Functor instances
as follows:
instance functorF :: Functor F where
map = liftM1
map :: forall f a b. Functor f => (a -> b) -> f a -> f b
mapFlipped :: forall f a b. Functor f => f a -> (a -> b) -> f b
mapFlipped is map with its arguments reversed. For example:
[1, 2, 3] <#> \n -> n * n
all :: forall a b f. Foldable f => HeytingAlgebra b => (a -> b) -> f a -> b
all f is the same as and <<< map f; map a function over the structure,
and then get the conjunction of the results.
any :: forall a b f. Foldable f => HeytingAlgebra b => (a -> b) -> f a -> b
any f is the same as or <<< map f; map a function over the structure,
and then get the disjunction of the results.
foldMap :: forall f a m. Foldable f => Monoid m => (a -> m) -> f a -> m
foldMap1 :: forall t a m. Foldable1 t => Semigroup m => (a -> m) -> t a -> m
foldMap1DefaultL :: forall t m a. Foldable1 t => Functor t => Semigroup m => (a -> m) -> t a -> m
A default implementation of foldMap1 using foldl1.
Note: when defining a Foldable1 instance, this function is unsafe to use
in combination with foldl1Default.
foldMap1DefaultR :: forall t m a. Foldable1 t => Functor t => Semigroup m => (a -> m) -> t a -> m
A default implementation of foldMap1 using foldr1.
Note: when defining a Foldable1 instance, this function is unsafe to use
in combination with foldr1Default.
foldMapDefault :: forall i f a m. FoldableWithIndex i f => Monoid m => (a -> m) -> f a -> m
A default implementation of foldMap using foldMapWithIndex
foldMapDefaultL :: forall f a m. Foldable f => Monoid m => (a -> m) -> f a -> m
A default implementation of foldMap using foldl.
Note: when defining a Foldable instance, this function is unsafe to use
in combination with foldlDefault.
foldMapDefaultR :: forall f a m. Foldable f => Monoid m => (a -> m) -> f a -> m
A default implementation of foldMap using foldr.
Note: when defining a Foldable instance, this function is unsafe to use
in combination with foldrDefault.
mapDefault :: forall i f a b. FunctorWithIndex i f => (a -> b) -> f a -> f b
A default implementation of Functor's map in terms of mapWithIndex
tracks :: forall w a t. ComonadTraced t w => (a -> t) -> w a -> a
Extracts a value at a relative position which depends on the current value.
flippedMap :: forall f a b. Functor f => f a -> (a -> b) -> f b
squigglyMap :: forall f a b. Functor f => (a -> b) -> f a -> f b
map :: forall p q a b. Dissect p q => (a -> b) -> p a -> p b
A tail-recursive map operation, implemented in terms of Dissect.
defaultFilter :: forall a h f. BooleanEq h => Applicative f => Foldable f => Monoid (f a) => (a -> h) -> f a -> f a
filter :: forall f h a. Filterable f => BooleanEq h => (a -> h) -> f a -> f a
map :: forall a c b. HasMap a => (b -> c) -> a b -> a c
map :: forall f a b. Functor f => (a -> b) -> f a -> f b
mkQ :: forall a b r. Typeable a => Typeable b => r -> (b -> r) -> a -> r
asks :: forall e1 e2 w a. ComonadAsk e1 w => (e1 -> e2) -> w a -> e2
Get a value which depends on the environment.
cmap :: forall f a b. Contravariant f => (b -> a) -> f a -> f b
cmapFlipped :: forall a b f. Contravariant f => f a -> (b -> a) -> f b
cmapFlipped is cmap with its arguments reversed.
censor :: forall w m a. MonadWriter w m => (w -> w) -> m a -> m a
Modify the final accumulator value by applying a function.
local :: forall e w a. ComonadEnv e w => (e -> e) -> w a -> w a
local :: forall r m a. MonadReader r m => (r -> r) -> m a -> m a
peeks :: forall s a w. ComonadStore s w => (s -> s) -> w a -> a
Extract a value from a position which depends on the current position.
seeks :: forall s a w. ComonadStore s w => (s -> s) -> w a -> w a
Reposition the focus at the specified position, which depends on the current position.