scalp
scalp copied to clipboard
Some Scala useful classes ported to PHP.
At this moment `Success::flatMap` and `Failure::recoverWith` functions use function `restrictCallableReturnType` to check whether callable passed as argument has defined return type to `TryCatch`. It rises `TypeError` in case when return...
Type partial function represents a function which is undefined for some elements of the domain. ### Example `f(x) = 42 / x` is not defined at `x` equal `0` ###...
In some of methods in Scala's implementation of `Option` and `Try` parameters are passed by name. In PHP we do not have such possibility and we have to pass evaluated...
https://github.com/pawaclawczyk/scalp/blob/0c0d6544688de3e091142d349beda68b26fbca4a/.php_cs#L20 https://github.com/pawaclawczyk/scalp/blob/0c0d6544688de3e091142d349beda68b26fbca4a/src/Scalp/PatternMatching/Value.php#L22-L24
`Scalp\PatternMatching\Deconstruction` trait provides `construct` and `deconstruct` methods, holds internally data that represents construction arguments. Problem related with current implementation: 1. `Destruction::construct` must be called manually with right arguments. It's easy...
Example of current usage of regular expression. ``` private function elementId(string $propertyName): Option { preg_match('/^_(\d+)$/', $propertyName, $matches); return isset($matches[1]) ? Some((int) $matches[1]) : None(); } ```
`flatMap`s and `recoverWith` are protected with check that ensures the passed callable will return an expected type ie. `Option` or `TryCatch`. In case of passing partially applied function the real...
Example of usage with `map` method. ```php class Counter { public static function zero(): Counter { ... } public function increment(int $step = 1): Counter { ... } } $res0...