Search results
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)
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 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
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)
antitransitive :: forall b a. HeytingAlgebra b => (a -> a -> b) -> a -> a -> a -> b
intransitive :: forall b a. HeytingAlgebra b => (a -> a -> b) -> a -> a -> a -> b
transitive :: forall b a. HeytingAlgebra b => (a -> a -> b) -> a -> a -> a -> b
antitransitive :: forall b a. HeytingAlgebra b => (a -> a -> b) -> a -> a -> a -> b
intransitive :: forall b a. HeytingAlgebra b => (a -> a -> b) -> a -> a -> a -> b
transitive :: forall b a. HeytingAlgebra b => (a -> a -> b) -> a -> a -> a -> b
splay1 :: forall a b c. (a -> b -> c) -> (a -> b) -> a -> c
s :: forall c b a. (a -> b -> c) -> (a -> b) -> (a -> c)
monotonic :: forall a. HeytingAlgebra a => Eq a => (a -> a -> a) -> a -> a -> a -> a
monotonic :: forall a. HeytingAlgebra a => Eq a => (a -> a -> a) -> a -> a -> a -> a
everything :: forall a r. Data a => (r -> r -> r) -> (forall b. Data b => b -> r) -> a -> r
Summarise all nodes in top-down, left-to-right
jay :: forall b a. (a -> b -> b) -> a -> b -> a -> b
J combinator - Jay
B(BC)(W(BC(B(BBB))))
Λ a b c d . (a → b → b) → a → b → a → b
λ f x y z . f x (f z y)
fold :: forall event b a. IsEvent event => (a -> b -> b) -> event a -> b -> event b
flip :: forall a b c. (a -> b -> c) -> b -> a -> c
Given a function that takes two arguments, applies the arguments to the function in a swapped order.
flip append "1" "2" == append "2" "1" == "21"
const 1 "two" == 1
flip const 1 "two" == const "two" 1 == "two"
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 Newtype
d
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
.
applySecond :: forall x y a. (y -> x -> a) -> x -> y -> a
\f x y -> f y x
(flip
)
cardinal :: forall c b a. (a -> b -> c) -> b -> a -> c
C combinator - cardinal
S(BBS)(KK)
Λ a b c . (a → b → c) → b → a → c
λ f x y . f y x
flip :: forall c b a. (a -> b -> c) -> (b -> a -> c)
Flips the first two arguments of a function.
"a" :add "b" -- "ab"
"a" :flip add "b" -- "ba"
memoCompose :: forall a b c. (a -> b) -> (b -> c) -> a -> c
Memoize the composition of two functions
vireostar :: forall c b a. (a -> b -> c) -> b -> a -> c
V* combinator - vireo once removed
CF
Λ a b c d . (b → a → b → d) → a → b → b → d
λ f x y z . f y x z
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
memoize2 :: forall a b c. Tabulate a => Tabulate b => (a -> b -> c) -> a -> b -> c
Memoize a function of two arguments
memoize2 :: forall c b a. Tabulate a => Tabulate b => (a -> b -> c) -> a -> b -> c
Memoize a function of two arguments
idstarstar :: forall c b a. (a -> b -> c) -> a -> b -> c
I** combinator - id bird twice removed
Λ a b c . (a → b → c) → a → b → c
λ f x y . f x y
moldl :: forall t e m. Moldable t e => (m -> e -> m) -> m -> t -> m
moldlDefault :: forall m e t. Moldable t e => (m -> e -> m) -> m -> t -> m
A default implementation of moldl
based on moldMap
moldr :: forall t e m. Moldable t e => (e -> m -> m) -> m -> t -> m
moldrDefault :: forall m e t. Moldable t e => (e -> m -> m) -> m -> t -> m
A default implementation of moldr
based on moldMap
falsehoodPreserving :: forall a. HeytingAlgebra a => Eq a => (a -> a -> a) -> a -> a -> a
truthPreserving :: forall a. HeytingAlgebra a => Eq a => (a -> a -> a) -> a -> a -> a
falsehoodPreserving :: forall a. HeytingAlgebra a => Eq a => (a -> a -> a) -> a -> a -> a
truthPreserving :: forall a. HeytingAlgebra a => Eq a => (a -> a -> a) -> a -> a -> 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.
allWithIndex :: forall i a b f. FoldableWithIndex i f => HeytingAlgebra b => (i -> a -> b) -> f a -> b
allWithIndex f
is the same as and <<< mapWithIndex f
; map a function over the
structure, and then get the conjunction of the results.
anyWithIndex :: forall i a b f. FoldableWithIndex i f => HeytingAlgebra b => (i -> a -> b) -> f a -> b
anyWithIndex f
is the same as or <<< mapWithIndex f
; map a function over the
structure, and then get the disjunction of the results.
foldMapWithIndex :: forall i f a m. FoldableWithIndex i f => Monoid m => (i -> a -> m) -> f a -> m
foldMapWithIndexDefaultL :: forall i f a m. FoldableWithIndex i f => Monoid m => (i -> a -> m) -> f a -> m
A default implementation of foldMapWithIndex
using foldlWithIndex
.
Note: when defining a FoldableWithIndex
instance, this function is
unsafe to use in combination with foldlWithIndexDefault
.
foldMapWithIndexDefaultR :: forall i f a m. FoldableWithIndex i f => Monoid m => (i -> a -> m) -> f a -> m
A default implementation of foldMapWithIndex
using foldrWithIndex
.
Note: when defining a FoldableWithIndex
instance, this function is
unsafe to use in combination with foldrWithIndexDefault
.
mapWithIndex :: forall i f a b. FunctorWithIndex i f => (i -> a -> b) -> f a -> f b
foldl1 :: forall t a. Foldable1 t => (a -> a -> a) -> t a -> a
foldl1Default :: forall t a. Foldable1 t => (a -> a -> a) -> t a -> a
A default implementation of foldl1
using foldMap1
.
Note: when defining a Foldable1
instance, this function is unsafe to use
in combination with foldMap1DefaultL
.
foldr1 :: forall t a. Foldable1 t => (a -> a -> a) -> t a -> a
foldr1Default :: forall t a. Foldable1 t => (a -> a -> a) -> t a -> a
A default implementation of foldr1
using foldMap1
.
Note: when defining a Foldable1
instance, this function is unsafe to use
in combination with foldMap1DefaultR
.