1. Go to this page and download the library: Download crell/fp library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
crell / fp example snippets
use function Crell\fp\pipe;
$result = pipe(5,
static fn ($in) => $in ** 4, // Returns 625
static fn ($in) => $in / 4, // Returns 156.25
static fn ($in) => (string)$in, // Coerces the number to a string
strlen(...), // Returns the length of the string
);
// $result is now 6, because "156.25" has 6 characters in it.
use function Crell\fp\explode;
$result = pipe("Hello world",
explode(' '), // Produces ['Hello', 'world']
count(...), // Returns tne number of array elements, which is 2
);
// $result is now 2
// or
$words = explode(' ')("Hello World");
// $words is now ['Hello', 'world']
use Crell\fp\Evolvable;
readonly class Person
{
use Evolvable;
public function __construct(
public string $name,
public int $age,
public string $jobTitle,
) {}
}
$p = new Person("Larry");
$p2 = $p->with(age: 18, jobTitle: "Developer");
use Crell\fp\Newable;
readonly class Person
{
use Newable;
public function __construct(
public string $name,
public int $age,
public string $jobTitle,
) {}
}
$p = Person::new("Larry", 18, "Developer");