option
1<?php
2
3declare(strict_types=1);
4
5namespace Upside\Std;
6
7if (!\function_exists(__NAMESPACE__ . '\some')) {
8/**
9* @template T of callable|object|array<mixed>|string|float|int|bool
10* @phpstan-param T $value
11* @phpstan-return Option<T>
12*/
13function Some(callable|object|iterable|string|float|int|bool $value): Option
14{
15return new Some($value);
16}
17}
18
19if (!\function_exists(__NAMESPACE__ . '\none')) {
20/**
21* @phpstan-return Option<null>
22*/
23function None(): Option
24{
25return new None();
26}
27}
28
29if (!\function_exists(__NAMESPACE__ . '\from')) {
30/**
31* @template T of callable|object|array<mixed>|string|float|int|bool|null
32* @param T $value
33* @phpstan-return (T is null ? Option<null> : Option<T>)
34*/
35function From(mixed $value = null): Option
36{
37return null === $value ? new None() : new Some($value);
38}
39}
40