Tuple.hx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C)2005-2017 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> return Syntax.tuple(a);
  40. var _1(get, null):A;
  41. inline function get__1():A return this[0];
  42. }
  43. @:native("tuple")
  44. extern class Tuple2<A,B> extends Tuple<Dynamic> {
  45. static inline function make <A,B>(a:A, b:B):Tuple2<A,B> return Syntax.tuple(a,b);
  46. var _1(get, null):A;
  47. inline function get__1():A return this[0];
  48. var _2(get, null):B;
  49. inline function get__2():B return this[1];
  50. }
  51. @:native("tuple")
  52. extern class Tuple3<A,B,C> extends Tuple<Dynamic> {
  53. static inline function make <A,B,C>(a:A, b:B,c:C):Tuple3<A,B,C> return Syntax.tuple(a,b,c);
  54. var _1(get, null):A;
  55. inline function get__1():A return this[0];
  56. var _2(get, null):B;
  57. inline function get__2():B return this[1];
  58. var _3(get, null):C;
  59. inline function get__3():C return this[2];
  60. }
  61. @:native("tuple")
  62. extern class Tuple4<A,B,C,D> extends Tuple<Dynamic> {
  63. static inline function make <A,B,C,D>(a:A, b:B,c:C,d:D):Tuple4<A,B,C,D> return Syntax.tuple(a,b,c,d);
  64. var _1(get, null):A;
  65. inline function get__1():A return this[0];
  66. var _2(get, null):B;
  67. inline function get__2():B return this[1];
  68. var _3(get, null):C;
  69. inline function get__3():C return this[2];
  70. var _4(get, null):D;
  71. inline function get__4():D return this[3];
  72. }
  73. @:native("tuple")
  74. extern class Tuple5<A,B,C,D,E> extends Tuple<Dynamic> {
  75. 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> return Syntax.tuple(a,b,c,d,e);
  76. var _1(get, null):A;
  77. inline function get__1():A return this[0];
  78. var _2(get, null):B;
  79. inline function get__2():B return this[1];
  80. var _3(get, null):C;
  81. inline function get__3():C return this[2];
  82. var _4(get, null):D;
  83. inline function get__4():D return this[3];
  84. var _5(get, null):E;
  85. inline function get__5():E return this[4];
  86. }