Set.hx 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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;
  23. import js.Map.MapEntry;
  24. /**
  25. The `js.Set` object lets you store unique values of any type, whether
  26. primitive values or object references.
  27. 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/).
  28. **/
  29. @:native("Set")
  30. extern class Set<T> {
  31. /**
  32. The number of values in the `js.Set` object.
  33. **/
  34. var size(default,null):Int;
  35. /**
  36. If an iterable object is passed, all of its elements will be added to
  37. the new `js.Set`.
  38. **/
  39. @:pure function new(?iterable:Any);
  40. /**
  41. Returns a boolean asserting whether an element is present with the given
  42. value in the `js.Set` object or not.
  43. **/
  44. @:pure function has(value:T):Bool;
  45. /**
  46. Appends a new element with the given value to the `js.Set` object.
  47. Returns the `js.Set` object.
  48. **/
  49. function add(value:T):Set<T>;
  50. /**
  51. Removes the element associated to the value and returns the value that
  52. `has(value)` would have previously returned.
  53. `has(value)` will return `false` afterwards.
  54. **/
  55. function delete(value:T):Bool;
  56. /**
  57. Removes all elements from the `js.Set` object.
  58. **/
  59. function clear():Void;
  60. /**
  61. Calls `callback` once for each key-value pair present in the `js.Set`
  62. object, in insertion order.
  63. If a `thisArg` parameter is provided to forEach, it will be used as the
  64. `this` value for each callback.
  65. **/
  66. function forEach(callback:(value:T, key:T, set:Set<T>)->Void, ?thisArg:Any):Void;
  67. /**
  68. Returns a new `JsIterator` object that contains the keys for each element
  69. in the `js.Set` object in insertion order.
  70. **/
  71. function keys():JsIterator<T>;
  72. /**
  73. Returns a new `JsIterator` object that contains the values for each
  74. element in the `js.Set` object in insertion order.
  75. **/
  76. function values():JsIterator<T>;
  77. /**
  78. Returns a new `JsIterator` object that contains an array of
  79. `[value, value]` for each element in the `js.Set` object, in insertion
  80. order.
  81. This is kept similar to the `js.Map` object, so that each entry has the
  82. same value for its key and value here.
  83. **/
  84. function entries():JsIterator<MapEntry<T,T>>;
  85. }