General

The structural backbone of the library. compose() and pipe() stitch smaller functions into bigger ones; the property accessors bridge arrays and objects with a single API; the combinators (always, ifThen, ifElse, sideEffect) handle common higher-order control flow.

Compose vs pipe

compose returns a Closure you can reuse. pipe takes a value and threads it through immediately.

// Build once, reuse.
$slugify = F\compose('trim', 'strtolower', Str\replaceWith(' ', '-'));
$slugify('  Hello World  ');           // 'hello-world'

// Immediate — value in, value out.
F\pipe(
    '  Hello World  ',
    'trim',
    'strtolower',
    Str\replaceWith(' ', '-')
);                                     // 'hello-world'

composeR / pipeR run callables in reverse order. composeSafe halts on the first null; composeTypeSafe halts on a custom type-check failure.

Property access — arrays or objects, one API

$users = [
    ['name' => 'Ada', 'role' => 'admin'],
    ['name' => 'Bea', 'role' => 'user'],
];

$getName  = F\getProperty('name');
$isAdmin  = F\propertyEquals('role', 'admin');

array_map($getName,  $users);          // ['Ada', 'Bea']
array_filter($users, $isAdmin);        // [ ['name' => 'Ada', ...] ]

pluckProperty follows a nested path. hasProperty is the existence predicate. setProperty is the curried setter. encodeProperty + recordEncoder build a new record from scratch.

Combinators

$toIntOrZero = F\ifElse(
    'is_numeric',
    'intval',
    F\always(0)
);

$toIntOrZero('42');                    // 42
$toIntOrZero('nope');                  // 0

Also: ifThen (apply a transform only when a predicate matches), sideEffect (run a callable for its side effect and return the input unchanged — great for logging inside a pipeline), invoker (wrap a callable into a uniform Closure).

Deep-dive examples

General Functions