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 \HH\Traversable */
21 namespace\KeyedTraversable::class,
22 namespace\Iterator::class,
23 namespace\IteratorAggregate::class,
26 interface Traversable<+Tv> extends \HH\Traversable<Tv> {}
28 /* See documentation for \HH\KeyedTraversable */
30 namespace\KeyedIterable::class,
31 namespace\KeyedIterator::class,
32 \HH\KeyedContainer::class
34 interface KeyedTraversable<+Tk, +Tv>
35 extends namespace\Traversable<Tv>, \HH\KeyedTraversable<Tk, Tv> {}
37 /* See documentation for \HH\Iterator */
38 interface Iterator<+Tv> extends namespace\Traversable<Tv>, \HH\Iterator<Tv> {
40 * Return the current value at the current iterator position.
42 * @return - The current value of type `Tv`.
44 <<__Pure, __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 <<__Pure, __MaybeMutable>>
68 public function valid(): bool;
71 interface KeyedIterator<+Tk, +Tv>
73 namespace\KeyedTraversable<Tk, Tv>,
74 namespace\Iterator<Tv>,
75 \HH\KeyedIterator<Tk, Tv> {
77 * Return the current key at the current iterator position.
79 * @return - The current key of type `Tk`.
81 <<__Pure, __MaybeMutable>>
82 public function key(): Tk;
85 /* See documentation for \AsyncIterator */
86 interface AsyncIterator<+Tv> extends \HH\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>, \HH\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.
116 <<__Pure, __Mutable>>
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 <<__Pure, __MutableReturn, __MaybeMutable>>
129 public function getIterator(): namespace\Iterator<Tv>;
132 interface Iterable<+Tv>
133 extends namespace\IteratorAggregate<Tv>, \HH\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 <<__Pure, __MutableReturn, __MaybeMutable>>
140 public function getIterator(): namespace\Iterator<Tv>;
142 * Returns an `array` with the values from the current `Iterable`.
144 * The keys in the current `Iterable` are discarded and replaced with integer
145 * indices, starting with 0.
147 * @return - an `array` containing the values from the current `Iterable`.
149 <<__Pure, __MaybeMutable>>
150 public function toValuesArray(): varray<Tv>;
152 * Returns an immutable vector (`ImmVector`) converted from the current
155 * Any keys in the current `Iterable` are discarded and replaced with integer
156 * indices, starting with 0.
158 * @return - an `ImmVector` converted from the current `Iterable`.
160 <<__Pure, __MaybeMutable>>
161 public function toImmVector(): ImmVector<Tv>;
163 * Returns an immutable set (`ImmSet`) converted from the current `Iterable`.
165 * Any keys in the current `Iterable` are discarded.
167 * @return - an `ImmSet` converted from the current `Iterable`.
169 <<__Pure, __MaybeMutable>>
170 public function toImmSet(): ImmSet<Tv> where Tv as arraykey;
172 * Returns a lazy, access elements only when needed view of the current
175 * Normally, memory is allocated for all of the elements of the `Iterable`.
176 * With a lazy view, memory is allocated for an element only when needed or
177 * used in a calculation like in `map()` or `filter()`.
179 * @return - an `Iterable` representing the lazy view into the current
182 * @guide /hack/collections/examples
184 <<__Pure, __MutableReturn, __MaybeMutable>>
185 public function lazy(): namespace\Iterable<Tv>;
187 * Returns an `Iterable` containing the current `Iterable`'s values.
189 * Any keys are discarded.
191 * @return An `Iterable` with the values of the current `Iterable`.
193 <<__Pure, __MutableReturn, __MaybeMutable>>
194 public function values(): namespace\Iterable<Tv>;
196 * Returns an `Iterable` containing the values after an operation has been
197 * applied to each value in the current `Iterable`.
199 * Every value in the current `Iterable` is affected by a call to `map()`,
200 * unlike `filter()` where only values that meet a certain criteria are
203 * @param $fn - The callback containing the operation to apply to the
206 * @return - an `Iterable` containing the values after a user-specified
207 * operation is applied.
209 * @guide /hack/collections/examples
211 <<__Pure, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
212 public function map<Tu>(
213 <<__AtMostRxAsFunc>>(function(Tv): Tu) $fn,
214 ): namespace\Iterable<Tu>;
216 * Returns an `Iterable` containing the values of the current `Iterable` that
217 * meet a supplied condition.
219 * Only values that meet a certain criteria are affected by a call to
220 * `filter()`, while all values are affected by a call to `map()`.
222 * @param $fn - The callback containing the condition to apply to the
225 * @return - an `Iterable` containing the values after a user-specified
226 * condition is applied.
228 * @guide /hack/collections/examples
230 <<__Pure, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
231 public function filter(
232 <<__AtMostRxAsFunc>>(function(Tv): bool) $fn,
233 ): namespace\Iterable<Tv>;
235 * Returns an `Iterable` where each element is a `Pair` that combines the
236 * element of the current `Iterable` and the provided `Traversable`.
238 * If the number of elements of the `Iterable` are not equal to the number of
239 * elements in the `Traversable`, then only the combined elements up to and
240 * including the final element of the one with the least number of elements
243 * @param $traversable - The `Traversable` to use to combine with the
244 * elements of the current `Iterable`.
246 * @return - The `Iterable` that combines the values of the current
247 * `Itearable` with the provided `Traversable`.
249 <<__Pure, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
250 public function zip<Tu>(
251 <<__OnlyRxIfImpl(namespace\Traversable::class)>> \HH\Traversable<Tu> $traversable,
252 ): namespace\Iterable<Pair<Tv, Tu>>;
254 * Returns an `Iterable` containing the first `n` values of the current
257 * The returned `Iterable` will always be a proper subset of the current
260 * `$n` is 1-based. So the first element is 1, the second 2, etc.
262 * @param $n - The last element that will be included in the returned
265 * @return - An `Iterable that is a proper subset of the current `Iterable`
266 * up to `n` elements.
268 <<__Pure, __MutableReturn, __MaybeMutable>>
269 public function take(int $n): namespace\Iterable<Tv>;
271 * Returns an `Iterable` containing the values of the current `Iterable` up
272 * to but not including the first value that produces `false` when passed to
273 * the specified callback.
275 * The returned `Iterable` will always be a proper subset of the current
278 * @param $fn - The callback that is used to determine the stopping
281 * @return - An `Iterable` that is a proper subset of the current `Iterable`
282 * up until the callback returns `false`.
284 <<__Pure, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
285 public function takeWhile(
286 <<__AtMostRxAsFunc>>(function(Tv): bool) $fn,
287 ): namespace\Iterable<Tv>;
289 * Returns an `Iterable` containing the values after the `n`-th element of the
290 * current `Iterable`.
292 * The returned `Iterable` will always be a proper subset of the current
295 * `$n` is 1-based. So the first element is 1, the second 2, etc.
297 * @param $n - The last element to be skipped; the `$n+1` element will be
298 * the first one in the returned `Iterable`.
300 * @return - An `Iterable` that is a proper subset of the current `Iterable`
301 * containing values after the specified `n`-th element.
303 <<__Pure, __MutableReturn, __MaybeMutable>>
304 public function skip(int $n): namespace\Iterable<Tv>;
306 * Returns an `Iterable` containing the values of the current `Iterable`
307 * starting after and including the first value that produces `true` when
308 * passed to the specified callback.
310 * The returned `Iterable` will always be a proper subset of the current
313 * @param $fn - The callback used to determine the starting element for the
314 * returned `Iterable`.
316 * @return - An `Iterable` that is a proper subset of the current `Iterable`
317 * starting after the callback returns `true`.
319 <<__Pure, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
320 public function skipWhile(
321 <<__AtMostRxAsFunc>>(function(Tv): bool) $fn,
322 ): namespace\Iterable<Tv>;
324 * Returns a subset of the current `Iterable` starting from a given key up
325 * to, but not including, the element at the provided length from the
328 * `$start` is 0-based. `$len` is 1-based. So `slice(0, 2)` would return the
329 * elements at key 0 and 1.
331 * The returned `Iterable` will always be a proper subset of the current
334 * @param $start - The starting key of the current `Iterable` to begin the
335 * returned `Iterable`.
336 * @param $len - The length of the returned `Iterable`.
338 * @return - An `Iterable` that is a proper subset of the current `Iterable`
339 * starting at `$start` up to but not including the element
342 <<__Pure, __MutableReturn, __MaybeMutable>>
343 public function slice(int $start, int $len): namespace\Iterable<Tv>;
345 * Returns an `Iterable` that is the concatenation of the values of the
346 * current `Iterable` and the values of the provided `Traversable`.
348 * The values of the provided `Traversable` is concatenated to the end of the
349 * current `Iterable` to produce the returned `Iterable`.
351 * @param $traversable - The `Traversable` to concatenate to the current
354 * @return - The concatenated `Iterable`.
356 * @guide /hack/generics/constraints
358 <<__Pure, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
359 public function concat<Tu super Tv>(
360 <<__OnlyRxIfImpl(namespace\Traversable::class)>> \HH\Traversable<Tu> $traversable,
361 ): namespace\Iterable<Tu>;
363 * Returns the first value in the current `Iterable`.
365 * @return - The first value in the current `Iterable`, or `null` if the
366 * current `Iterable` is empty.
368 <<__Pure, __MaybeMutable>>
369 public function firstValue(): ?Tv;
371 * Returns the last value in the current `Iterable`.
373 * @return - The last value in the current `Iterable`, or `null` if the
374 * current `Iterable` is empty.
376 <<__Pure, __MaybeMutable>>
377 public function lastValue(): ?Tv;
380 interface KeyedIterable<Tk, +Tv>
382 namespace\KeyedTraversable<Tk, Tv>,
383 namespace\Iterable<Tv>,
384 \HH\KeyedIterable<Tk, Tv> {
386 * Returns an iterator that points to beginning of the current
389 * @return - A `KeyedIterator` that allows you to traverse the current
392 <<__Pure, __MutableReturn, __MaybeMutable>>
393 public function getIterator(): namespace\KeyedIterator<Tk, Tv>;
395 * Returns an `array` with the keys from the current `KeyedIterable`.
397 * @return - an `array` containing the values from the current
400 <<__Pure, __MaybeMutable>>
401 public function toKeysArray(): varray;
403 * Returns an immutable map (`ImmMap`) based on the keys and values of the
404 * current `KeyedIterable`.
406 * @return - an `ImmMap` that has the keys and associated values of the
407 * current `KeyedIterable`.
409 <<__Pure, __MaybeMutable>>
410 public function toImmMap(): ImmMap<Tk, Tv> where Tk as arraykey;
412 * Returns a lazy, access elements only when needed view of the current
415 * Normally, memory is allocated for all of the elements of the
416 * `KeyedIterable`. With a lazy view, memory is allocated for an element only
417 * when needed or used in a calculation like in `map()` or `filter()`.
419 * @return - a `KeyedIterable` representing the lazy view into the current
422 * @guide /hack/collections/examples
424 <<__Pure, __MutableReturn, __MaybeMutable>>
425 public function lazy(): namespace\KeyedIterable<Tk, Tv>;
427 * Returns an `Iterable` containing the current `KeyedIterable`'s values.
429 * Any keys are discarded.
431 * @return An `Iterable` with the values of the current `KeyedIterable`.
433 <<__Pure, __MutableReturn, __MaybeMutable>>
434 public function values(): namespace\Iterable<Tv>;
436 * Returns an `Iterable` containing the current `KeyedIterable`'s keys.
438 * Any values are discarded.
440 * @return An `Iterable` with the keys of the current `KeyedIterable`.
442 <<__Pure, __MutableReturn, __MaybeMutable>>
443 public function keys(): namespace\Iterable<Tk>;
445 * Returns a `KeyedIterable` containing the values after an operation has been
446 * applied to each value in the current `KeyedIterable`.
448 * Every value in the current `KeyedIterable` is affected by a call to
449 * `map()`, unlike `filter()` where only values that meet a certain criteria
452 * @param $fn - The callback containing the operation to apply to the
453 * `KeyedIterable` values.
455 * @return - a `KeyedIterable` containing the values after a user-specified
456 * operation is applied.
458 * @guide /hack/collections/examples
460 <<__Pure, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
461 public function map<Tu>(
462 <<__AtMostRxAsFunc>>(function(Tv): Tu) $fn,
463 ): namespace\KeyedIterable<Tk, Tu>;
465 * Returns a `KeyedIterable` containing the values after an operation has
466 * been applied to each key and value in the current `KeyedIterable`.
468 * Every key and value in the current `KeyedIterable` is affected by a call to
469 * `mapWithKey()`, unlike `filterWithKey()` where only values that meet a
470 * certain criteria are affected.
472 * @param $fn - The callback containing the operation to apply to the
473 * `KeyedIterable` keys and values.
475 * @return - a `KeyedIterable` containing the values after a user-specified
476 * operation on the current `KeyedIterable`'s keys and values is
479 <<__Pure, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
480 public function mapWithKey<Tu>(
481 <<__AtMostRxAsFunc>>(function(Tk, Tv): Tu) $fn,
482 ): namespace\KeyedIterable<Tk, Tu>;
484 * Returns a `KeyedIterable` containing the values of the current
485 * `KeyedIterable` that meet a supplied condition.
487 * Only values that meet a certain criteria are affected by a call to
488 * `filter()`, while all values are affected by a call to `map()`.
490 * @param $fn - The callback containing the condition to apply to the
491 * `KeyedItearble` values.
493 * @return - a `KeyedIterable` containing the values after a user-specified
494 * condition is applied.
496 * @guide /hack/collections/examples
498 <<__Pure, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
499 public function filter(
500 <<__AtMostRxAsFunc>>(function(Tv): bool) $fn,
501 ): namespace\KeyedIterable<Tk, Tv>;
503 * Returns a `KeyedIterable` containing the values of the current
504 * `KeyedIterable` that meet a supplied condition applied to its keys and
507 * Only keys and values that meet a certain criteria are affected by a call to
508 * `filterWithKey()`, while all values are affected by a call to
511 * @param $fn - The callback containing the condition to apply to the
512 * `KeyedIterable` keys and values.
514 * @return - a `KeyedIterable` containing the values after a user-specified
515 * condition is applied to the keys and values of the current
519 <<__Pure, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
520 public function filterWithKey(
521 <<__AtMostRxAsFunc>>(function(Tk, Tv): bool) $fn,
522 ): namespace\KeyedIterable<Tk, Tv>;
524 * Returns a `KeyedIterable` where each element is a `Pair` that combines the
525 * element of the current `KeyedIterable` and the provided `Traversable`.
527 * If the number of elements of the `KeyedIterable` are not equal to the
528 * number of elements in the `Traversable`, then only the combined elements
529 * up to and including the final element of the one with the least number of
530 * elements is included.
532 * @param $traversable - The `Traversable` to use to combine with the
533 * elements of the current `KeyedIterable`.
535 * @return - The `KeyedIterable` that combines the values of the current
536 * `KeyedItearable` with the provided `Traversable`.
538 <<__Pure, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
539 public function zip<Tu>(
540 <<__OnlyRxIfImpl(namespace\Traversable::class)>> \HH\Traversable<Tu> $traversable,
541 ): namespace\KeyedIterable<Tk, Pair<Tv, Tu>>;
543 * Returns a `KeyedIterable` containing the first `n` values of the current
546 * The returned `KeyedIterable` will always be a proper subset of the current
549 * `$n` is 1-based. So the first element is 1, the second 2, etc.
551 * @param $n - The last element that will be included in the returned
554 * @return - A `KeyedIterable that is a proper subset of the current
555 * `KeyedIterable` up to `n` elements.
557 <<__Pure, __MutableReturn, __MaybeMutable>>
558 public function take(int $n): namespace\KeyedIterable<Tk, Tv>;
560 * Returns a `KeyedIterable` containing the values of the current
561 * `KeyedIterable` up to but not including the first value that produces
562 * `false` when passed to the specified callback.
564 * The returned `KeyedIterable` will always be a proper subset of the current
567 * @param $fn - The callback that is used to determine the stopping
570 * @return - A `KeyedIterable` that is a proper subset of the current
571 * `KeyedIterable` up until the callback returns `false`.
573 <<__Pure, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
574 public function takeWhile(
575 <<__AtMostRxAsFunc>>(function(Tv): bool) $fn,
576 ): namespace\KeyedIterable<Tk, Tv>;
578 * Returns a `KeyedIterable` containing the values after the `n`-th element
579 * of the current `KeyedIterable`.
581 * The returned `KeyedIterable` will always be a proper subset of the current
584 * `$n` is 1-based. So the first element is 1, the second 2, etc.
586 * @param $n - The last element to be skipped; the `$n+1` element will be
587 * the first one in the returned `KeyedIterable`.
589 * @return - A `KeyedIterable` that is a proper subset of the current
590 * `KeyedIterable` containing values after the specified `n`-th
593 <<__Pure, __MutableReturn, __MaybeMutable>>
594 public function skip(int $n): namespace\KeyedIterable<Tk, Tv>;
596 * Returns a `KeyedIterable` containing the values of the current
597 * `KeyedIterable` starting after and including the first value that produces
598 * `true` when passed to the specified callback.
600 * The returned `KeyedIterable` will always be a proper subset of the current
603 * @param $fn - The callback used to determine the starting element for the
604 * returned `KeyedIterable`.
606 * @return - A `KeyedIterable` that is a proper subset of the current
607 * `KeyedIterable` starting after the callback returns `true`.
609 <<__Pure, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
610 public function skipWhile(
611 <<__AtMostRxAsFunc>>(function(Tv): bool) $fn,
612 ): namespace\KeyedIterable<Tk, Tv>;
614 * Returns a subset of the current `KeyedIterable` starting from a given key
615 * up to, but not including, the element at the provided length from the
618 * `$start` is 0-based. `$len` is 1-based. So `slice(0, 2)` would return the
619 * elements at key 0 and 1.
621 * The returned `KeyedIterable` will always be a proper subset of the current
624 * @param $start - The starting key of the current `KeyedIterable` to begin
625 * the returned `KeyedIterable`.
626 * @param $len - The length of the returned `KeyedIterable`.
628 * @return - A `KeyedIterable` that is a proper subset of the current
629 * `KeyedIterable` starting at `$start` up to but not including the
630 * element `$start + $len`.
632 <<__Pure, __MutableReturn, __MaybeMutable>>
633 public function slice(int $start, int $len): namespace\KeyedIterable<Tk, Tv>;
635 * Returns an `Iterable` that is the concatenation of the values of the
636 * current `KeyedIterable` and the values of the provided `Traversable`.
638 * The values of the provided `Traversable` is concatenated to the end of the
639 * current `KeyedIterable` to produce the returned `Iterable`.
641 * @param $traversable - The `Traversable` to concatenate to the current
644 * @return - The concatenated `Iterable`.
646 * @guide /hack/generics/constraints
648 <<__Pure, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
649 public function concat<Tu super Tv>(
650 <<__OnlyRxIfImpl(namespace\Traversable::class)>> \HH\Traversable<Tu> $traversable,
651 ): namespace\Iterable<Tu>;
653 * Returns the first value in the current `KeyedIterable`.
655 * @return - The first value in the current `KeyedIterable`, or `null` if the
656 * current `KeyedIterable` is empty.
658 <<__Pure, __MaybeMutable>>
659 public function firstValue(): ?Tv;
661 * Returns the first key in the current `KeyedIterable`.
663 * @return - The first key in the current `KeyedIterable`, or `null` if the
664 * current `KeyedIterable` is empty.
666 <<__Pure, __MaybeMutable>>
667 public function firstKey(): ?Tk;
669 * Returns the last value in the current `KeyedIterable`.
671 * @return - The last value in the current `KeyedIterable`, or `null` if the
672 * current `KeyedIterable` is empty.
674 <<__Pure, __MaybeMutable>>
675 public function lastValue(): ?Tv;
677 * Returns the last key in the current `KeyedIterable`.
679 * @return - The last key in the current `KeyedIterable`, or `null` if the
680 * current `KeyedIterable` is empty.
682 <<__Pure, __MaybeMutable>>
683 public function lastKey(): ?Tk;
686 interface Countable extends \Countable {
687 <<__Pure, __MaybeMutable>>
688 public function count(): int;