PageRenderTime 89ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 1ms

/hphp/runtime/ext/collections/ext_collections-vector.php

http://github.com/facebook/hiphop-php
PHP | 911 lines | 397 code | 112 blank | 402 comment | 18 complexity | 62bad7a49f1897aea3a2e28141ccf1c8 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh // partial
  2. namespace {
  3. /** An iterator implementation for iterating over a Vector/ImmVector.
  4. */
  5. <<__NativeData("VectorIterator")>>
  6. final class VectorIterator implements HH\Rx\KeyedIterator {
  7. /** Do nothing */
  8. <<__Rx>>
  9. public function __construct(): void { }
  10. /** Returns the current value that the iterator points to.
  11. * @return mixed
  12. */
  13. <<__Native, __Rx, __MaybeMutable>>
  14. public function current(): mixed;
  15. /** Returns the current key that the iterator points to.
  16. * @return mixed
  17. */
  18. <<__Native, __Rx, __MaybeMutable>>
  19. public function key(): mixed;
  20. /** Returns true if the iterator points to a valid value, returns false
  21. * otherwise.
  22. * @return bool
  23. */
  24. <<__Native, __Rx, __MaybeMutable>>
  25. public function valid(): bool;
  26. /** Advance this iterator forward one position.
  27. */
  28. <<__Native, __Rx, __Mutable>>
  29. public function next(): void;
  30. /** Move this iterator back to the first position.
  31. */
  32. <<__Native, __Rx, __Mutable>>
  33. public function rewind(): void;
  34. }
  35. } // empty namespace
  36. namespace HH {
  37. /** An ordered collection where values are keyed using integers 0 thru n-1 in
  38. * order.
  39. */
  40. final class Vector implements \MutableVector {
  41. /** Returns a Vector built from the values produced by the specified Iterable.
  42. * @param mixed $iterable
  43. */
  44. <<__Native, __Rx, __AtMostRxAsArgs>>
  45. public function __construct(<<__MaybeMutable, __OnlyRxIfImpl(Rx\Traversable::class)>> mixed $iterable = null): void;
  46. /** Returns true if the Vector is empty, false otherwise.
  47. * @return bool
  48. */
  49. <<__Rx, __MaybeMutable>>
  50. public function isEmpty(): bool {
  51. return !$this->count();
  52. }
  53. /** Returns the number of values in the Vector.
  54. * @return int
  55. */
  56. <<__Native, __Rx, __MaybeMutable>>
  57. public function count(): int;
  58. /** Returns an Iterable that produces the values from this Vector.
  59. * @return object
  60. */
  61. <<__Rx, __MutableReturn, __MaybeMutable>>
  62. public function items(): \LazyIterableView {
  63. return new \LazyIterableView($this);
  64. }
  65. /** Returns a Vector built from the keys of this Vector.
  66. * @return object
  67. */
  68. <<__Native, __Rx, __MutableReturn, __MaybeMutable>>
  69. public function keys(): object;
  70. /** Returns a copy of this Vector.
  71. * @return object
  72. */
  73. <<__Rx, __MutableReturn, __MaybeMutable>>
  74. public function values(): this {
  75. return new self($this);
  76. }
  77. /** Returns a lazy iterable view of this Vector.
  78. * @return object
  79. */
  80. <<__Rx, __MutableReturn, __MaybeMutable>>
  81. public function lazy(): \LazyKeyedIterableView {
  82. return new \LazyKeyedIterableView($this);
  83. }
  84. /** Returns the value at the specified key. If the key is not present, an
  85. * exception is thrown.
  86. * @param mixed $key
  87. * @return mixed
  88. */
  89. <<__Native, __Rx, __MaybeMutable>>
  90. public function at(mixed $key): mixed;
  91. /** Returns the value at the specified key. If the key is not present, null is
  92. * returned.
  93. * @param mixed $key
  94. * @return mixed
  95. */
  96. <<__Native, __Rx, __MaybeMutable>>
  97. public function get(mixed $key): mixed;
  98. /** Stores a value into the Vector with the specified key, overwriting any
  99. * previous value that was associated with the key; if the key is outside the
  100. * bounds of the Vector, an exception is thrown.
  101. * @param mixed $key
  102. * @param mixed $value
  103. * @return object
  104. */
  105. <<__Native, __Rx, __Mutable, __ReturnsVoidToRx>>
  106. public function set(mixed $key,
  107. mixed $value): object;
  108. /** Stores each value produced by the specified KeyedIterable into the Vector
  109. * using its corresponding key, overwriting any previous value that was
  110. * associated with that key; if the key is outside the bounds of the Vector,
  111. * an exception is thrown.
  112. * @param mixed $iterable
  113. * @return object
  114. */
  115. <<__Native, __Rx, __Mutable, __AtMostRxAsArgs, __ReturnsVoidToRx>>
  116. public function setAll(<<__MaybeMutable, __OnlyRxIfImpl(Rx\KeyedTraversable::class)>> mixed $iterable): object;
  117. /** Removes all values from the Vector.
  118. * @return object
  119. */
  120. <<__Native, __Rx, __Mutable, __ReturnsVoidToRx>>
  121. public function clear(): object;
  122. /** Returns true if the specified key is present in the Vector, returns false
  123. * otherwise.
  124. * @param mixed $key
  125. * @return bool
  126. */
  127. <<__Deprecated(
  128. "Use Vector::containsKey() for key search or Vector::linearSearch() for value search"
  129. )>>
  130. public function contains(mixed $key): bool {
  131. if (!\is_int($key)) {
  132. throw new \InvalidArgumentException(
  133. "Only integer keys may be used with Vectors"
  134. );
  135. }
  136. return ($key >= 0) && ($key < $this->count());
  137. }
  138. /** Returns true if the specified key is present in the Vector, returns false
  139. * otherwise.
  140. * @param mixed $key
  141. * @return bool
  142. */
  143. <<__Rx, __MaybeMutable>>
  144. public function containsKey(mixed $key): bool {
  145. if (!\is_int($key)) {
  146. throw new \InvalidArgumentException(
  147. "Only integer keys may be used with Vectors"
  148. );
  149. }
  150. return ($key >= 0) && ($key < $this->count());
  151. }
  152. /** Removes the element with the specified key from this Vector and renumbers
  153. * the keys of all subsequent elements.
  154. * @param mixed $key
  155. * @return object
  156. */
  157. <<__Native, __Rx, __Mutable, __ReturnsVoidToRx>>
  158. public function removeKey(mixed $key): object;
  159. /** @param mixed $val
  160. * @return object
  161. */
  162. <<__Native>>
  163. public function append(mixed $val): object;
  164. /** Adds the specified value to the end of this Vector using the next available
  165. * integer key.
  166. * @param mixed $val
  167. * @return object
  168. */
  169. <<__Native, __Rx, __Mutable, __ReturnsVoidToRx>>
  170. public function add(mixed $val): object;
  171. /** Adds the values produced by the specified Iterable to the end of this
  172. * Vector using the next available integer keys.
  173. * @param mixed $iterable
  174. * @return object
  175. */
  176. <<__Native, __Rx, __Mutable, __AtMostRxAsArgs, __ReturnsVoidToRx>>
  177. public function addAll(<<__MaybeMutable, __OnlyRxIfImpl(Rx\Traversable::class)>> mixed $iterable): object;
  178. /** Adds the keys of the specified KeyedContainer to the end of this Vector
  179. * using the next available integer keys.
  180. * @param mixed $container
  181. * @return object
  182. */
  183. <<__Native, __Rx, __Mutable, __ReturnsVoidToRx>>
  184. public function addAllKeysOf(mixed $container): object;
  185. /** @return mixed
  186. */
  187. <<__Native, __Rx, __Mutable>>
  188. public function pop(): mixed;
  189. /** @param mixed $sz
  190. * @param mixed $value
  191. */
  192. <<__Native, __Rx, __Mutable>>
  193. public function resize(mixed $sz,
  194. mixed $value): void;
  195. /** Instructs this Vector to grow its capacity to accommodate the given number
  196. * of elements. The caller is expected to make the appropriate add/addAll
  197. * calls to fill that reserved capacity.
  198. * @param mixed $sz
  199. */
  200. <<__Native, __Rx, __Mutable>>
  201. public function reserve(mixed $sz): void;
  202. /** Returns an array built from the values from this Vector.
  203. * @return array
  204. */
  205. <<__Native, __Rx, __MaybeMutable>>
  206. public function toArray(): array;
  207. <<__Native, __Rx, __MaybeMutable>>
  208. public function toVArray(): varray;
  209. <<__Native, __Rx, __MaybeMutable>>
  210. public function toDArray(): darray;
  211. /** Returns a copy of this Vector.
  212. * @return object
  213. */
  214. <<__Rx, __MutableReturn, __MaybeMutable>>
  215. public function toVector(): this {
  216. return new self($this);
  217. }
  218. /** Returns a ImmVector built from the values of this Vector.
  219. * @return object
  220. */
  221. <<__Native, __Rx, __MaybeMutable>>
  222. public function toImmVector(): object;
  223. /** Returns an immutable version of this collection.
  224. * @return object
  225. */
  226. <<__Rx, __MaybeMutable>>
  227. public function immutable(): \HH\ImmVector {
  228. return $this->toImmVector();
  229. }
  230. /** Returns a Map built from the keys and values of this Vector.
  231. * @return object
  232. */
  233. <<__Native, __Rx, __MutableReturn, __MaybeMutable>>
  234. public function toMap(): object;
  235. /** Returns a ImmMap built from the keys and values of this Vector.
  236. * @return object
  237. */
  238. <<__Native, __Rx, __MaybeMutable>>
  239. public function toImmMap(): object;
  240. /** Returns a Set built from the values of this Vector.
  241. * @return object
  242. */
  243. <<__Native, __Rx, __MutableReturn, __MaybeMutable>>
  244. public function toSet(): object;
  245. /** Returns a ImmSet built from the values of this Vector.
  246. * @return object
  247. */
  248. <<__Native, __Rx, __MaybeMutable>>
  249. public function toImmSet(): object;
  250. /** Returns an array built from the keys from this Vector.
  251. * @return array
  252. */
  253. <<__Rx, __MaybeMutable, __ProvenanceSkipFrame>>
  254. public function toKeysArray(): varray {
  255. $count = $this->count();
  256. return $count ? varray(\range(0, $count - 1)) : varray[];
  257. }
  258. /** Returns an array built from the values from this Vector.
  259. * @return array
  260. */
  261. <<__Rx, __MaybeMutable, __ProvenanceSkipFrame>>
  262. public function toValuesArray(): varray {
  263. return $this->toVArray();
  264. }
  265. /** Returns an iterator that points to beginning of this Vector.
  266. * @return object
  267. */
  268. <<__Native, __Rx, __MutableReturn, __MaybeMutable>>
  269. public function getIterator(): object;
  270. /** Returns a Vector of the values produced by applying the specified callback
  271. * on each value from this Vector.
  272. * @param mixed $callback
  273. * @return object
  274. */
  275. <<__Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  276. public function map(<<__AtMostRxAsFunc>> mixed $callback): \HH\Vector {
  277. $ret = vec[];
  278. foreach ($this as $v) {
  279. $ret[] = $callback($v);
  280. }
  281. return new \HH\Vector($ret);
  282. }
  283. /** Returns a Vector of the values produced by applying the specified callback
  284. * on each key and value from this Vector.
  285. * @param mixed $callback
  286. * @return object
  287. */
  288. <<__Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  289. public function mapWithKey(<<__AtMostRxAsFunc>> mixed $callback): \HH\Vector {
  290. $ret = vec[];
  291. foreach ($this as $k => $v) {
  292. $ret[] = $callback($k, $v);
  293. }
  294. return new \HH\Vector($ret);
  295. }
  296. /** Returns a Vector of all the values from this Vector for which the specified
  297. * callback returns true.
  298. * @param mixed $callback
  299. * @return object
  300. */
  301. <<__Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  302. public function filter(<<__AtMostRxAsFunc>> mixed $callback): \HH\Vector {
  303. $ret = vec[];
  304. foreach ($this as $v) {
  305. if ($callback($v)) {
  306. $ret[] = $v;
  307. }
  308. }
  309. return new \HH\Vector($ret);
  310. }
  311. /** Returns a Vector of all the values from this Vector for which the specified
  312. * callback returns true.
  313. * @param mixed $callback
  314. * @return object
  315. */
  316. <<__Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  317. public function filterWithKey(<<__AtMostRxAsFunc>> mixed $callback): \HH\Vector {
  318. $ret = vec[];
  319. foreach ($this as $k => $v) {
  320. if ($callback($k, $v)) {
  321. $ret[] = $v;
  322. }
  323. }
  324. return new \HH\Vector($ret);
  325. }
  326. /** Returns a KeyedIterable produced by combined the specified Iterables
  327. * pair-wise.
  328. * @param mixed $iterable
  329. * @return object
  330. */
  331. <<__Native, __Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  332. public function zip(<<__MaybeMutable, __OnlyRxIfImpl(Rx\Traversable::class)>> mixed $iterable): object;
  333. /** Returns a Vector containing the first n values of this Vector.
  334. * @param mixed $n
  335. * @return object
  336. */
  337. <<__Native, __Rx, __MutableReturn, __MaybeMutable>>
  338. public function take(mixed $n): object;
  339. /** Returns a Vector containing the values of this Vector up to but not
  340. * including the first value that produces false when passed to the specified
  341. * callback.
  342. * @param mixed $callback
  343. * @return object
  344. */
  345. <<__Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  346. public function takeWhile(<<__AtMostRxAsFunc>> mixed $callback): \HH\Vector {
  347. $ret = vec[];
  348. foreach ($this as $v) {
  349. if (!$callback($v)) {
  350. break;
  351. }
  352. $ret[] = $v;
  353. }
  354. return new \HH\Vector($ret);
  355. }
  356. /** Returns a Vector containing all the values except the first n of this
  357. * Vector.
  358. * @param mixed $n
  359. * @return object
  360. */
  361. <<__Native, __Rx, __MutableReturn, __MaybeMutable>>
  362. public function skip(mixed $n): object;
  363. /** Returns a Vector containing the values of this Vector excluding the first
  364. * values that produces true when passed to the specified callback.
  365. * @param mixed $fn
  366. * @return object
  367. */
  368. <<__Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  369. public function skipWhile(<<__AtMostRxAsFunc>> mixed $fn): \HH\Vector {
  370. $ret = vec[];
  371. $skipping = true;
  372. foreach ($this as $v) {
  373. if ($skipping) {
  374. if ($fn($v)) {
  375. continue;
  376. }
  377. $skipping = false;
  378. }
  379. $ret[] = $v;
  380. }
  381. return new \HH\Vector($ret);
  382. }
  383. /** Returns a Vector containing the specified range of values from this Vector.
  384. * The range is specified by two non-negative integers: a starting position
  385. * and a length.
  386. * @param mixed $start
  387. * @param mixed $len
  388. * @return object
  389. */
  390. <<__Native, __Rx, __MutableReturn, __MaybeMutable>>
  391. public function slice(mixed $start,
  392. mixed $len): object;
  393. /** Builds a new Vector by concatenating the elements of this Vector with the
  394. * elements of the specified Iterable.
  395. * @param mixed $iterable
  396. * @return object
  397. */
  398. <<__Native, __Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  399. public function concat(<<__MaybeMutable, __OnlyRxIfImpl(Rx\Traversable::class)>> mixed $iterable): object;
  400. /** Returns the first value from this Vector, or null if this Vector is empty.
  401. * @return mixed
  402. */
  403. <<__Native, __Rx, __MaybeMutable>>
  404. public function firstValue(): mixed;
  405. /** Returns the first key from this Vector, or null if this Vector is empty.
  406. * @return mixed
  407. */
  408. <<__Rx, __MaybeMutable>>
  409. public function firstKey(): mixed {
  410. return $this->count() ? 0 : null;
  411. }
  412. /** Returns the last value from this Vector, or null if this Vector is empty.
  413. * @return mixed
  414. */
  415. <<__Native, __Rx, __MaybeMutable>>
  416. public function lastValue(): mixed;
  417. /** Returns the last key from this Vector, or null if this Vector is empty.
  418. * @return mixed
  419. */
  420. <<__Rx, __MaybeMutable>>
  421. public function lastKey(): mixed {
  422. $count = $this->count();
  423. return $count ? ($count - 1) : null;
  424. }
  425. /** Reverses the values of the Vector in place.
  426. */
  427. <<__Native, __Rx, __Mutable>>
  428. public function reverse(): void;
  429. /** Splices the values of the Vector in place (see the documentation for
  430. * array_splice() on php.net for more details.
  431. * @param mixed $offset
  432. * @param mixed $len
  433. * @param mixed $replacement
  434. */
  435. <<__Native, __Rx, __Mutable>>
  436. public function splice(mixed $offset,
  437. mixed $len = null,
  438. mixed $replacement = null): void;
  439. /** Returns index of the specified value if it is present, -1 otherwise.
  440. * @param mixed $search_value
  441. * @return int
  442. */
  443. <<__Native, __Rx, __MaybeMutable>>
  444. public function linearSearch(mixed $search_value): int;
  445. /** Shuffles the values of the Vector randomly in place.
  446. */
  447. <<__Native, __Rx, __Mutable>>
  448. public function shuffle(): void;
  449. /** @return string
  450. */
  451. <<__Rx, __MaybeMutable>>
  452. public function __toString(): string { return "Vector"; }
  453. /** Returns a Vector built from the values produced by the specified Iterable.
  454. * @param mixed $iterable
  455. * @return object
  456. */
  457. <<__Native, __Rx, __AtMostRxAsArgs, __MutableReturn>>
  458. public static function fromItems(<<__MaybeMutable, __OnlyRxIfImpl(Rx\Traversable::class)>> mixed $iterable): object;
  459. /** Returns a Vector built from the keys of the specified container.
  460. * @param mixed $container
  461. * @return object
  462. */
  463. <<__Native, __Rx, __MutableReturn>>
  464. public static function fromKeysOf(mixed $container): object;
  465. /** Returns a Vector built from the values from the specified array.
  466. * @param mixed $arr
  467. * @return object
  468. */
  469. <<__Native>>
  470. public static function fromArray(mixed $arr): object;
  471. }
  472. /** An immutable ordered collection where values are keyed using integers 0
  473. * thru n-1 in order.
  474. */
  475. final class ImmVector implements \ConstVector {
  476. /** Returns a ImmVector built from the values produced by the specified
  477. * Iterable.
  478. * @param mixed $iterable
  479. */
  480. <<__Native, __Rx, __AtMostRxAsArgs>>
  481. public function __construct(<<__MaybeMutable, __OnlyRxIfImpl(Rx\Traversable::class)>> mixed $iterable = null): void;
  482. /** Returns an ImmVector built from the values produced by the specified
  483. * Iterable.
  484. * @param mixed $iterable
  485. * @return object
  486. */
  487. <<__Native, __Rx, __AtMostRxAsArgs>>
  488. public static function fromItems(<<__MaybeMutable, __OnlyRxIfImpl(Rx\Traversable::class)>> mixed $iterable): object;
  489. /** Returns a ImmVector built from the keys of the specified container.
  490. * @param mixed $container
  491. * @return object
  492. */
  493. <<__Native, __Rx>>
  494. public static function fromKeysOf(mixed $container): object;
  495. /** Returns true if the ImmVector is empty, false otherwise.
  496. * @return bool
  497. */
  498. <<__Rx, __MaybeMutable>>
  499. public function isEmpty(): bool {
  500. return !$this->count();
  501. }
  502. /** Returns the number of values in the ImmVector.
  503. * @return int
  504. */
  505. <<__Native, __Rx, __MaybeMutable>>
  506. public function count(): int;
  507. /** Returns an Iterable that produces the values from this ImmVector.
  508. * @return object
  509. */
  510. <<__Rx, __MutableReturn, __MaybeMutable>>
  511. public function items(): \LazyIterableView {
  512. return new \LazyIterableView($this);
  513. }
  514. /** Returns true if the specified key is present in the ImmVector, returns
  515. * false otherwise.
  516. * @param mixed $key
  517. * @return bool
  518. */
  519. <<__Rx, __MaybeMutable>>
  520. public function containsKey(mixed $key): bool {
  521. if (!\is_int($key)) {
  522. throw new \InvalidArgumentException(
  523. "Only integer keys may be used with Vectors"
  524. );
  525. }
  526. return ($key >= 0) && ($key < $this->count());
  527. }
  528. /** Returns the value at the specified key. If the key is not present, an
  529. * exception is thrown.
  530. * @param mixed $key
  531. * @return mixed
  532. */
  533. <<__Native, __Rx, __MaybeMutable>>
  534. public function at(mixed $key): mixed;
  535. /** Returns the value at the specified key. If the key is not present, null is
  536. * returned.
  537. * @param mixed $key
  538. * @return mixed
  539. */
  540. <<__Native, __Rx, __MaybeMutable>>
  541. public function get(mixed $key): mixed;
  542. /** Returns an iterator that points to beginning of this ImmVector.
  543. * @return object
  544. */
  545. <<__Native, __Rx, __MutableReturn, __MaybeMutable>>
  546. public function getIterator(): object;
  547. /** Returns a Vector of the values produced by applying the specified callback
  548. * on each value from this ImmVector.
  549. * @param mixed $callback
  550. * @return object
  551. */
  552. <<__Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  553. public function map(<<__AtMostRxAsFunc>> mixed $callback): \HH\ImmVector {
  554. $ret = vec[];
  555. foreach ($this as $v) {
  556. $ret[] = $callback($v);
  557. }
  558. return new \HH\ImmVector($ret);
  559. }
  560. /** Returns a Vector of the values produced by applying the specified callback
  561. * on each key and value from this ImmVector.
  562. * @param mixed $callback
  563. * @return object
  564. */
  565. <<__Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  566. public function mapWithKey(<<__AtMostRxAsFunc>> mixed $callback): \HH\ImmVector {
  567. $ret = vec[];
  568. foreach ($this as $k => $v) {
  569. $ret[] = $callback($k, $v);
  570. }
  571. return new \HH\ImmVector($ret);
  572. }
  573. /** Returns a Vector of all the values from this ImmVector for which the
  574. * specified callback returns true.
  575. * @param mixed $callback
  576. * @return object
  577. */
  578. <<__Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  579. public function filter(<<__AtMostRxAsFunc>> mixed $callback): \HH\ImmVector {
  580. $ret = vec[];
  581. foreach ($this as $v) {
  582. if ($callback($v)) {
  583. $ret[] = $v;
  584. }
  585. }
  586. return new \HH\ImmVector($ret);
  587. }
  588. /** Returns a Vector of all the values from this ImmVector for which the
  589. * specified callback returns true.
  590. * @param mixed $callback
  591. * @return object
  592. */
  593. <<__Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  594. public function filterWithKey(<<__AtMostRxAsFunc>> mixed $callback): \HH\ImmVector {
  595. $ret = vec[];
  596. foreach ($this as $k => $v) {
  597. if ($callback($k, $v)) {
  598. $ret[] = $v;
  599. }
  600. }
  601. return new \HH\ImmVector($ret);
  602. }
  603. /** Returns a KeyedIterable produced by combined the specified Iterables
  604. * pair-wise.
  605. * @param mixed $iterable
  606. * @return object
  607. */
  608. <<__Native, __Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  609. public function zip(<<__MaybeMutable, __OnlyRxIfImpl(Rx\Traversable::class)>> mixed $iterable): object;
  610. /** Returns a ImmVector containing the first n values of this ImmVector.
  611. * @param mixed $n
  612. * @return object
  613. */
  614. <<__Native, __Rx, __MutableReturn, __MaybeMutable>>
  615. public function take(mixed $n): object;
  616. /** Returns a ImmVector containing the values of this ImmVector up to but not
  617. * including the first value that produces false when passed to the specified
  618. * callback.
  619. * @param mixed $callback
  620. * @return object
  621. */
  622. <<__Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  623. public function takeWhile(<<__AtMostRxAsFunc>> mixed $callback): \HH\ImmVector {
  624. $ret = vec[];
  625. foreach ($this as $v) {
  626. if (!$callback($v)) {
  627. break;
  628. }
  629. $ret[] = $v;
  630. }
  631. return new \HH\ImmVector($ret);
  632. }
  633. /** Returns a ImmVector containing all values except the first n of this
  634. * ImmVector.
  635. * @param mixed $n
  636. * @return object
  637. */
  638. <<__Native, __Rx, __MutableReturn, __MaybeMutable>>
  639. public function skip(mixed $n): object;
  640. /** Returns a ImmVector containing the values of this ImmVector excluding the
  641. * first values that produces true when passed to the specified callback.
  642. * @param mixed $fn
  643. * @return object
  644. */
  645. <<__Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  646. public function skipWhile(<<__AtMostRxAsFunc>> mixed $fn): \HH\ImmVector {
  647. $ret = vec[];
  648. $skipping = true;
  649. foreach ($this as $v) {
  650. if ($skipping) {
  651. if ($fn($v)) {
  652. continue;
  653. }
  654. $skipping = false;
  655. }
  656. $ret[] = $v;
  657. }
  658. return new \HH\ImmVector($ret);
  659. }
  660. /** Returns an ImmVector containing the specified range of values from this
  661. * ImmVector. The range is specified by two non-negative integers: a starting
  662. * position and a length.
  663. * @param mixed $start
  664. * @param mixed $len
  665. * @return object
  666. */
  667. <<__Native, __Rx, __MutableReturn, __MaybeMutable>>
  668. public function slice(mixed $start,
  669. mixed $len): object;
  670. /** Builds a new ImmVector by concatenating the elements of this ImmVector with
  671. * the elements of the specified Iterable.
  672. * @param mixed $iterable
  673. * @return object
  674. */
  675. <<__Native, __Rx, __AtMostRxAsArgs, __MutableReturn, __MaybeMutable>>
  676. public function concat(<<__MaybeMutable, __OnlyRxIfImpl(Rx\Traversable::class)>> mixed $iterable): object;
  677. /** Returns the first value from this ImmVector, or null if this ImmVector is
  678. * empty.
  679. * @return mixed
  680. */
  681. <<__Native, __Rx, __MaybeMutable>>
  682. public function firstValue(): mixed;
  683. /** Returns the first key from this ImmVector, or null if this ImmVector is
  684. * empty.
  685. * @return mixed
  686. */
  687. <<__Rx, __MaybeMutable>>
  688. public function firstKey(): mixed {
  689. return $this->count() ? 0 : null;
  690. }
  691. /** Returns the last value from this ImmVector, or null if this ImmVector is
  692. * empty.
  693. * @return mixed
  694. */
  695. <<__Native, __Rx, __MaybeMutable>>
  696. public function lastValue(): mixed;
  697. /** Returns the last key from this ImmVector, or null if this ImmVector is
  698. * empty.
  699. * @return mixed
  700. */
  701. <<__Rx, __MaybeMutable>>
  702. public function lastKey(): mixed {
  703. $count = $this->count();
  704. return $count ? ($count - 1) : null;
  705. }
  706. /** Returns an Iterable that produces the keys from this ImmVector.
  707. * @return object
  708. */
  709. <<__Native, __Rx, __MutableReturn, __MaybeMutable>>
  710. public function keys(): object;
  711. /** @return string
  712. */
  713. <<__Rx, __MaybeMutable>>
  714. public function __toString(): string { return "ImmVector"; }
  715. /** Returns a Vector built from the values of this ImmVector.
  716. * @return object
  717. */
  718. <<__Native, __Rx, __MutableReturn, __MaybeMutable>>
  719. public function toVector(): object;
  720. /** Returns an immutable version of this collection.
  721. * @return object
  722. */
  723. <<__Rx, __MaybeMutable>>
  724. public function toImmVector(): this {
  725. return $this;
  726. }
  727. /** Returns a Map built from the keys and values of this ImmVector.
  728. * @return object
  729. */
  730. <<__Native, __Rx, __MutableReturn, __MaybeMutable>>
  731. public function toMap(): object;
  732. /** Returns a ImmMap built from the keys and values of this ImmVector.
  733. * @return object
  734. */
  735. <<__Native, __Rx, __MaybeMutable>>
  736. public function toImmMap(): object;
  737. /** Returns a Set built from the values of this ImmVector.
  738. * @return object
  739. */
  740. <<__Native, __Rx, __MutableReturn, __MaybeMutable>>
  741. public function toSet(): object;
  742. /** Returns a ImmSet built from the values of this ImmVector.
  743. * @return object
  744. */
  745. <<__Native, __Rx, __MaybeMutable>>
  746. public function toImmSet(): object;
  747. /** Returns an immutable version of this collection.
  748. * @return object
  749. */
  750. <<__Rx, __MaybeMutable>>
  751. public function immutable(): this {
  752. return $this;
  753. }
  754. /** Returns a copy of this ImmVector.
  755. * @return object
  756. */
  757. <<__Rx, __MutableReturn, __MaybeMutable>>
  758. public function values(): this {
  759. return new self($this);
  760. }
  761. /** Returns a lazy iterable view of this ImmVector.
  762. * @return object
  763. */
  764. <<__Rx, __MutableReturn, __MaybeMutable>>
  765. public function lazy(): \LazyKeyedIterableView {
  766. return new \LazyKeyedIterableView($this);
  767. }
  768. /** Returns an array built from the values from this ImmVector.
  769. * @return array
  770. */
  771. <<__Native, __Rx, __MaybeMutable>>
  772. public function toArray(): array;
  773. <<__Native, __Rx, __MaybeMutable>>
  774. public function toVArray(): varray;
  775. <<__Native, __Rx, __MaybeMutable>>
  776. public function toDArray(): darray;
  777. /** Returns an array built from the keys from this ImmVector.
  778. * @return array
  779. */
  780. <<__Rx, __ProvenanceSkipFrame>>
  781. public function toKeysArray(): varray {
  782. $count = $this->count();
  783. return $count ? varray(\range(0, $count - 1)) : varray[];
  784. }
  785. /** Returns an array built from the values from this ImmVector.
  786. * @return array
  787. */
  788. <<__Rx, __MaybeMutable, __ProvenanceSkipFrame>>
  789. public function toValuesArray(): varray {
  790. return $this->toVArray();
  791. }
  792. /** Returns index of the specified value if it is present, -1 otherwise.
  793. * @param mixed $search_value
  794. * @return int
  795. */
  796. <<__Native, __Rx, __MaybeMutable>>
  797. public function linearSearch(mixed $search_value): int;
  798. }
  799. } // namespace HH