PHP code example of kikytokamuro / futils

1. Go to this page and download the library: Download kikytokamuro/futils 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/ */

    

kikytokamuro / futils example snippets


Futils\all(fn($x) => $x > 100)([101, 102, 103]) // => true

Futils\always(true)() // => true

Futils\any(fn($x) => $x == 100)([1, 2, 100]) // => true

Futils\compose(fn($x) => $x + 1, fn($x) => $x * 100)(2) // => 201

Futils\contains(1337)([1, 1337, 2]) // => true

Futils\difference([1, 2, 3, 4])([1, 2]) // => [3, 4]

Futils\drop(2)([1, 2, 3, 4]) // => [3, 4]

Futils\filter(fn($x) => $x > 0)([-1, -2, 1, 2]) // => [1, 2]

Futils\find(fn($x) => $x > 10)([1, 2, 11]) // => 11

Futils\flatten([1, [2, [3, [4]]]]) // => [1, 2, 3, 4]

Futils\has("test")(["test" => 1]) // => true

Futils\head([1, 2, 3]) // => 1

Futils\indexOf("test")([1, "test", 3]) // => 1

Futils\join([1, 2, 3])("|") // => "1|2|3"

Futils\last([1, 2, 3, 4]) // => 4

Futils\map(fn($x) => $x + 1)([1, 2, 3]) // => [2, 3, 4]

Futils\merge([1, 2])([3, 4]) // => [1, 2, 3, 4]

Futils\partial(fn($x, $y, $z) => $x + $y + $z)(1, 2)(3) // => 6

Futils\partition(fn($x) => $x > 0)([-1, -2, 1, 2]) // => [[1, 2], [-1, -2]]

Futils\pipe(fn($x) => $x + 1, fn($x) => $x * 100)(1) // => 200

Futils\reduce(fn($x, $y) => $x + $y)([1, 2, 3]) // => 6

Futils\reject(fn($x) => $x > 0)([-1, -2, 1, 2]) // => [-1, -2]

Futils\replace([1, 2, 3])([1 => 3, 2 => 2]) // => [1, 3, 2]

Futils\tail([1, 2, 3, 4, 5]) // => [2, 3, 4, 5]

Futils\take(2)([1, 2, 3, 4]) // => [1, 2]

Futils\when(fn($x) => $x > 100)(fn($x) => $x + 5)(1000) // => 1005

Futils\zip([1, 2, 3])([4, 5, 6]) // => [[1, 4], [2, 5], [3, 6]]

(new Futils\IdentityMonad(100))
    ->bind(fn($x, $n) => $x * $n, 2)
    ->bind("strval")
    ->extract() // => "200"

(new Futils\MaybeMonad("test"))
    ->bind(fn() => null)
    ->bind(fn($x) => $x + 1)
    ->extract() // => null

(new Futils\ListMonad([1, new IdentityMonad(2), new MaybeMonad(3), new ListMonad([4])]))
    ->bind(fn($x) => $x + 100)
    ->extract() // => [101, 102, 103, [104]]