Tuple.hx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 python;
  23. import python.internal.UBuiltins;
  24. import python.Syntax;
  25. @:native("tuple")
  26. extern class Tuple<X> implements ArrayAccess<X> {
  27. @:overload(function():Void {})
  28. function new(a:Array<X>):Void;
  29. var length(get, never):Int;
  30. inline function get_length():Int {
  31. return UBuiltins.len(this);
  32. }
  33. inline function toArray():Array<X> {
  34. return UBuiltins.list(this);
  35. }
  36. }
  37. @:native("tuple")
  38. extern class Tuple1<A> extends Tuple<Dynamic> {
  39. static inline function make<A>(a:A):Tuple1<A>
  40. return Syntax.tuple(a);
  41. var _1(get, null):A;
  42. inline function get__1():A
  43. return this[0];
  44. }
  45. @:native("tuple")
  46. extern class Tuple2<A, B> extends Tuple<Dynamic> {
  47. static inline function make<A, B>(a:A, b:B):Tuple2<A, B>
  48. return Syntax.tuple(a, b);
  49. var _1(get, null):A;
  50. inline function get__1():A
  51. return this[0];
  52. var _2(get, null):B;
  53. inline function get__2():B
  54. return this[1];
  55. }
  56. @:native("tuple")
  57. extern class Tuple3<A, B, C> extends Tuple<Dynamic> {
  58. static inline function make<A, B, C>(a:A, b:B, c:C):Tuple3<A, B, C>
  59. return Syntax.tuple(a, b, c);
  60. var _1(get, null):A;
  61. inline function get__1():A
  62. return this[0];
  63. var _2(get, null):B;
  64. inline function get__2():B
  65. return this[1];
  66. var _3(get, null):C;
  67. inline function get__3():C
  68. return this[2];
  69. }
  70. @:native("tuple")
  71. extern class Tuple4<A, B, C, D> extends Tuple<Dynamic> {
  72. static inline function make<A, B, C, D>(a:A, b:B, c:C, d:D):Tuple4<A, B, C, D>
  73. return Syntax.tuple(a, b, c, d);
  74. var _1(get, null):A;
  75. inline function get__1():A
  76. return this[0];
  77. var _2(get, null):B;
  78. inline function get__2():B
  79. return this[1];
  80. var _3(get, null):C;
  81. inline function get__3():C
  82. return this[2];
  83. var _4(get, null):D;
  84. inline function get__4():D
  85. return this[3];
  86. }
  87. @:native("tuple")
  88. extern class Tuple5<A, B, C, D, E> extends Tuple<Dynamic> {
  89. static inline function make<A, B, C, D, E>(a:A, b:B, c:C, d:D, e:E):Tuple5<A, B, C, D, E>
  90. return Syntax.tuple(a, b, c, d, e);
  91. var _1(get, null):A;
  92. inline function get__1():A
  93. return this[0];
  94. var _2(get, null):B;
  95. inline function get__2():B
  96. return this[1];
  97. var _3(get, null):C;
  98. inline function get__3():C
  99. return this[2];
  100. var _4(get, null):D;
  101. inline function get__4():D
  102. return this[3];
  103. var _5(get, null):E;
  104. inline function get__5():E
  105. return this[4];
  106. }