option
1<?php
2
3declare(strict_types=1);
4
5namespace Upside\Std;
6
7/**
8* @template T of callable|object|array<mixed>|string|float|int|bool|null
9*/
10interface Option
11{
12public function is_none(): bool;
13
14public function is_some(): bool;
15
16public function is_some_and(callable $op): bool;
17
18/**
19* @throws \Exception
20* @phpstan-return (T is null ? never : T)
21*/
22public function expect_or(\Exception $e): callable|object|iterable|string|float|int|bool;
23
24/**
25* @throws \RuntimeException
26* @phpstan-return (T is null ? never : T)
27*/
28public function expect(string $msg): callable|object|iterable|string|float|int|bool;
29
30/**
31* @throws \RuntimeException
32* @phpstan-return (T is null ? never : T)
33*/
34public function unwrap(): callable|object|iterable|string|float|int|bool;
35
36/**
37* @template D of callable|object|array<mixed>|string|float|int|bool
38* @phpstan-param D $default
39* @phpstan-return (T is null ? D : T)
40*/
41public function unwrap_or(callable|object|iterable|string|float|int|bool $default): callable|object|iterable|string|float|int|bool;
42
43/**
44* @template D of callable|object|array<mixed>|string|float|int|bool
45* @phpstan-param callable():D $op
46* @phpstan-return (T is null ? D : T)
47*/
48public function unwrap_or_else(callable $op): callable|object|iterable|string|float|int|bool;
49}
50