// THIS IS A FIRST EXAMPLE TITLE - 1
public function of(...$cases)
{
return (new ListCollection($cases))
->any(function (AbstractWhen $case) {
return $case->matches($this->matched);
})
->map(function (AbstractWhen $case) {
return $case->getResult($this->matched);
})
->getOrCall(function () {
throw new NoMatchFoundException();
});
}
$this->maybeString()
->map(function (string $existingString){
return 'Yes we have it: ' . $existingString;
})
->getOrElse('No, we don\'t');
$this->update($domainObject)
->right($this->successfulResponse())
->left($this->failWithGrace())
->get();
Match::val("test 123")->of(
When::typeOf(Option::class, "maybe string"),
When::results(function ($item) {
return $item == "test";
}, "equal to test"),
When::equals("test", "oh my, it was that easy"),
When::other("default result")
)
← swipe to see rest of code →
function avgOfTopTenBiggestEvenNumbersWithMessage(
ParallelListCollection $numbers, string $message)
{
return $numbers
->filter($this->isEven())
->sort()
->slice(0, 10)
->avg()
->map(function (int $number) use ($message) {
return $number . $message;
});
}
public function search(string $query) : ListCollection
{
return Future::all([
$this->textService->search($query),
$this->imageService->search($query),
$this->videoService->search($query),
])
->map(function (ListCollection $searchResults) {
return $searchResults->flatten()->sort();
})
->await();
}
function tailRecursiveFibonacci(
int $index,
int $previous = 0,
int $next = 1) : Trampoline
{
return ($index <= 1)
? new Done($index == 0 ? $previous : $next)
: new Bounce(function () use (
$index, $next, $previous) {
return $this
->tailRecursiveFibonacci(
$index - 1,
$next,
$next + $previous
);
});
}