You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* develop:
specify next release
add Sequence::via()
add deprecation notice in the documentation for Sequence::indexOf()
deprecate Sequence::indexOf()
use date range in license copyright
typo
add deprecation notice
add snap documenation
deprecate Set::defer()
add Set::snap()
remove old Set implementation
directly use a Sequence as a Set implementation
add Sequence::snap()
This method configures the `Sequence` via the provided callable. It allows a more fluent API when the code to modify the `Sequence` lies elsewhere and may be dynamic.
->map(static fn($line) => \strtoupper($line)) // still no line loaded here
815
863
->memoize(); // load all lines and apply strtoupper on each
816
864
```
865
+
866
+
### `->snap()`
867
+
868
+
This method indicates that the `Sequence` will be [memoized](#-memoize) when a method that needs to load the data is called.
869
+
870
+
```php
871
+
$sequence = Sequence::lazy(function() {
872
+
$stream = \fopen('some-file', 'r');
873
+
while (!\feof($stream)) {
874
+
yield \fgets($stream);
875
+
}
876
+
})
877
+
->map(static fn($line) => \trim($line, "\n"))
878
+
->exclude(static fn($line) => $line === '')
879
+
->snap()
880
+
->map(static fn($line) => \strtoupper($line)); // still no line loaded here
881
+
```
882
+
883
+
Unlike `->memoize()`, if no code after this needs to access the data then nothing is loaded but it some does then it will load all non empty lines at once.
->map(static fn($line) => \strtoupper($line)) // still no line loaded here
446
449
->memoize(); // load all lines and apply strtoupper on each
447
450
```
451
+
452
+
### `->snap()`
453
+
454
+
This method indicates that the `Set` will be [memoized](#-memoize) when a method that needs to load the data is called.
455
+
456
+
```php
457
+
$sequence = Set::lazy(function() {
458
+
$stream = \fopen('some-file', 'r');
459
+
while (!\feof($stream)) {
460
+
yield \fgets($stream);
461
+
}
462
+
})
463
+
->map(static fn($line) => \trim($line, "\n"))
464
+
->exclude(static fn($line) => $line === '')
465
+
->snap()
466
+
->map(static fn($line) => \strtoupper($line)); // still no line loaded here
467
+
```
468
+
469
+
Unlike `->memoize()`, if no code after this needs to access the data then nothing is loaded but it some does then it will load all non empty lines at once.
0 commit comments