Skip to content

Object Functions

All functions below are in the Cline\fp namespace.

Returns the $prop public property of a piped object.

use function Cline\fp\prop;
class Person {
public function __construct(public string $name) {}
}
$name = pipe(new Person('Alice'),
prop('name')
);
// $name is 'Alice'

Invokes $method on a piped object using $args as arguments. Both positional and named arguments are supported.

use function Cline\fp\method;
class Calculator {
public function add(int $a, int $b): int {
return $a + $b;
}
}
$result = pipe(new Calculator(),
method('add', 5, 3)
);
// $result is 8

Returns true if a piped value is of the specified type, false otherwise. Legal types are int, string, float, bool, array, resource, or a class/interface name. This will usually be the last function in a pipe.

use function Cline\fp\typeIs;
$isString = pipe("Hello",
typeIs('string')
);
// $isString is true
$isPerson = pipe(new Person('Alice'),
typeIs(Person::class)
);
// $isPerson is true