3 * Copyright (c) 2014, Facebook, Inc.
6 * This source code is licensed under the MIT license found in the
7 * LICENSE file in the "hack" directory of this source tree.
12 * This file provides type information for some of hack's reactive interfaces
14 * YOU SHOULD NEVER INCLUDE THIS FILE ANYWHERE!!!
19 /* See documentation for \Traversable */
21 namespace\KeyedTraversable::class,
22 namespace\Iterator::class,
23 namespace\IteratorAggregate::class,
26 interface Traversable<+Tv> extends \Traversable<Tv> {}
28 /* See documentation for \KeyedTraversable */
30 namespace\KeyedIterable::class,
31 namespace\KeyedIterator::class,
32 \KeyedContainer::class
34 interface KeyedTraversable<+Tk, +Tv>
35 extends namespace\Traversable<Tv>, \KeyedTraversable<Tk, Tv> {}
37 /* See documentation for \Iterator */
38 interface Iterator<+Tv> extends namespace\Traversable<Tv>, \Iterator<Tv> {
40 * Return the current value at the current iterator position.
42 * @return - The current value of type `Tv`.
44 <<__Rx, __MaybeMutable>>
45 public function current(): Tv;
47 * Move the iterator position to the next element.
51 public function next(): void;
53 * Rewind the iterator position to its beginning.
55 * This rewinds back to the first element of the `Iterator`.
58 public function rewind(): void;
60 * Checks to see if the current iterator position is valid.
62 * This method is called after `rewind()` and `next()` to check if the
63 * current iterator position is valid.
65 * @return - `true` if the position is valid; `false` otherwise.
67 <<__Rx, __MaybeMutable>>
68 public function valid(): bool;
71 interface KeyedIterator<+Tk, +Tv>
73 namespace\KeyedTraversable<Tk, Tv>,
74 namespace\Iterator<Tv>,
75 \KeyedIterator<Tk, Tv> {
77 * Return the current key at the current iterator position.
79 * @return - The current key of type `Tk`.
81 <<__Rx, __MaybeMutable>>
82 public function key(): Tk;
85 /* See documentation for \AsyncIterator */
86 interface AsyncIterator<+Tv> extends \AsyncIterator<Tv> {
88 * Move the async iterator to the next `Awaitable` position.
91 * foreach ($async_iter await $async_iter->next() $value)
94 * The above is the longhand syntax for `await as $value`.
96 * @return - The next `Awaitable` in the iterator sequence.
99 public function next(): Awaitable<?(mixed, Tv)>;
102 /* See documentation for \AsyncKeyedIterator */
103 interface AsyncKeyedIterator<+Tk, +Tv>
104 extends namespace\AsyncIterator<Tv>, \AsyncKeyedIterator<Tk, Tv> {
106 * Move the async iterator to the next `Awaitable` position.
109 * foreach ($async_iter await $async_iter->next() $key=>$value)
112 * The above is the longhand syntax for `await as $key=>$value`.
114 * @return - The next `Awaitable` in the iterator sequence.
117 public function next(): Awaitable<?(Tk, Tv)>;
120 /* See documentation for \IteratorAggregate */
121 interface IteratorAggregate<+Tv>
122 extends namespace\Traversable<Tv>, \IteratorAggregate<Tv> {
124 * Returns an iterator to be used to iterate over the object's elements.
126 * @return - An `Iterator` for iteration.
128 <<__Rx, __MutableReturn, __MaybeMutable>>
129 public function getIterator(): namespace\Iterator<Tv>;
132 interface Iterable<+Tv>
133 extends namespace\IteratorAggregate<Tv>, \Iterable<Tv> {
135 * Returns an iterator that points to beginning of the current `Iterable`.
137 * @return - An `Iterator` that allows you to traverse the current `Iterable`.
139 <<__Rx, __MutableReturn, __MaybeMutable>>
140 public function getIterator(): namespace\Iterator<Tv>;
142 * Returns an `array` converted from the current `Iterable`.
144 * @return - an array converted from the current `Iterable`.
146 <<__Rx, __MaybeMutable>>
147 /* HH_IGNORE_ERROR[2082] T30260145 */
148 public function toArray(): array;
150 * Returns an `array` with the values from the current `Iterable`.
152 * The keys in the current `Iterable` are discarded and replaced with integer
153 * indices, starting with 0.
155 * @return - an `array` containing the values from the current `Iterable`.
157 <<__Rx, __MaybeMutable>>
158 public function toValuesArray(): varray;
160 * Returns a `Vector` converted from the current `Iterable`.
162 * Any keys in the current `Iterable` are discarded and replaced with integer
163 * indices, starting with 0.
165 * @return - a `Vector` converted from the current `Iterable`.
167 <<__Rx, __MutableReturn, __MaybeMutable>>
168 /* HH_FIXME[4120]: While this violates our variance annotations, we are
169 * returning a copy of the underlying collection, so it is actually safe
171 public function toVector(): Vector<Tv>;
173 * Returns an immutable vector (`ImmVector`) converted from the current
176 * Any keys in the current `Iterable` are discarded and replaced with integer
177 * indices, starting with 0.
179 * @return - an `ImmVector` converted from the current `Iterable`.
181 <<__Rx, __MaybeMutable>>
182 public function toImmVector(): ImmVector<Tv>;
184 * Returns a `Set` converted from the current `Iterable`.
186 * Any keys in the current `Iterable` are discarded.
188 * @return - a `Set` converted from the current `Iterable`.
190 <<__Rx, __MutableReturn, __MaybeMutable>>
191 /* HH_FIXME[4120]: While this violates our variance annotations, we are
192 * returning a copy of the underlying collection, so it is actually safe.
194 public function toSet(): Set<Tv>;
196 * Returns an immutable set (`ImmSet`) converted from the current `Iterable`.
198 * Any keys in the current `Iterable` are discarded.
200 * @return - an `ImmSet` converted from the current `Iterable`.
202 <<__Rx, __MaybeMutable>>
203 public function toImmSet(): ImmSet<Tv>;
205 * Returns a lazy, access elements only when needed view of the current
208 * Normally, memory is allocated for all of the elements of the `Iterable`.
209 * With a lazy view, memory is allocated for an element only when needed or
210 * used in a calculation like in `map()` or `filter()`.
212 * @return - an `Iterable` representing the lazy view into the current
215 * @guide /hack/collections/examples
217 <<__Rx, __MutableReturn, __MaybeMutable>>
218 public function lazy(): namespace\Iterable<Tv>;
220 * Returns an `Iterable` containing the current `Iterable`'s values.
222 * Any keys are discarded.
224 * @return An `Iterable` with the values of the current `Iterable`.
226 <<__Rx, __MutableReturn, __MaybeMutable>>
227 public function values(): namespace\Iterable<Tv>;
229 * Returns an `Iterable` containing the values after an operation has been
230 * applied to each value in the current `Iterable`.
232 * Every value in the current `Iterable` is affected by a call to `map()`,
233 * unlike `filter()` where only values that meet a certain criteria are
236 * @param $fn - The callback containing the operation to apply to the
239 * @return - an `Iterable` containing the values after a user-specified
240 * operation is applied.
242 * @guide /hack/collections/examples
244 <<__Rx, __OnlyRxIfArgs, __MutableReturn, __MaybeMutable>>
245 public function map<Tu>(
246 <<__OnlyRxIfRxFunc>>(function(Tv): Tu) $fn,
247 ): namespace\Iterable<Tu>;
249 * Returns an `Iterable` containing the values of the current `Iterable` that
250 * meet a supplied condition.
252 * Only values that meet a certain criteria are affected by a call to
253 * `filter()`, while all values are affected by a call to `map()`.
255 * @param $fn - The callback containing the condition to apply to the
258 * @return - an `Iterable` containing the values after a user-specified
259 * condition is applied.
261 * @guide /hack/collections/examples
263 <<__Rx, __OnlyRxIfArgs, __MutableReturn, __MaybeMutable>>
264 public function filter(
265 <<__OnlyRxIfRxFunc>>(function(Tv): bool) $fn,
266 ): namespace\Iterable<Tv>;
268 * Returns an `Iterable` where each element is a `Pair` that combines the
269 * element of the current `Iterable` and the provided `Traversable`.
271 * If the number of elements of the `Iterable` are not equal to the number of
272 * elements in the `Traversable`, then only the combined elements up to and
273 * including the final element of the one with the least number of elements
276 * @param $traversable - The `Traversable` to use to combine with the
277 * elements of the current `Iterable`.
279 * @return - The `Iterable` that combines the values of the current
280 * `Itearable` with the provided `Traversable`.
282 <<__Rx, __OnlyRxIfArgs, __MutableReturn, __MaybeMutable>>
283 public function zip<Tu>(
284 <<__OnlyRxIfImpl(namespace\Traversable::class)>> \Traversable<Tu> $traversable,
285 ): namespace\Iterable<Pair<Tv, Tu>>;
287 * Returns an `Iterable` containing the first `n` values of the current
290 * The returned `Iterable` will always be a proper subset of the current
293 * `$n` is 1-based. So the first element is 1, the second 2, etc.
295 * @param $n - The last element that will be included in the returned
298 * @return - An `Iterable that is a proper subset of the current `Iterable`
299 * up to `n` elements.
301 <<__Rx, __MutableReturn, __MaybeMutable>>
302 public function take(int $n): namespace\Iterable<Tv>;
304 * Returns an `Iterable` containing the values of the current `Iterable` up
305 * to but not including the first value that produces `false` when passed to
306 * the specified callback.
308 * The returned `Iterable` will always be a proper subset of the current
311 * @param $fn - The callback that is used to determine the stopping
314 * @return - An `Iterable` that is a proper subset of the current `Iterable`
315 * up until the callback returns `false`.
317 <<__Rx, __OnlyRxIfArgs, __MutableReturn, __MaybeMutable>>
318 public function takeWhile(
319 <<__OnlyRxIfRxFunc>>(function(Tv): bool) $fn,
320 ): namespace\Iterable<Tv>;
322 * Returns an `Iterable` containing the values after the `n`-th element of the
323 * current `Iterable`.
325 * The returned `Iterable` will always be a proper subset of the current
328 * `$n` is 1-based. So the first element is 1, the second 2, etc.
330 * @param $n - The last element to be skipped; the `$n+1` element will be
331 * the first one in the returned `Iterable`.
333 * @return - An `Iterable` that is a proper subset of the current `Iterable`
334 * containing values after the specified `n`-th element.
336 <<__Rx, __MutableReturn, __MaybeMutable>>
337 public function skip(int $n): namespace\Iterable<Tv>;
339 * Returns an `Iterable` containing the values of the current `Iterable`
340 * starting after and including the first value that produces `true` when
341 * passed to the specified callback.
343 * The returned `Iterable` will always be a proper subset of the current
346 * @param $fn - The callback used to determine the starting element for the
347 * returned `Iterable`.
349 * @return - An `Iterable` that is a proper subset of the current `Iterable`
350 * starting after the callback returns `true`.
352 <<__Rx, __OnlyRxIfArgs, __MutableReturn, __MaybeMutable>>
353 public function skipWhile(
354 <<__OnlyRxIfRxFunc>>(function(Tv): bool) $fn,
355 ): namespace\Iterable<Tv>;
357 * Returns a subset of the current `Iterable` starting from a given key up
358 * to, but not including, the element at the provided length from the
361 * `$start` is 0-based. `$len` is 1-based. So `slice(0, 2)` would return the
362 * elements at key 0 and 1.
364 * The returned `Iterable` will always be a proper subset of the current
367 * @param $start - The starting key of the current `Iterable` to begin the
368 * returned `Iterable`.
369 * @param $len - The length of the returned `Iterable`.
371 * @return - An `Iterable` that is a proper subset of the current `Iterable`
372 * starting at `$start` up to but not including the element
375 <<__Rx, __MutableReturn, __MaybeMutable>>
376 public function slice(int $start, int $len): namespace\Iterable<Tv>;
378 * Returns an `Iterable` that is the concatenation of the values of the
379 * current `Iterable` and the values of the provided `Traversable`.
381 * The values of the provided `Traversable` is concatenated to the end of the
382 * current `Iterable` to produce the returned `Iterable`.
384 * @param $traversable - The `Traversable` to concatenate to the current
387 * @return - The concatenated `Iterable`.
389 * @guide /hack/generics/constraints
391 <<__Rx, __OnlyRxIfArgs, __MutableReturn, __MaybeMutable>>
392 public function concat<Tu super Tv>(
393 <<__OnlyRxIfImpl(namespace\Traversable::class)>> \Traversable<Tu> $traversable,
394 ): namespace\Iterable<Tu>;
396 * Returns the first value in the current `Iterable`.
398 * @return - The first value in the current `Iterable`, or `null` if the
399 * current `Iterable` is empty.
401 <<__Rx, __MaybeMutable>>
402 public function firstValue(): ?Tv;
404 * Returns the last value in the current `Iterable`.
406 * @return - The last value in the current `Iterable`, or `null` if the
407 * current `Iterable` is empty.
409 <<__Rx, __MaybeMutable>>
410 public function lastValue(): ?Tv;
413 interface KeyedIterable<Tk, +Tv>
415 namespace\KeyedTraversable<Tk, Tv>,
416 namespace\Iterable<Tv>,
417 \KeyedIterable<Tk, Tv> {
419 * Returns an iterator that points to beginning of the current
422 * @return - A `KeyedIterator` that allows you to traverse the current
425 <<__Rx, __MutableReturn, __MaybeMutable>>
426 public function getIterator(): namespace\KeyedIterator<Tk, Tv>;
428 * Returns an `array` with the keys from the current `KeyedIterable`.
430 * @return - an `array` containing the values from the current
433 <<__Rx, __MaybeMutable>>
434 public function toKeysArray(): varray;
436 * Returns a `Map` based on the keys and values of the current
439 * @return - a `Map` that has the keys and associated values of the current
442 <<__Rx, __MutableReturn, __MaybeMutable>>
443 /* HH_FIXME[4120]: While this violates our variance annotations, we are
444 * returning a copy of the underlying collection, so it is actually safe
446 public function toMap(): \Map<Tk, Tv>;
448 * Returns an immutable map (`ImmMap`) based on the keys and values of the
449 * current `KeyedIterable`.
451 * @return - an `ImmMap` that has the keys and associated values of the
452 * current `KeyedIterable`.
454 <<__Rx, __MaybeMutable>>
455 public function toImmMap(): \ImmMap<Tk, Tv>;
457 * Returns a lazy, access elements only when needed view of the current
460 * Normally, memory is allocated for all of the elements of the
461 * `KeyedIterable`. With a lazy view, memory is allocated for an element only
462 * when needed or used in a calculation like in `map()` or `filter()`.
464 * @return - a `KeyedIterable` representing the lazy view into the current
467 * @guide /hack/collections/examples
469 <<__Rx, __MutableReturn, __MaybeMutable>>
470 public function lazy(): namespace\KeyedIterable<Tk, Tv>;
472 * Returns an `Iterable` containing the current `KeyedIterable`'s values.
474 * Any keys are discarded.
476 * @return An `Iterable` with the values of the current `KeyedIterable`.
478 <<__Rx, __MutableReturn, __MaybeMutable>>
479 public function values(): namespace\Iterable<Tv>;
481 * Returns an `Iterable` containing the current `KeyedIterable`'s keys.
483 * Any values are discarded.
485 * @return An `Iterable` with the keys of the current `KeyedIterable`.
487 <<__Rx, __MutableReturn, __MaybeMutable>>
488 public function keys(): namespace\Iterable<Tk>;
490 * Returns a `KeyedIterable` containing the values after an operation has been
491 * applied to each value in the current `KeyedIterable`.
493 * Every value in the current `KeyedIterable` is affected by a call to
494 * `map()`, unlike `filter()` where only values that meet a certain criteria
497 * @param $fn - The callback containing the operation to apply to the
498 * `KeyedIterable` values.
500 * @return - a `KeyedIterable` containing the values after a user-specified
501 * operation is applied.
503 * @guide /hack/collections/examples
505 <<__Rx, __OnlyRxIfArgs, __MutableReturn, __MaybeMutable>>
506 public function map<Tu>(
507 <<__OnlyRxIfRxFunc>>(function(Tv): Tu) $fn,
508 ): namespace\KeyedIterable<Tk, Tu>;
510 * Returns a `KeyedIterable` containing the values after an operation has
511 * been applied to each key and value in the current `KeyedIterable`.
513 * Every key and value in the current `KeyedIterable` is affected by a call to
514 * `mapWithKey()`, unlike `filterWithKey()` where only values that meet a
515 * certain criteria are affected.
517 * @param $fn - The callback containing the operation to apply to the
518 * `KeyedIterable` keys and values.
520 * @return - a `KeyedIterable` containing the values after a user-specified
521 * operation on the current `KeyedIterable`'s keys and values is
524 <<__Rx, __OnlyRxIfArgs, __MutableReturn, __MaybeMutable>>
525 public function mapWithKey<Tu>(
526 <<__OnlyRxIfRxFunc>>(function(Tk, Tv): Tu) $fn,
527 ): namespace\KeyedIterable<Tk, Tu>;
529 * Returns a `KeyedIterable` containing the values of the current
530 * `KeyedIterable` that meet a supplied condition.
532 * Only values that meet a certain criteria are affected by a call to
533 * `filter()`, while all values are affected by a call to `map()`.
535 * @param $fn - The callback containing the condition to apply to the
536 * `KeyedItearble` values.
538 * @return - a `KeyedIterable` containing the values after a user-specified
539 * condition is applied.
541 * @guide /hack/collections/examples
543 <<__Rx, __OnlyRxIfArgs, __MutableReturn, __MaybeMutable>>
544 public function filter(
545 <<__OnlyRxIfRxFunc>>(function(Tv): bool) $fn,
546 ): namespace\KeyedIterable<Tk, Tv>;
548 * Returns a `KeyedIterable` containing the values of the current
549 * `KeyedIterable` that meet a supplied condition applied to its keys and
552 * Only keys and values that meet a certain criteria are affected by a call to
553 * `filterWithKey()`, while all values are affected by a call to
556 * @param $fn - The callback containing the condition to apply to the
557 * `KeyedIterable` keys and values.
559 * @return - a `KeyedIterable` containing the values after a user-specified
560 * condition is applied to the keys and values of the current
564 <<__Rx, __OnlyRxIfArgs, __MutableReturn, __MaybeMutable>>
565 public function filterWithKey(
566 <<__OnlyRxIfRxFunc>>(function(Tk, Tv): bool) $fn,
567 ): namespace\KeyedIterable<Tk, Tv>;
569 * Returns a `KeyedIterable` where each element is a `Pair` that combines the
570 * element of the current `KeyedIterable` and the provided `Traversable`.
572 * If the number of elements of the `KeyedIterable` are not equal to the
573 * number of elements in the `Traversable`, then only the combined elements
574 * up to and including the final element of the one with the least number of
575 * elements is included.
577 * @param $traversable - The `Traversable` to use to combine with the
578 * elements of the current `KeyedIterable`.
580 * @return - The `KeyedIterable` that combines the values of the current
581 * `KeyedItearable` with the provided `Traversable`.
583 <<__Rx, __OnlyRxIfArgs, __MutableReturn, __MaybeMutable>>
584 public function zip<Tu>(
585 <<__OnlyRxIfImpl(namespace\Traversable::class)>> \Traversable<Tu> $traversable,
586 ): namespace\KeyedIterable<Tk, Pair<Tv, Tu>>;
588 * Returns a `KeyedIterable` containing the first `n` values of the current
591 * The returned `KeyedIterable` will always be a proper subset of the current
594 * `$n` is 1-based. So the first element is 1, the second 2, etc.
596 * @param $n - The last element that will be included in the returned
599 * @return - A `KeyedIterable that is a proper subset of the current
600 * `KeyedIterable` up to `n` elements.
602 <<__Rx, __MutableReturn, __MaybeMutable>>
603 public function take(int $n): namespace\KeyedIterable<Tk, Tv>;
605 * Returns a `KeyedIterable` containing the values of the current
606 * `KeyedIterable` up to but not including the first value that produces
607 * `false` when passed to the specified callback.
609 * The returned `KeyedIterable` will always be a proper subset of the current
612 * @param $fn - The callback that is used to determine the stopping
615 * @return - A `KeyedIterable` that is a proper subset of the current
616 * `KeyedIterable` up until the callback returns `false`.
618 <<__Rx, __OnlyRxIfArgs, __MutableReturn, __MaybeMutable>>
619 public function takeWhile(
620 <<__OnlyRxIfRxFunc>>(function(Tv): bool) $fn,
621 ): namespace\KeyedIterable<Tk, Tv>;
623 * Returns a `KeyedIterable` containing the values after the `n`-th element
624 * of the current `KeyedIterable`.
626 * The returned `KeyedIterable` will always be a proper subset of the current
629 * `$n` is 1-based. So the first element is 1, the second 2, etc.
631 * @param $n - The last element to be skipped; the `$n+1` element will be
632 * the first one in the returned `KeyedIterable`.
634 * @return - A `KeyedIterable` that is a proper subset of the current
635 * `KeyedIterable` containing values after the specified `n`-th
638 <<__Rx, __MutableReturn, __MaybeMutable>>
639 public function skip(int $n): namespace\KeyedIterable<Tk, Tv>;
641 * Returns a `KeyedIterable` containing the values of the current
642 * `KeyedIterable` starting after and including the first value that produces
643 * `true` when passed to the specified callback.
645 * The returned `KeyedIterable` will always be a proper subset of the current
648 * @param $fn - The callback used to determine the starting element for the
649 * returned `KeyedIterable`.
651 * @return - A `KeyedIterable` that is a proper subset of the current
652 * `KeyedIterable` starting after the callback returns `true`.
654 <<__Rx, __OnlyRxIfArgs, __MutableReturn, __MaybeMutable>>
655 public function skipWhile(
656 <<__OnlyRxIfRxFunc>>(function(Tv): bool) $fn,
657 ): namespace\KeyedIterable<Tk, Tv>;
659 * Returns a subset of the current `KeyedIterable` starting from a given key
660 * up to, but not including, the element at the provided length from the
663 * `$start` is 0-based. `$len` is 1-based. So `slice(0, 2)` would return the
664 * elements at key 0 and 1.
666 * The returned `KeyedIterable` will always be a proper subset of the current
669 * @param $start - The starting key of the current `KeyedIterable` to begin
670 * the returned `KeyedIterable`.
671 * @param $len - The length of the returned `KeyedIterable`.
673 * @return - A `KeyedIterable` that is a proper subset of the current
674 * `KeyedIterable` starting at `$start` up to but not including the
675 * element `$start + $len`.
677 <<__Rx, __MutableReturn, __MaybeMutable>>
678 public function slice(int $start, int $len): namespace\KeyedIterable<Tk, Tv>;
680 * Returns an `Iterable` that is the concatenation of the values of the
681 * current `KeyedIterable` and the values of the provided `Traversable`.
683 * The values of the provided `Traversable` is concatenated to the end of the
684 * current `KeyedIterable` to produce the returned `Iterable`.
686 * @param $traversable - The `Traversable` to concatenate to the current
689 * @return - The concatenated `Iterable`.
691 * @guide /hack/generics/constraints
693 <<__Rx, __OnlyRxIfArgs, __MutableReturn, __MaybeMutable>>
694 public function concat<Tu super Tv>(
695 <<__OnlyRxIfImpl(namespace\Traversable::class)>> \Traversable<Tu> $traversable,
696 ): namespace\Iterable<Tu>;
698 * Returns the first value in the current `KeyedIterable`.
700 * @return - The first value in the current `KeyedIterable`, or `null` if the
701 * current `KeyedIterable` is empty.
703 <<__Rx, __MaybeMutable>>
704 public function firstValue(): ?Tv;
706 * Returns the first key in the current `KeyedIterable`.
708 * @return - The first key in the current `KeyedIterable`, or `null` if the
709 * current `KeyedIterable` is empty.
711 <<__Rx, __MaybeMutable>>
712 public function firstKey(): ?Tk;
714 * Returns the last value in the current `KeyedIterable`.
716 * @return - The last value in the current `KeyedIterable`, or `null` if the
717 * current `KeyedIterable` is empty.
719 <<__Rx, __MaybeMutable>>
720 public function lastValue(): ?Tv;
722 * Returns the last key in the current `KeyedIterable`.
724 * @return - The last key in the current `KeyedIterable`, or `null` if the
725 * current `KeyedIterable` is empty.
727 <<__Rx, __MaybeMutable>>
728 public function lastKey(): ?Tk;
731 interface Countable extends \Countable {
732 <<__Rx, __MaybeMutable>>
733 public function count(): int;