scalp icon indicating copy to clipboard operation
scalp copied to clipboard

Shorthand for creating function that calls a method on its arguments

Open pawaclawczyk opened this issue 7 years ago • 0 comments

Example of usage with map method.

class Counter
{
    public static function zero(): Counter
    {
        ...
    }

    public function increment(int $step = 1): Counter
    {
        ...
    }
}

$res0 = Some(Counter::zero())
    ->map(__::increment())
    ->map(__::increment())
;

println($res0);

$res1 = $res0
    ->map(__::increment(3))
;

println($res1);
Some[Counter](Counter(2))
Some[Counter](Counter(5))

pawaclawczyk avatar Sep 16 '17 16:09 pawaclawczyk