Skip to main content

Applicatives

An applicative is a functor which conforms to certain laws - interchange, map, identity, and homomorphism. The most pervasive element of applicatives is the ability to apply a function to the values in their context.

Functions, arrays, objects, and primitives can be encapsulated in Applicatives.

pure#

pure(value)

pure :: a -> f a

Lifts a value into an Applicative context.

Since:

  • bingo-functional - v1.11.0

Argument(s):

  • value - An arbitrary value - function, array, or otherwise - to lift into an Applicative context
use function Chemem\Bingo\Functional\Functors\Applicative;
$app = Applicative\pure(  fn (string $text) => substr($text, 0, (5 - mb_strlen($text))),);

liftA2#

liftA2(function, ...applicatives)

liftA2 :: (a -> b -> c) -> f a -> f b -> f c

Lifts a binary function into actions.

Since:

  • bingo-functional - v1.11.0

Argument(s):

  • function - Lift function
  • applicatives - Instances of an Applicative
use Chemem\Bingo\Functional\Functors\Applicative;
$app = Applicative\liftA2(  fn (int $val) => ($val / 2) * pow($val, $val / 5),  Applicative::pure(12),  Applicative::pure(9));