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
Copy file name to clipboardExpand all lines: collections.md
+29-1Lines changed: 29 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -175,6 +175,7 @@ For the remainder of this documentation, we'll discuss each method available on
175
175
[unless](#method-unless)
176
176
[unlessEmpty](#method-unlessempty)
177
177
[unlessNotEmpty](#method-unlessnotempty)
178
+
[until](#method-until)
178
179
[unwrap](#method-unwrap)
179
180
[values](#method-values)
180
181
[when](#method-when)
@@ -2150,6 +2151,33 @@ Alias for the [`whenNotEmpty`](#method-whennotempty) method.
2150
2151
2151
2152
Alias for the [`whenEmpty`](#method-whenempty) method.
2152
2153
2154
+
<aname="method-until"></a>
2155
+
#### `until()` {#collection-method}
2156
+
2157
+
The `until` method returns items in the collection until the given value is found:
2158
+
2159
+
$collection = collect([1, 2, 3, 4]);
2160
+
2161
+
$subset = $collection->until(3);
2162
+
2163
+
$subset->all();
2164
+
2165
+
// [1, 2]
2166
+
2167
+
You may also pass a callback to the `until` method to perform your own logic. The callback should return `true` when the `until` method should stop.
2168
+
2169
+
$collection = collect([1, 2, 3, 4]);
2170
+
2171
+
$subset = $collection->until(function ($item) {
2172
+
return $item >= 3;
2173
+
});
2174
+
2175
+
$subset->all();
2176
+
2177
+
// [1, 2]
2178
+
2179
+
If the given value is not found or callback does not return `true`, the `until` method will return all items in the collection.
2180
+
2153
2181
<aname="method-unwrap"></a>
2154
2182
#### `unwrap()` {#collection-method}
2155
2183
@@ -2552,7 +2580,7 @@ The `zip` method merges together the values of the given array with the values o
2552
2580
<aname="higher-order-messages"></a>
2553
2581
## Higher Order Messages
2554
2582
2555
-
Collections also provide support for "higher order messages", which are short-cuts for performing common actions on collections. The collection methods that provide higher order messages are: [`average`](#method-average), [`avg`](#method-avg), [`contains`](#method-contains), [`each`](#method-each), [`every`](#method-every), [`filter`](#method-filter), [`first`](#method-first), [`flatMap`](#method-flatmap), [`groupBy`](#method-groupby), [`keyBy`](#method-keyby), [`map`](#method-map), [`max`](#method-max), [`min`](#method-min), [`partition`](#method-partition), [`reject`](#method-reject), [`some`](#method-some), [`sortBy`](#method-sortby), [`sortByDesc`](#method-sortbydesc), [`sum`](#method-sum), and [`unique`](#method-unique).
2583
+
Collections also provide support for "higher order messages", which are short-cuts for performing common actions on collections. The collection methods that provide higher order messages are: [`average`](#method-average), [`avg`](#method-avg), [`contains`](#method-contains), [`each`](#method-each), [`every`](#method-every), [`filter`](#method-filter), [`first`](#method-first), [`flatMap`](#method-flatmap), [`groupBy`](#method-groupby), [`keyBy`](#method-keyby), [`map`](#method-map), [`max`](#method-max), [`min`](#method-min), [`partition`](#method-partition), [`reject`](#method-reject), [`some`](#method-some), [`sortBy`](#method-sortby), [`sortByDesc`](#method-sortbydesc), [`sum`](#method-sum), [`unique`](#method-unique), and [`until`](#method-until).
2556
2584
2557
2585
Each higher order message can be accessed as a dynamic property on a collection instance. For instance, let's use the `each` higher order message to call a method on each object within a collection:
0 commit comments