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 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.9.0 4.9.1 5.0.1 5.0.2 5.1.1 5.1.2 5.1.3 5.2.0 5.2.1 5.3.2 5.3.3.1 5.3.4 5.3.5 5.3.6 5.3.7
woocommerce-multilingual / vendor / otgs / installer / includes / utilities / FP / Either.php
woocommerce-multilingual / vendor / otgs / installer / includes / utilities / FP Last commit date
Traits 1 month ago Either.php 1 month ago Fns.php 1 month ago Invoker.php 1 month ago Logic.php 1 month ago Obj.php 1 month ago Relation.php 1 month ago Str.php 1 month ago Undefined.php 1 month ago functions.php 1 month ago
Either.php
158 lines
1 <?php
2
3 namespace OTGS\Installer\FP;
4
5 use OTGS\Installer\Collect\Support\Macroable;
6 use OTGS\Installer\FP\Traits\Functor;
7 use OTGS\Installer\FP\Traits\Pointed;
8 use OTGS\Installer\FP\Traits\ConstApplicative;
9 use OTGS\Installer\FP\Traits\Applicative;
10
11 abstract class Either {
12 use Functor;
13 use Macroable;
14
15 public static function init() {
16 self::macro( 'of', Right::of() );
17
18 self::macro( 'left', Left::of() );
19
20 self::macro( 'right', Right::of() );
21
22 self::macro( 'fromNullable', curryN( 1, function ( $value ) {
23 return is_null( $value ) ? self::left( $value ) : self::right( $value );
24 } ) );
25
26 self::macro( 'fromBool', curryN( 1, function ( $value ) {
27 return (bool) $value ? self::right( $value ) : self::left( $value );
28 } ) );
29
30 }
31
32 public function join() {
33 if ( ! $this->value instanceof Either ) {
34 return $this;
35 }
36
37 return $this->value->join();
38 }
39
40 abstract public function chain( callable $fn );
41
42 abstract public function bichain( callable $leftFn, callable $rightFn);
43
44 abstract public function orElse( callable $fn );
45 abstract public function bimap( callable $leftFn, callable $rightFn );
46 abstract public function coalesce( callable $leftFn, callable $rightFn );
47 abstract public function alt( Either $alt );
48 abstract public function filter( callable $fn );
49
50 }
51
52 class Left extends Either {
53
54 use ConstApplicative;
55 use Pointed;
56
57 public function map( callable $fn ) {
58 return $this;
59 }
60
61 public function bimap( callable $leftFn, callable $rightFn ) {
62 return Either::left( $leftFn( $this->value ) );
63 }
64
65 public function coalesce( callable $leftFn, callable $rightFn ) {
66 return Either::of( $leftFn( $this->value ) );
67 }
68
69 public function get() {
70 throw new \Exception( "Can't extract the value of Left" );
71 }
72
73 public function getOrElse( $other ) {
74 return $other;
75 }
76
77 public function orElse( callable $fn ) {
78 return Either::right( $fn( $this->value ) );
79 }
80
81 public function chain( callable $fn ) {
82 return $this;
83 }
84
85 public function bichain( callable $leftFn, callable $rightFn ) {
86 return $leftFn( $this->value );
87 }
88
89 public function getOrElseThrow( $value ) {
90 throw new \Exception( $value );
91 }
92
93 public function filter( callable $fn ) {
94 return $this;
95 }
96
97 public function tryCatch( callable $fn ) {
98 return $this;
99 }
100
101 public function alt( Either $alt ) {
102 return $alt;
103 }
104 }
105
106 class Right extends Either {
107
108 use Applicative;
109 use Pointed;
110
111 public function map( callable $fn ) {
112 return Either::of( $fn( $this->value ) );
113 }
114
115 public function bimap( callable $leftFn, callable $rightFn ) {
116 return $this->map( $rightFn );
117 }
118
119 public function coalesce( callable $leftFn, callable $rightFn ) {
120 return $this->map( $rightFn );
121 }
122
123 public function getOrElse( $other ) {
124 return $this->value;
125 }
126
127 public function orElse( callable $fn ) {
128 return $this;
129 }
130
131 public function getOrElseThrow( $value ) {
132 return $this->value;
133 }
134
135 public function chain( callable $fn ) {
136 return $this->map( $fn )->join();
137 }
138
139 public function bichain( callable $leftFn, callable $rightFn ) {
140 return $rightFn( $this->value );
141 }
142
143 public function filter( callable $fn ) {
144 return Logic::ifElse( $fn, Either::right(), Either::left(), $this->value );
145 }
146
147 public function tryCatch( callable $fn ) {
148 return tryCatch( function () use ( $fn ) {
149 return $fn( $this->value );
150 } );
151 }
152
153 public function alt( Either $alt ) {
154 return $this;
155 }
156 }
157
158 Either::init();