Commit a26cc19 1 parent d772aa6 commit a26cc19 Copy full SHA for a26cc19
File tree 2 files changed +79
-0
lines changed
2 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -181,4 +181,37 @@ static function($assert, $values) {
181
181
$ assert ->same (2 , $ loaded );
182
182
},
183
183
);
184
+
185
+ yield proof (
186
+ 'Identity::defer() holds intermediary values ' ,
187
+ given (
188
+ Set \Type::any (),
189
+ Set \Type::any (),
190
+ ),
191
+ static function ($ assert , $ value1 , $ value2 ) {
192
+ $ m1 = Identity::defer (static function () use ($ value1 ) {
193
+ static $ loaded = false ;
194
+
195
+ if ($ loaded ) {
196
+ throw new Exception ;
197
+ }
198
+
199
+ $ loaded = true ;
200
+
201
+ return $ value1 ;
202
+ });
203
+ $ m2 = $ m1 ->map (static fn () => $ value2 );
204
+
205
+ $ assert ->same (
206
+ $ value2 ,
207
+ $ m2 ->unwrap (),
208
+ );
209
+ $ assert ->not ()->throws (
210
+ static fn () => $ assert ->same (
211
+ $ value1 ,
212
+ $ m1 ->unwrap (),
213
+ ),
214
+ );
215
+ },
216
+ );
184
217
};
Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types = 1 );
3
+
4
+ use Innmind \Immutable \Maybe ;
5
+ use Innmind \BlackBox \Set ;
6
+
7
+ return static function () {
8
+ yield proof (
9
+ 'Maybe::defer() holds intermediary values ' ,
10
+ given (
11
+ Set \Type::any (),
12
+ Set \Type::any (),
13
+ ),
14
+ static function ($ assert , $ value1 , $ value2 ) {
15
+ $ m1 = Maybe::defer (static function () use ($ value1 ) {
16
+ static $ loaded = false ;
17
+
18
+ if ($ loaded ) {
19
+ throw new Exception ;
20
+ }
21
+
22
+ $ loaded = true ;
23
+
24
+ return Maybe::just ($ value1 );
25
+ });
26
+ $ m2 = $ m1 ->map (static fn () => $ value2 );
27
+
28
+ $ assert ->same (
29
+ $ value2 ,
30
+ $ m2 ->match (
31
+ static fn ($ value ) => $ value ,
32
+ static fn () => null ,
33
+ ),
34
+ );
35
+ $ assert ->not ()->throws (
36
+ static fn () => $ assert ->same (
37
+ $ value1 ,
38
+ $ m1 ->match (
39
+ static fn ($ value ) => $ value ,
40
+ static fn () => null ,
41
+ ),
42
+ ),
43
+ );
44
+ },
45
+ );
46
+ };
You can’t perform that action at this time.
0 commit comments