Set.hx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (C)2005-2019 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package js.lib;
  23. import js.lib.Map.MapEntry;
  24. import js.lib.Iterator;
  25. /**
  26. The `js.Set` object lets you store unique values of any type, whether
  27. primitive values or object references.
  28. Documentation [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) by [Mozilla Contributors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set$history), licensed under [CC-BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/).
  29. **/
  30. @:native("Set")
  31. extern class Set<T> {
  32. /**
  33. The number of values in the `js.Set` object.
  34. **/
  35. var size(default, null):Int;
  36. /**
  37. If an iterable object is passed, all of its elements will be added to
  38. the new `js.Set`.
  39. **/
  40. @:pure function new(?iterable:Any);
  41. /**
  42. Returns a boolean asserting whether an element is present with the given
  43. value in the `js.Set` object or not.
  44. **/
  45. @:pure function has(value:T):Bool;
  46. /**
  47. Appends a new element with the given value to the `js.Set` object.
  48. Returns the `js.Set` object.
  49. **/
  50. function add(value:T):Set<T>;
  51. /**
  52. Removes the element associated to the value and returns the value that
  53. `has(value)` would have previously returned.
  54. `has(value)` will return `false` afterwards.
  55. **/
  56. function delete(value:T):Bool;
  57. /**
  58. Removes all elements from the `js.Set` object.
  59. **/
  60. function clear():Void;
  61. /**
  62. Calls `callback` once for each key-value pair present in the `js.Set`
  63. object, in insertion order.
  64. If a `thisArg` parameter is provided to forEach, it will be used as the
  65. `this` value for each callback.
  66. **/
  67. function forEach(callback:(value:T, key:T, set:Set<T>) -> Void, ?thisArg:Any):Void;
  68. /**
  69. Returns a new `js.lib.Iterator` object that contains the keys for each element
  70. in the `js.Set` object in insertion order.
  71. **/
  72. function keys():Iterator<T>;
  73. /**
  74. Returns a new `js.lib.Iterator` object that contains the values for each
  75. element in the `js.Set` object in insertion order.
  76. **/
  77. function values():Iterator<T>;
  78. /**
  79. Returns a new `js.lib.Iterator` object that contains an array of
  80. `[value, value]` for each element in the `js.Set` object, in insertion
  81. order.
  82. This is kept similar to the `js.Map` object, so that each entry has the
  83. same value for its key and value here.
  84. **/
  85. function entries():Iterator<MapEntry<T, T>>;
  86. }