PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

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