Search results
compose2 :: forall a b x y. (a -> b) -> (x -> y -> a) -> x -> y -> b
\f g x y -> f (g x y)
distributive :: forall a. Eq a => (a -> a) -> (a -> a -> a) -> a -> a -> Boolean
f (g x y) == g (f x) (f y)?
composeSecondFlipped :: forall a b x y. (y -> b) -> (x -> b -> a) -> x -> y -> a
over2 :: forall t a s b. Newtype t a => Newtype s b => (a -> t) -> (a -> a -> b) -> t -> t -> s
Lifts a binary function to operate over newtypes.
newtype Meter = Meter Int
derive newtype instance newtypeMeter :: Newtype Meter _
newtype SquareMeter = SquareMeter Int
derive newtype instance newtypeSquareMeter :: Newtype SquareMeter _
area :: Meter -> Meter -> SquareMeter
area = over2 Meter (*)
The above example also demonstrates that the return type is polymorphic here too.
under2 :: forall t a s b. Newtype t a => Newtype s b => (a -> t) -> (t -> t -> s) -> a -> a -> b
The opposite of over2: lowers a binary function that operates on Newtyped
values to operate on the wrapped value instead.
absorbtion :: forall a. Eq a => (a -> a -> a) -> (a -> a -> a) -> a -> a -> Boolean
absorbtion :: forall a. Eq a => (a -> a -> a) -> (a -> a -> a) -> a -> a -> Boolean
mapCopyAll :: forall a b p q. (String -> String) -> (a -> b) -> p -> q -> p
dimap :: forall a b. (a -> Number) -> (Number -> b) -> ContinuousScale -> (a -> b)
Transform both input and output (profunctor-like)
transformed = scale # dimap preprocess postprocess
insertByWith :: forall a. (a -> Boolean) -> (a -> a -> Ordering) -> a -> Array a -> Maybe (Array a)
Insert the element into a sorted array but only if the element can not be found by the predicate.
insertByWith (_ == 2) (\a b -> compare a b) 2 [1,3] == Just [1,2,3]
compose3 :: forall a b x y z. (a -> b) -> (x -> y -> z -> a) -> x -> y -> z -> b
\f g x y z -> f (g x y z)
composeThirdFlipped :: forall a b x y z. (z -> b) -> (x -> y -> b -> a) -> x -> y -> z -> a
splay2 :: forall a b c d. (a -> b -> c -> d) -> (a -> b -> c) -> a -> b -> d
traverse :: forall f t a. Coercible (f a) (f t) => Newtype t a => (a -> t) -> (a -> f a) -> t -> f t
Similar to the function from the Traversable class, but operating within
a newtype instead.
iterateUntilM :: forall a m. Monad m => (a -> Boolean) -> (a -> m a) -> a -> m a
Yields the result of applying f until p holds.
iterateUntilM :: forall m a. MonadRec m => (a -> Boolean) -> (a -> m a) -> a -> m a
Yields the result of applying f until p holds.
compose2SecondFlipped :: forall a b x y z. (y -> z -> b) -> (x -> b -> a) -> x -> y -> z -> a
retryUntilLoop :: forall m a. Monad m => (a -> Boolean) -> (a -> m a) -> a -> m a
Repeat a computation until the value satisfies a predicate, looping in the previous value
distributive :: forall a. Eq a => (a -> a -> a) -> (a -> a -> a) -> a -> a -> a -> Boolean
leftDistributive :: forall a. Eq a => (a -> a -> a) -> (a -> a -> a) -> a -> a -> a -> Boolean
rightDistributive :: forall a. Eq a => (a -> a -> a) -> (a -> a -> a) -> a -> a -> a -> Boolean
distributive :: forall a. Eq a => (a -> a -> a) -> (a -> a -> a) -> a -> a -> a -> Boolean
leftDistributive :: forall a. Eq a => (a -> a -> a) -> (a -> a -> a) -> a -> a -> a -> Boolean
rightDistributive :: forall a. Eq a => (a -> a -> a) -> (a -> a -> a) -> a -> a -> a -> Boolean
discard :: forall m a b c. Bind m => (a -> m b) -> (Unit -> (b -> m c)) -> (a -> m c)
bifoldl :: forall p a b c. Bifoldable p => (c -> a -> c) -> (c -> b -> c) -> c -> p a b -> c
bifoldlDefault :: forall p a b c. Bifoldable p => (c -> a -> c) -> (c -> b -> c) -> c -> p a b -> c
A default implementation of bifoldl using bifoldMap.
Note: when defining a Bifoldable instance, this function is unsafe to
use in combination with bifoldMapDefaultL.
applyThirdFlipped :: forall x y z a. x -> (y -> z -> x -> a) -> y -> z -> a
composeKleisliFlipped :: forall a b c m. Bind m => (b -> m c) -> (a -> m b) -> a -> m c
Backwards Kleisli composition.
compose2Second :: forall a b x y z. (x -> b -> a) -> (y -> z -> b) -> x -> y -> z -> a
\f g x y z -> f x (g y z)
becard :: forall d c b a. (c -> d) -> (b -> c) -> (a -> b) -> a -> d
B3 combinator - becard
B(BB)B
Λ a b c d . (c → d) → (b → c) → (a → b) → a → d
λ f g h x . f (g (h x))
on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
The on function is used to change the domain of a binary operator.
For example, we can create a function which compares two records based on the values of their x properties:
compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
compareX = compare `on` _.x
bifoldr :: forall p a b c. Bifoldable p => (a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldrDefault :: forall p a b c. Bifoldable p => (a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
A default implementation of bifoldr using bifoldMap.
Note: when defining a Bifoldable instance, this function is unsafe to
use in combination with bifoldMapDefaultR.
goldfinch :: forall d c b a. (b -> c -> d) -> (a -> c) -> a -> b -> d
G combinator - goldfinch
BBC
Λ a b c d . (b → c → d) → (a → c) → a → b → d
λ f g x y . f y (g x)
on :: forall c b a. (b -> b -> c) -> (a -> b) -> a -> a -> c
Psi combinator - psi bird - on
Λ a b . (b → b → c) → (a → b) → a → a → c
λ f g . λ x y . f (g x) (g y)
on :: forall c b a. (a -> a -> b) -> (c -> a) -> c -> c -> b
psi :: forall c b a. (a -> a -> b) -> (c -> a) -> (c -> c -> b)
compose2Flipped :: forall a b x y. (x -> y -> a) -> (a -> b) -> x -> y -> b
composeSecond :: forall a b x y. (x -> b -> a) -> (y -> b) -> x -> y -> a
\f g x y -> f x (g y)
composeKleisli :: forall a b c m. Bind m => (a -> m b) -> (b -> m c) -> a -> m c
Forwards Kleisli composition.
For example:
import Data.Array (head, tail)
third = tail >=> tail >=> head
applySecondFlipped :: forall x y a. x -> (y -> x -> a) -> y -> a
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.
finch :: forall c b a. a -> (c -> a -> b) -> c -> b
F combinator - finch
ETTET
Λ a b c . a → b → (b → a → c) → c
λ x y f . f y x
modifyOrCons :: forall a. (a -> Boolean) -> (a -> a) -> a -> Array a -> Array a
Modify an element when it was found by the predicate or push a new element to the front of the array.
modifyOrCons (_ == 2) (* 3) 11 [1,2,3] == Just [1,6,3]
modifyOrCons (_ == 4) (* 3) 11 [1,2,3] == Just [11,1,2,3]
modifyOrCons :: forall a. (a -> Boolean) -> (a -> a) -> a -> Array a -> Array a
Modify an element when it was found by the predicate or push a new element to the front of the array.
modifyOrCons (_ == 2) (* 3) 11 [1,2,3] == Just [1,6,3]
modifyOrCons (_ == 4) (* 3) 11 [1,2,3] == Just [11,1,2,3]
robin :: forall c b a. a -> (b -> a -> c) -> b -> c
R combinator - robin
BBT
Λ a b c . a → (b → a → c) → b → c
λ x f y . f y x
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
unsafeOptField_helper :: forall r val obj. r -> (val -> r) -> String -> obj -> r
caseDeposit :: forall a d. Deposit d => (Source -> a) -> (Mineral -> a) -> d -> a