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
fromKillSignal' :: forall r. (Int -> r) -> (String -> r) -> KillSignal -> r
modifyOrSnoc :: forall a. (a -> Boolean) -> (a -> a) -> Array a -> a -> Array a
Modify an element when it was found by the predicate or append a new element to the end of the array.
modifyOrSnoc (_ == 2) (* 3) [1,2,3] 11 == Just [1,6,3]
modifyOrSnoc (_ == 4) (* 3) [1,2,3] 11 == Just [1,2,3,11]
modifyOrSnoc :: forall a. (a -> Boolean) -> (a -> a) -> Array a -> a -> Array a
Modify an element when it was found by the predicate or append a new element to the end of the array.
modifyOrSnoc (_ == 2) (* 3) [1,2,3] 11 == Just [1,6,3]
modifyOrSnoc (_ == 4) (* 3) [1,2,3] 11 == Just [1,2,3,11]
while :: forall a. (a -> Boolean) -> (a -> a) -> a -> a
Keeps calling the function while the predicate is true.
1 :while (_ < 3) (_ + 1) -- 3
9 :while (_ < 3) (_ + 1) -- 9
alaF :: forall f g t a s b. Coercible (f t) (f a) => Coercible (g s) (g b) => Newtype t a => Newtype s b => (a -> t) -> (f t -> g s) -> f a -> g b
Similar to ala but useful for cases where you want to use an additional
projection with the higher order function:
alaF Additive foldMap String.length ["hello", "world"] -- 10
alaF Multiplicative foldMap Math.abs [1.0, -2.0, 3.0, -4.0] -- 24.0
The type admits other possibilities due to the polymorphic Functor
constraints, but the case described above works because ((->) a) is a
Functor.
overF :: forall f g t a s b. Coercible (f a) (f t) => Coercible (g b) (g s) => Newtype t a => Newtype s b => (a -> t) -> (f a -> g b) -> f t -> g s
Much like over, but where the lifted function operates on values in a
Functor:
findLabel :: String -> Array Label -> Maybe Label
findLabel s = overF Label (Foldable.find (_ == s))
The above example also demonstrates that the functor type is polymorphic
here too, the input is an Array but the result is a Maybe.
underF :: forall f g t a s b. Coercible (f t) (f a) => Coercible (g s) (g b) => Newtype t a => Newtype s b => (a -> t) -> (f t -> g s) -> f a -> g b
Much like under, but where the lifted function operates on values in a
Functor:
newtype EmailAddress = EmailAddress String
derive instance newtypeEmailAddress :: Newtype EmailAddress _
isValid :: EmailAddress -> Boolean
isValid x = false -- imagine a slightly less strict predicate here
findValidEmailString :: Array String -> Maybe String
findValidEmailString = underF EmailAddress (Foldable.find isValid)
The above example also demonstrates that the functor type is polymorphic
here too, the input is an Array but the result is a Maybe.
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.
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
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.
uncons' :: forall r. r -> (SourceToken -> TokenList -> r) -> TokenList -> r
memoCompose :: forall a b c. (a -> b) -> (b -> c) -> a -> c
Memoize the composition of two functions
subscriptionEventOpts :: forall opts c. SubscriptionClient c opts => (opts -> opts) -> c -> String -> Json -> Emitter Json
watchQueryEventOpts :: forall opts c. WatchQueryClient c opts => (opts -> opts) -> c -> String -> Json -> Emitter Json
verifyScannable :: forall b a f. Eq (f b) => Functor f => Foldable f => Scannable f => (b -> a -> b) -> (a -> b) -> b -> f a -> Boolean
jacobiIdentity :: forall a. Eq a => (a -> a -> a) -> (a -> a -> a) -> a -> a -> a -> a -> Boolean
jacobiIdentity :: forall a. Eq a => (a -> a -> a) -> (a -> a -> a) -> a -> a -> a -> a -> Boolean
distributive' :: forall b a. Eq b => (a -> b) -> (a -> a -> a) -> (b -> b -> b) -> a -> a -> Boolean
f (g x y) == g' (f x) (f y)?
handle :: forall a' a p t s. RowCons t (Action t p) a a' => IsSymbol t => (s -> Action t p -> s) -> (Variant a -> s -> s) -> Variant a' -> s -> s
Converts a single action handler into an "action handler set"
handlers = handle logIn. This "action handler set" can be combined
with other action handlers using combine or >>=>>.
surroundMapWithIndex :: forall i f a m. FoldableWithIndex i f => Semigroup m => m -> (i -> a -> m) -> f a -> m
foldMapWithIndex but with each element surrounded by some fixed value.
For example:
> surroundMapWithIndex "*" (\i x -> show i <> x) []
= "*"
> surroundMapWithIndex "*" (\i x -> show i <> x) ["a"]
= "*0a*"
> surroundMapWithIndex "*" (\i x -> show i <> x) ["a", "b"]
= "*0a*1b*"
> surroundMapWithIndex "*" (\i x -> show i <> x) ["a", "b", "c"]
= "*0a*1b*2c*"
maybe' :: forall a b. (Unit -> b) -> (a -> b) -> Maybe a -> b
Similar to maybe but for use in cases where the default value may be
expensive to compute. As PureScript is not lazy, the standard maybe has
to evaluate the default value before returning the result, whereas here
the value is only computed when the Maybe is known to be Nothing.
maybe' (\_ -> x) f Nothing == x
maybe' (\_ -> x) f (Just y) == f y
expectNotSatisfyM :: forall m a. MonadThrow Error m => Show a => a -> (a -> m Boolean) -> String -> m Unit
expectSatisfyM :: forall m a. MonadThrow Error m => Show a => a -> (a -> m Boolean) -> String -> m Unit
iterateN :: forall f a. Unfoldable1 f => (a -> a) -> a -> Int -> f a
forWithIndex :: forall i a b m t. Applicative m => TraversableWithIndex i t => t a -> (i -> a -> m b) -> m (t b)
A version of traverseWithIndex with its arguments flipped.
This can be useful when running an action written using do notation for every element in a data structure:
For example:
for [1, 2, 3] \i x -> do
logShow i
pure (x * x)
overF2 :: forall f g t a s b. Coercible (f a) (f t) => Coercible (g b) (g s) => Newtype t a => Newtype s b => (a -> t) -> (f a -> f a -> g b) -> f t -> f t -> g s
Much like over2, but where the lifted binary function operates on
values in a Functor.
underF2 :: forall f g t a s b. Coercible (f t) (f a) => Coercible (g s) (g b) => Newtype t a => Newtype s b => (a -> t) -> (f t -> f t -> g s) -> f a -> f a -> g b
Much like under2, but where the lifted binary function operates on
values in a Functor.
bitraverse_ :: forall t f a b c d. Bifoldable t => Applicative f => (a -> f c) -> (b -> f d) -> t a b -> f Unit
Traverse a data structure, accumulating effects using an Applicative functor,
ignoring the final result.
onemore :: forall t24 t25 t27 t28. (t25 -> t27 -> t28) -> (t24 -> t25) -> (t24 -> t27) -> t24 -> t28
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
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)
switchFoldOp :: forall s' s. Game s => GameBoot s' => (Input -> s -> s) -> (Input -> s' -> s') -> Input -> GameWithBoot s s' -> GameWithBoot s s'
associative :: forall a. Eq a => (a -> a -> a) -> a -> a -> a -> Boolean
cancellative :: forall a. Eq a => (a -> a -> a) -> a -> a -> a -> Boolean
leftCancellative :: forall a. Eq a => (a -> a -> a) -> a -> a -> a -> Boolean
leftUnar :: forall a. Eq a => (a -> a -> a) -> a -> a -> a -> Boolean
rightCancellative :: forall a. Eq a => (a -> a -> a) -> a -> a -> a -> Boolean
rightUnar :: forall a. Eq a => (a -> a -> a) -> a -> a -> a -> Boolean
associative :: forall a. Eq a => (a -> a -> a) -> a -> a -> a -> Boolean
cancellative :: forall a. Eq a => (a -> a -> a) -> a -> a -> a -> Boolean
leftCancellative :: forall a. Eq a => (a -> a -> a) -> a -> a -> a -> Boolean
leftUnar :: forall a. Eq a => (a -> a -> a) -> a -> a -> a -> Boolean
rightCancellative :: forall a. Eq a => (a -> a -> a) -> a -> a -> a -> Boolean