WPML Functional Programming Library
Table of Contents
Fns
- Full name: \WPML\FP\Fns
always
Fns::always( mixed $...$a ): callable
Curried :: a → ( * → a )
Returns a function that always returns the given value.
$t = Fns::always( 'Tee' );
$t(); //=> 'Tee'
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed |
converge
Fns::converge( mixed $...$convergingFn, mixed $...$branchingFns ): callable
- Curried :: ( ( x1, x2, … ) → z ) → [( ( a, b, … ) → x1 ), ( ( a, b, … ) → x2 ), …] → ( a → b → … → z )
Accepts a converging function and a list of branching functions and returns a new function. The arity of the new function is the same as the arity of the longest branching function. When invoked, this new function is applied to some arguments, and each branching function is applied to those same arguments. The results of each branching function are passed as arguments to the converging function to produce the return value.
$divide = curryN( 2, function ( $num, $dom ) { return $num / $dom; } );
$sum = function ( Collection $collection ) { return $collection->sum(); };
$length = function ( Collection $collection ) { return $collection->count(); };
$average = Fns::converge( $divide, [ $sum, $length ] );
$this->assertEquals( 4, $average( wpml_collect( [ 1, 2, 3, 4, 5, 6, 7 ] ) ) );
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$convergingFn |
mixed | |
$...$branchingFns |
mixed |
map
Fns::map( mixed $...$fn, mixed $...$target ): callable|mixed
- Curried :: ( a→b )→f a→f b
Takes a function and a functor, applies the function to each of the functor's values, and returns a functor of the same shape.
And array is considered a functor
Dispatches to the map method of the second argument, if present
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$fn |
mixed | |
$...$target |
mixed |
Fns::( ):
static callable|mixed each ( ...$fn, ...$target ) - Curried :: ( a→b )→f a→f b
identity
Fns::identity( mixed $mixed ): callable|mixed
Curried :: a->a
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$mixed |
mixed |
tap
Fns::tap( mixed $callable, mixed $mixed ): callable|mixed
Curried :: fn->data->data
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$callable |
mixed | |
$mixed |
mixed |
reduce
Fns::reduce( mixed $...$fn, mixed $...$initial, mixed $...$target ): callable|mixed
Curried :: ( ( a, b ) → a ) → a → [b] → a
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$fn |
mixed | |
$...$initial |
mixed | |
$...$target |
mixed |
reduceRight
Fns::reduceRight( mixed $...$fn, mixed $...$initial, mixed $...$target ): callable|mixed
- Curried :: ( ( a, b ) → a ) → a → [b] → a
Takes a function, an initial value and an array and returns the result.
The function receives two values, the accumulator and the current value, and should return a result.
The array values are passed to the function in the reverse order.
$numbers = [ 1, 2, 3, 4, 5, 8, 19 ];
$append = function( $acc, $val ) {
$acc[] = $val;
return $acc;
};
$reducer = Fns::reduceRight( $append, [] );
$result = $reducer( $numbers ); // [ 19, 8, 5, 4, 3, 2, 1 ]
// Works on collections too.
$result = $reducer( wpml_collect( $numbers ) ); // [ 19, 8, 5, 4, 3, 2, 1 ]
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$fn |
mixed | |
$...$initial |
mixed | |
$...$target |
mixed |
filter
Fns::filter( mixed $...$predicate, mixed $...$target ): callable|mixed
Curried :: ( a → bool ) → [a] → [a]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$predicate |
mixed | |
$...$target |
mixed |
reject
Fns::reject( mixed $...$predicate, mixed $...$target ): callable|mixed
Curried :: ( a → bool ) → [a] → [a]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$predicate |
mixed | |
$...$target |
mixed |
value
Fns::value( mixed $mixed ): callable|mixed
Curried :: a|( *→a ) → a
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$mixed |
mixed |
constructN
Fns::constructN( mixed $...$argCount, mixed $...$className ): callable|object
Curried :: int → string → object
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$argCount |
mixed | |
$...$className |
mixed |
ascend
Fns::ascend( mixed $...$fn, mixed $...$a, mixed $...$b ): callable|integer
Curried :: ( a → b ) → a → a → int
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$fn |
mixed | |
$...$a |
mixed | |
$...$b |
mixed |
descend
Fns::descend( mixed $...$fn, mixed $...$a, mixed $...$b ): callable|integer
Curried :: ( a → b ) → a → a → int
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$fn |
mixed | |
$...$a |
mixed | |
$...$b |
mixed |
useWith
Fns::useWith( mixed $...$fn, mixed $...$transformations ): callable
Curried :: ( ( x1, x2, … ) → z ) → [( a → x1 ), ( b → x2 ), …] → ( a → b → … → z )
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$fn |
mixed | |
$...$transformations |
mixed |
nthArg
Fns::nthArg( mixed $...$n ): callable
Curried :: int → *… → *
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$n |
mixed |
either
Fns::either( mixed $...$f, mixed $...$g, mixed $...$e ): callable|mixed
Curried:: ( a → b ) → ( b → c ) → Either a b → c
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$f |
mixed | |
$...$g |
mixed | |
$...$e |
mixed |
maybe
Fns::maybe( mixed $...$v, mixed $...$f, mixed $...$m ): callable|mixed
Curried:: b → ( a → b ) → Maybe a → b
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$v |
mixed | |
$...$f |
mixed | |
$...$m |
mixed |
isRight
Fns::isRight( mixed $...$e ): callable|boolean
Curried:: e → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$e |
mixed |
isLeft
Fns::isLeft( mixed $...$e ): callable|boolean
Curried:: e → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$e |
mixed |
isJust
Fns::isJust( mixed $...$m ): callable|boolean
Curried:: e → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$m |
mixed |
isNothing
Fns::isNothing( mixed $...$m ): callable|boolean
Curried:: e → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$m |
mixed |
T
Fns::T( mixed $...$_ ): callable|mixed
Curried :: _ → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$_ |
mixed |
F
Fns::F( mixed $...$_ ): callable|mixed
Curried :: _ → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$_ |
mixed |
safe
Fns::safe( mixed $...$fn ): callable|\WPML\FP\Maybe
Curried :: ( a → b ) → ( a → Maybe b )
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$fn |
mixed |
make
Fns::make( mixed $...$className ): callable|object
Curried :: string → object
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$className |
mixed |
makeN
Fns::makeN( mixed $...$argCount, mixed $...$className ): callable|object
Curried :: int → string → object
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$argCount |
mixed | |
$...$className |
mixed |
unary
Fns::unary( mixed $...$fn ): callable
Curried:: ( * → b ) → ( a → b )
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$fn |
mixed |
memorizeWith
Fns::memorizeWith( mixed $...$cacheKeyFn, mixed $...$fn ): callable|mixed
Curried :: ( *… → String ) → ( *… → a ) → ( *… → a )
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$cacheKeyFn |
mixed | |
$...$fn |
mixed |
memorize
Fns::memorize( mixed $...$fn ): callable|mixed
Curried :: ( *… → a ) → ( *… → a )
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$fn |
mixed |
once
Fns::once( mixed $...$fn ): callable|mixed
Curried :: ( *… → a ) → ( *… → a )
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$fn |
mixed |
withNamedLock
Fns::withNamedLock( mixed $...$name, mixed $...$returnFn, mixed $...$fn ): callable|mixed
- Curried :: String → ( *… → String ) → ( *… → a ) → ( *… → a )
Creates a new function that is locked so that it wont be called recursively. Multiple functions can use the same lock so they are blocked from calling each other recursively
$lockName = 'my-lock';
$addOne = Fns::withNamedLock(
$lockName,
Fns::identity(),
function ( $x ) use ( &$addOne ) { return $addOne( $x + 1 ); }
);
$this->assertEquals( 13, $addOne( 12 ), 'Should not recurse' );
$addTwo = Fns::withNamedLock(
$lockName,
Fns::identity(),
function ( $x ) use ( $addOne ) { return pipe( $addOne, $addOne) ( $x ); }
);
$this->assertEquals( 10, $addTwo( 10 ), 'Should return 10 because $addOne is locked by the same name as $addTwo' );
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$name |
mixed | |
$...$returnFn |
mixed | |
$...$fn |
mixed |
withoutRecursion
Fns::withoutRecursion( mixed $...$returnFn, mixed $...$fn ): callable|mixed
Curried :: ( *… → String ) → ( *… → a ) → ( *… → a )
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$returnFn |
mixed | |
$...$fn |
mixed |
liftA2
Fns::liftA2( mixed $...$fn, mixed $...$monadA, mixed $...$monadB ): callable|mixed
Curried :: ( a → b → c ) → m a → m b → m c
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$fn |
mixed | |
$...$monadA |
mixed | |
$...$monadB |
mixed |
liftA3
Fns::liftA3( mixed $...$fn, mixed $...$monadA, mixed $...$monadB, mixed $...$monadC ): callable|mixed
Curried :: ( a → b → c → d ) → m a → m b → m c → m d
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$fn |
mixed | |
$...$monadA |
mixed | |
$...$monadB |
mixed | |
$...$monadC |
mixed |
liftN
Fns::liftN( mixed $...$n, mixed $...$fn, mixed $...$monad ): callable|mixed
Curried :: Number->( ( * ) → a ) → ( *m ) → m a
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$n |
mixed | |
$...$fn |
mixed | |
$...$monad |
mixed |
until
Fns::until( mixed $...$predicate, mixed $...$fns ): callable|mixed
- Curried :: ( b → bool ) → [( a → b )] → a → b
Executes consecutive functions until their $predicate($fn(...$args)) is true. When a result fulfils predicate then it is returned.
$fns = [
$add(1),
$add(5),
$add(10),
$add(23),
];
$this->assertSame( 20, Fns::until( Relation::gt( Fns::__, 18 ), $fns )( 10 ) );
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$predicate |
mixed | |
$...$fns |
mixed |
init
Fns::init( ): void
- This method is static.
noop
Fns::noop( ): \Closure
- This method is static.
maybeToEither
Curried function that transforms a Maybe into an Either.
Fns::maybeToEither( mixed|null $or = null, \WPML\FP\Maybe|null $maybe = null ): callable|\WPML\FP\Either
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$or |
mixed|null | |
$maybe |
\WPML\FP\Maybe|null |
Logic
- Full name: \WPML\FP\Logic
not
Logic::not( mixed $mixed ): callable|boolean
Curried :: mixed->bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$mixed |
mixed |
isNotNull
Logic::isNotNull( mixed $mixed ): callable|boolean
Curried :: mixed->bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$mixed |
mixed |
ifElse
Logic::ifElse( mixed $...$predicate, mixed $...$first, mixed $...$second, mixed $...$data ): callable|mixed
Curried :: ( a->bool )->callable->callable->callable
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$predicate |
mixed | |
$...$first |
mixed | |
$...$second |
mixed | |
$...$data |
mixed |
when
Logic::when( mixed $...$predicate, mixed $...$fn ): callable
Curried :: ( a->bool )->callable->callable
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$predicate |
mixed | |
$...$fn |
mixed |
unless
Logic::unless( mixed $...$predicate, mixed $...$fn ): callable
Curried :: ( a->bool )->callable->callable
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$predicate |
mixed | |
$...$fn |
mixed |
cond
Logic::cond( mixed $...$conditions, mixed $...$fn ): callable
Curried :: [( a->bool ), callable]->callable
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$conditions |
mixed | |
$...$fn |
mixed |
both
Logic::both( mixed $...$a, mixed $...$b, mixed $...$data ): callable
Curried :: ( a → bool ) → ( a → bool ) → a → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed | |
$...$data |
mixed |
allPass
Logic::allPass( mixed $...$predicates, mixed $...$data ): callable|boolean
Curried :: [( *… → bool )] → ( *… → bool )
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$predicates |
mixed | |
$...$data |
mixed |
anyPass
Logic::anyPass( mixed $...$predicates, mixed $...$data ): callable|boolean
Curried :: [( *… → bool )] → ( *… → bool )
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$predicates |
mixed | |
$...$data |
mixed |
complement
Logic::complement( mixed $...$fn ): callable
Curried :: ( *… → * ) → ( *… → bool )
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$fn |
mixed |
defaultTo
Logic::defaultTo( mixed $...$a, mixed $...$b ): callable|mixed
Curried :: a → b → a | b
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
either
Logic::either( mixed $...$a, mixed $...$b ): callable|boolean
Curried :: ( *… → bool ) → ( *… → bool ) → ( *… → bool )
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
Logic::( ):
static callable|mixed until ( ...$predicate, ...$transform, ...$data ) - Curried :: ( a → bool ) → ( a → a ) → a → a
propSatisfies
Logic::propSatisfies( mixed $...$predicate, mixed $...$prop, mixed $...$data ): callable|boolean
Curried :: ( a → bool ) → String → [String => a] → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$predicate |
mixed | |
$...$prop |
mixed | |
$...$data |
mixed |
Logic::( ):
static callable|bool isArray ( ...$a ) - Curried :: a → bool
Logic::( ):
static callable|bool isMappable ( ...$a ) - Curried :: a → bool
isEmpty
Logic::isEmpty( mixed $...$a ): callable|boolean
Curried:: a → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed |
isNotEmpty
Logic::isNotEmpty( mixed $...$a ): callable|boolean
Curried:: a → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed |
firstSatisfying
Logic::firstSatisfying( mixed $...$predicate, mixed $...$functions, mixed $...$data ): callable|mixed
Curried:: callable->callable[]->mixed->mixed
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$predicate |
mixed | |
$...$functions |
mixed | |
$...$data |
mixed |
isTruthy
Logic::isTruthy( mixed $...$data ): callable|boolean
Curried:: mixed->bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$data |
mixed |
init
Logic::init( ): void
- This method is static.
Lst
Lst class contains functions for working on ordered arrays indexed with numerical keys
- Full name: \WPML\FP\Lst
append
Lst::append( mixed $mixed, mixed $array ): callable|array
Curried :: mixed->array->array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$mixed |
mixed | |
$array |
mixed |
fromPairs
Lst::fromPairs( mixed $array ): callable|array
Curried :: [[a, b]] → [a => b]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$array |
mixed |
toObj
Lst::toObj( mixed $array ): callable|array
Curried :: array → object
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$array |
mixed |
pluck
Lst::pluck( mixed $...$prop, mixed $...$array ): callable|array
Curried :: string → array → array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$prop |
mixed | |
$...$array |
mixed |
partition
Lst::partition( mixed $...$predicate, mixed $...$target ): callable|array
Curried :: ( a → bool ) → [a] → [[a], [a]]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$predicate |
mixed | |
$...$target |
mixed |
sort
Lst::sort( mixed $...$fn, mixed $...$target ): callable|array
Curried :: ( ( a, a ) → int ) → [a] → [a]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$fn |
mixed | |
$...$target |
mixed |
unfold
Lst::unfold( mixed $...$fn, mixed $...$seed ): callable|array
Curried :: ( a → [b] ) → * → [b]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$fn |
mixed | |
$...$seed |
mixed |
zip
Lst::zip( mixed $...$a, mixed $...$b ): callable|array
Curried :: [a] → [b] → [[a, b]]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
zipObj
Lst::zipObj( mixed $...$a, mixed $...$b ): callable|array
Curried :: [a] → [b] → [a => b]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
zipWith
Lst::zipWith( mixed $...$f, mixed $...$a, mixed $...$b ): callable|array
Curried :: ( ( a, b ) → c ) → [a] → [b] → [c]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$f |
mixed | |
$...$a |
mixed | |
$...$b |
mixed |
join
Lst::join( mixed $...$glue, mixed $...$array ): callable|string
Curried :: string → [a] → string
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$glue |
mixed | |
$...$array |
mixed |
joinWithCommasAndAnd
Lst::joinWithCommasAndAnd( mixed $...$array ): callable|string
Curried :: [a] → string
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$array |
mixed |
concat
Lst::concat( mixed $...$a, mixed $...$b ): callable|array
Curried :: [a] → [a] → [a]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
find
Lst::find( mixed $...$predicate, mixed $...$array ): callable|array|null
Curried :: ( a → bool ) → [a] → a | null
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$predicate |
mixed | |
$...$array |
mixed |
flattenToDepth
Lst::flattenToDepth( mixed $...$depth, mixed $...$array ): callable|array
Curried :: int → [[a]] → [a]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$depth |
mixed | |
$...$array |
mixed |
flatten
Lst::flatten( mixed $...$array ): callable|array
Curried :: [[a]] → [a]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$array |
mixed |
includes
Lst::includes( mixed $...$val, mixed $...$array ): callable|boolean
Curried :: a → [a] → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$val |
mixed | |
$...$array |
mixed |
includesAll
Lst::includesAll( mixed $...$values, mixed $...$array ): callable|boolean
- Curried :: [a] → [a] → bool
Determines if all the values are in the given array
$includes10and20 = Lst::includesAll( [ 10, 20 ] );
$this->assertTrue( $includes10and20( [ 5, 10, 15, 20 ] ) );
$this->assertFalse( $includes10and20( [ 5, 15, 20 ] ) );
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$values |
mixed | |
$...$array |
mixed |
nth
Lst::nth( mixed $...$n, mixed $...$array ): callable|boolean
Curried :: int → [a] → a | null
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$n |
mixed | |
$...$array |
mixed |
first
Lst::first( mixed $...$array ): callable|boolean
Curried :: [a, b] → a | null
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$array |
mixed |
last
Lst::last( mixed $...$array ): callable|boolean
Curried :: [a, b] → b | null
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$array |
mixed |
length
Lst::length( mixed $...$array ): callable|integer
Curried :: [a] → int
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$array |
mixed |
take
Lst::take( mixed $...$n, mixed $...$array ): callable|array
Curried :: int → [a] → [a]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$n |
mixed | |
$...$array |
mixed |
takeLast
Lst::takeLast( mixed $...$n, mixed $...$array ): callable|array
Curried :: int → [a] → [a]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$n |
mixed | |
$...$array |
mixed |
slice
Lst::slice( mixed $...$offset, mixed $...$limit, mixed $...$array ): callable|array
Curried :: int → int->[a] → [a]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$offset |
mixed | |
$...$limit |
mixed | |
$...$array |
mixed |
drop
Lst::drop( mixed $...$n, mixed $...$array ): callable|array
Curried :: int → [a] → [a]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$n |
mixed | |
$...$array |
mixed |
dropLast
Lst::dropLast( mixed $...$n, mixed $...$array ): callable|array
Curried :: int → [a] → [a]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$n |
mixed | |
$...$array |
mixed |
makePair
Lst::makePair( mixed $...$a, mixed $...$b ): callable|array
Curried :: mixed → mixed → array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
Lst::( ):
static callable|array make ( ...$a ) - Curried :: mixed → array
insert
Lst::insert( mixed $...$index, mixed $...$v, mixed $...$array ): callable|array
Curried :: int → mixed → array → array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$index |
mixed | |
$...$v |
mixed | |
$...$array |
mixed |
range
Lst::range( mixed $...$from, mixed $...$to ): callable|array
Curried :: int → int → array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$from |
mixed | |
$...$to |
mixed |
xprod
Lst::xprod( mixed $...$a, mixed $...$b ): callable|array
- Curried :: [a]->[b]->[a, b]
Creates a new list out of the two supplied by creating each possible pair from the lists.
$a = [ 1, 2, 3 ];
$b = [ 'a', 'b', 'c' ];
$expectedResult = [
[ 1, 'a' ], [ 1, 'b' ], [ 1, 'c' ],
[ 2, 'a' ], [ 2, 'b' ], [ 2, 'c' ],
[ 3, 'a' ], [ 3, 'b' ], [ 3, 'c' ],
];
$this->assertEquals( $expectedResult, Lst::xprod( $a, $b ) );
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
prepend
Lst::prepend( mixed $...$val, mixed $...$array ): callable|array
- Curried:: a → [a] → [a]
Returns a new array with the given element at the front, followed by the contents of the list.
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$val |
mixed | |
$...$array |
mixed |
reverse
Lst::reverse( mixed $...$array ): callable|array
- Curried:: [a] → [a]
Returns a new array with the elements reversed.
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$array |
mixed |
init
Lst::init( ): void
- This method is static.
keyBy
Curried function that keys the array by the given key
Lst::keyBy( string $key = null, array<mixed,mixed> $array = null ): array<mixed,mixed>|callable
keyBy :: string -> array -> array
$data = [
[ 'x' => 'a', 'y' => 123 ],
[ 'x' => 'b', 'y' => 456 ],
];
Lst::keyBy( 'x', $data );
[
'a' => [ 'x' => 'a', 'y' => 123 ],
'b' => [ 'x' => 'b', 'y' => 456 ],
],
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$key |
string | |
$array |
array |
keyWith
Curried function that wraps each item in array with pair: [$key => $item1]
Lst::keyWith( string $key = null, array<mixed,mixed> $array = null ): array<mixed,mixed>|callable
keyWith :: string -> array -> array
$data = [ 1, 2.3, 'some data', - 2, 'a' ];
Lst::keyWith('myKey', $data);
[ [ 'myKey' => 1 ], [ 'myKey' => 2.3 ], [ 'myKey' => 'some data' ], [ 'myKey' => - 2 ], [ 'myKey' => 'a' ] ]
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$key |
string | |
$array |
array |
diff
This method will return the values in the original collection that are not present in the given collection:
Lst::diff( array|\WPML\Collect\Support\Collection $array1 = null, array|\WPML\Collect\Support\Collection $array2 = null ): callable|\WPML\Collect\Support\Collection|array
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$array1 |
array|\WPML\Collect\Support\Collection | |
$array2 |
array|\WPML\Collect\Support\Collection |
repeat
It returns array of $val elements repeated $times times.
Lst::repeat( mixed $val = null, integer $times = null ): callable|\WPML\FP\array[mixed]
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$val |
mixed | |
$times |
integer |
sum
Lst::sum( array|\WPML\Collect\Support\Collection $param = null ): callable|integer
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$param |
array|\WPML\Collect\Support\Collection |
Math
- Full name: \WPML\FP\Math
multiply
Math::multiply( mixed $...$a, mixed $...$b ): callable|mixed
Curried :: Number → Number → Number
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
divide
Math::divide( mixed $...$a, mixed $...$b ): callable|mixed
Curried :: Number → Number → Number
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
add
Math::add( mixed $...$a, mixed $...$b ): callable|mixed
Curried :: Number → Number → Number
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
product
Math::product( mixed $...$array ): callable|mixed
Curried :: [Number] → Number
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$array |
mixed |
init
Math::init( ): void
- This method is static.
Obj
- Full name: \WPML\FP\Obj
prop
Obj::prop( mixed $...$key, mixed $...$obj ): callable|mixed
Curried :: string->Collection|array|object->mixed|null
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$key |
mixed | |
$...$obj |
mixed |
propOr
Obj::propOr( mixed $...$default, mixed $...$key, mixed $...$obj ): callable|mixed
Curried :: mixed->string->Collection|array|object->mixed|null
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$default |
mixed | |
$...$key |
mixed | |
$...$obj |
mixed |
props
Obj::props( mixed $...$keys, mixed $...$obj ): callable|array
Curried :: [keys] → Collection|array|object → [v]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$keys |
mixed | |
$...$obj |
mixed |
addProp
Obj::addProp( mixed $...$key, mixed $...$transformation, mixed $...$obj ): callable|array|\stdClass
Curried :: string->callable->object|array->object->array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$key |
mixed | |
$...$transformation |
mixed | |
$...$obj |
mixed |
removeProp
Obj::removeProp( mixed $...$key, mixed $...$obj ): callable|array|\stdClass
Curried :: string->object|array->object->array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$key |
mixed | |
$...$obj |
mixed |
renameProp
Obj::renameProp( mixed $...$key, mixed $...$newKey, mixed $...$obj ): callable|array|\stdClass
Curried :: string->string->object|array->object->array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$key |
mixed | |
$...$newKey |
mixed | |
$...$obj |
mixed |
path
Obj::path( mixed $...$path, mixed $...$obj ): callable|mixed
Curried :: array->Collection|array|object->mixed|null
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$path |
mixed | |
$...$obj |
mixed |
pathOr
Obj::pathOr( mixed $...$default, mixed $...$path, mixed $...$obj ): callable|mixed
Curried :: mixed → array → Collection|array|object → mixed
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$default |
mixed | |
$...$path |
mixed | |
$...$obj |
mixed |
assoc
Obj::assoc( mixed $...$key, mixed $...$value, mixed $...$item ): callable
Curried :: string->mixed->Collection|array|object->mixed|null
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$key |
mixed | |
$...$value |
mixed | |
$...$item |
mixed |
assocPath
Obj::assocPath( mixed $...$path, mixed $...$value, mixed $...$item ): callable
Curried :: array->mixed->Collection|array|object->mixed|null
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$path |
mixed | |
$...$value |
mixed | |
$...$item |
mixed |
lens
Obj::lens( mixed $...$getter, mixed $...$setter ): callable
Curried :: callable->callable->callable
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$getter |
mixed | |
$...$setter |
mixed |
lensProp
Obj::lensProp( mixed $...$prop ): callable
Curried :: string->callable
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$prop |
mixed |
lensPath
Obj::lensPath( mixed $...$path ): callable
Curried :: array->callable
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$path |
mixed |
lensMapped
Obj::lensMapped( mixed $...$toFunctorFn ): callable
Curried :: callable->callable
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$toFunctorFn |
mixed |
lensMappedProp
Obj::lensMappedProp( mixed $...$prop ): callable
Curried :: string->callable
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$prop |
mixed |
view
Obj::view( mixed $...$lens, mixed $...$obj ): callable
Curried :: callable->Collection|array|object->mixed
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$lens |
mixed | |
$...$obj |
mixed |
set
Obj::set( mixed $...$lens, mixed $...$value, mixed $...$obj ): callable
Curried :: callable->mixed->Collection|array|object->mixed
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$lens |
mixed | |
$...$value |
mixed | |
$...$obj |
mixed |
over
Obj::over( mixed $...$lens, mixed $...$transformation, mixed $...$obj ): callable
Curried :: callable->callable->Collection|array|object->mixed
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$lens |
mixed | |
$...$transformation |
mixed | |
$...$obj |
mixed |
pick
Obj::pick( mixed $...$props, mixed $...$obj ): callable
Curried :: array->Collection|array->Collection|array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$props |
mixed | |
$...$obj |
mixed |
pickAll
Obj::pickAll( mixed $...$props, mixed $...$obj ): callable
Curried :: array->Collection|array->Collection|array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$props |
mixed | |
$...$obj |
mixed |
pickBy
Obj::pickBy( mixed $...$predicate, mixed $...$obj ): callable
Curried :: ( ( v, k ) → bool ) → Collection|array->Collection|array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$predicate |
mixed | |
$...$obj |
mixed |
pickByKey
Obj::pickByKey( mixed $...$predicate, mixed $...$obj ): callable
Curried :: ( ( k ) → bool ) → Collection|array->callable|Collection|array|object
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$predicate |
mixed | |
$...$obj |
mixed |
project
Obj::project( mixed $...$props, mixed $...$target ): callable
Curried :: array->Collection|array->Collection|array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$props |
mixed | |
$...$target |
mixed |
where
Obj::where( array $condition ): callable
Curried :: [string → ( * → bool )] → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$condition |
array |
has
Obj::has( mixed $...$prop, mixed $...$item ): callable|boolean
Curried :: string → a → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$prop |
mixed | |
$...$item |
mixed |
evolve
Obj::evolve( mixed $...$transformations, mixed $...$item ): callable|mixed
Curried :: array → array → array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$transformations |
mixed | |
$...$item |
mixed |
objOf
Obj::objOf( mixed $...$key, mixed $...$value ): callable|array
- Curried :: string->mixed->array
Creates an object containing a single key:value pair.
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$key |
mixed | |
$...$value |
mixed |
keys
Obj::keys( mixed $...$obj ): callable|array
- Curried :: object|array->array
Returns
- keys if argument is an array
- public properties' names if argument is an object
- keys if argument is Collection
$this->assertEquals( [ 0, 1, 2 ], Obj::keys( [ 'a', 'b', 'c' ] ) );
$this->assertEquals( [ 'a', 'b', 'c' ], Obj::keys( [ 'a' => 1, 'b' => 2, 'c' => 3 ] ) );
$this->assertEquals( [ 0, 1, 2 ], Obj::keys( \wpml_collect( [ 'a', 'b', 'c' ] ) ) );
$this->assertEquals( [ 'a', 'b', 'c' ], Obj::keys( \wpml_collect( [ 'a' => 1, 'b' => 2, 'c' => 3 ] ) ) );
$this->assertEquals( [ 'a', 'b', 'c' ], Obj::keys( (object) [ 'a' => 1, 'b' => 2, 'c' => 3 ] ) );
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$obj |
mixed |
values
Obj::values( mixed $...$obj ): callable|array
- Curried :: object|array->array
Returns
- values if argument is an array
- public properties' values if argument is an object
- values if argument is Collection
$this->assertEquals( [ 'a', 'b', 'c' ], Obj::values( [ 'a', 'b', 'c' ] ) );
$this->assertEquals( [ 1, 2, 3 ], Obj::values( [ 'a' => 1, 'b' => 2, 'c' => 3 ] ) );
$this->assertEquals( [ 'a', 'b', 'c' ], Obj::values( \wpml_collect( [ 'a', 'b', 'c' ] ) ) );
$this->assertEquals( [ 1, 2, 3 ], Obj::values( \wpml_collect( [ 'a' => 1, 'b' => 2, 'c' => 3 ] ) ) );
$this->assertEquals( [ 1, 2, 3 ], Obj::values( (object) [ 'a' => 1, 'b' => 2, 'c' => 3 ] ) );
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$obj |
mixed |
replaceRecursive
Obj::replaceRecursive( mixed $array, mixed $...$target ): callable|array
Curried :: array->array->array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$array |
mixed | |
$...$target |
mixed |
toArray
Obj::toArray( mixed $Collection|Object ): callable|array
Curried :: Collection|Object->array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
| `$Collection | Object` | mixed |
init
Obj::init( ): void
- This method is static.
without
Curried :: mixed → array|object|Collection → array|object|Collection function to remove an item by key from an array.
Obj::without( string|integer $key = null, array|object|\WPML\Collect\Support\Collection|null $item = null ): callable|array|object|\WPML\Collect\Support\Collection
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$key |
string|integer | |
$item |
array|object|\WPML\Collect\Support\Collection|null |
Relation
- Full name: \WPML\FP\Relation
equals
Relation::equals( mixed $...$a, mixed $...$b ): callable|boolean
Curried :: a->b->bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
lt
Relation::lt( mixed $...$a, mixed $...$b ): callable|boolean
Curried :: a->b->bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
lte
Relation::lte( mixed $...$a, mixed $...$b ): callable|boolean
Curried :: a->b->bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
gt
Relation::gt( mixed $...$a, mixed $...$b ): callable|boolean
Curried :: a->b->bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
gte
Relation::gte( mixed $...$a, mixed $...$b ): callable|boolean
Curried :: a->b->bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
propEq
Relation::propEq( mixed $...$prop, mixed $...$value, mixed $...$obj ): callable|boolean
Curried :: String → a → array → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$prop |
mixed | |
$...$value |
mixed | |
$...$obj |
mixed |
sortWith
Relation::sortWith( mixed $...$comparators, mixed $...$array ): callable|array
Curried :: [(a, a) → int] → [a] → [a]
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$comparators |
mixed | |
$...$array |
mixed |
init
Relation::init( ): void
- This method is static.
Str
- Full name: \WPML\FP\Str
tail
Str::tail( mixed $string ): string
Curried :: string->string
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$string |
mixed |
split
Str::split( mixed $...$delimiter, mixed $...$str ): array
Curried :: string->string->string
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$delimiter |
mixed | |
$...$str |
mixed |
includes
Str::includes( mixed $...$needle, mixed $...$str ): callable|boolean
Curried :: string → string → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$needle |
mixed | |
$...$str |
mixed |
trim
Str::trim( mixed $...$trim, mixed $...$str ): callable|string
Curried :: string → string → string
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$trim |
mixed | |
$...$str |
mixed |
trimPrefix
Str::trimPrefix( mixed $...$trim, mixed $...$str ): callable|string
- Curried :: string → string → string
Trims the prefix from the start of the string if the prefix exists
$trimmed = Str::trimPrefix( 'prefix-', 'prefix-test' );
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$trim |
mixed | |
$...$str |
mixed |
concat
Str::concat( mixed $...$a, mixed $...$b ): callable|string
Curried :: string → string → string
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$a |
mixed | |
$...$b |
mixed |
sub
Str::sub( mixed $...$start, mixed $...$str ): callable|string
Curried :: int → string → string
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$start |
mixed | |
$...$str |
mixed |
startsWith
Str::startsWith( mixed $...$test, mixed $...$str ): callable|string
Curried :: string → string → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$test |
mixed | |
$...$str |
mixed |
endsWith
Str::endsWith( mixed $...$test, mixed $...$str ): callable|string
Curried :: string → string → bool
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$test |
mixed | |
$...$str |
mixed |
pos
Str::pos( mixed $...$test, mixed $...$str ): callable|integer
Curried :: string → string → int
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$test |
mixed | |
$...$str |
mixed |
len
Str::len( mixed $...$str ): callable|integer
Curried :: string → int
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$str |
mixed |
replace
Str::replace( mixed $...$find, mixed $...$replace, mixed $...$str ): callable|string
Curried :: string → string → string → string
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$find |
mixed | |
$...$replace |
mixed | |
$...$str |
mixed |
pregReplace
Str::pregReplace( mixed $...$pattern, mixed $...$replace, mixed $...$str ): callable|string
Curried :: string → string → string → string
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$pattern |
mixed | |
$...$replace |
mixed | |
$...$str |
mixed |
match
Str::match( mixed $...$pattern, mixed $...$str ): callable|string
Curried :: string → string → array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$pattern |
mixed | |
$...$str |
mixed |
matchAll
Str::matchAll( mixed $...$pattern, mixed $...$str ): callable|string
Curried :: string → string → array
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$pattern |
mixed | |
$...$str |
mixed |
wrap
Str::wrap( mixed $...$before, mixed $...$after, mixed $...$str ): callable|string
Curried :: string → string → string
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$...$before |
mixed | |
$...$after |
mixed | |
$...$str |
mixed |
toUpper
Str::toUpper( mixed $string ): callable|string
Curried :: string → string
This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$string |
mixed |
toLower
Str::toLower( mixed $string ): callable|string
- Curried :: string → string
Wraps a string inside 2 other strings
$wrapsInDiv = Str::wrap( '<div>', '</div>' );
$wrapsInDiv( 'To be wrapped' ); // '<div>To be wrapped</div>'
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$string |
mixed |
init
Str::init( ): void
- This method is static.
This document was automatically generated from source code comments on 2022-03-07 using phpDocumentor and cvuorinen/phpdoc-markdown-public