Tuple.hx 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C)2005-2012 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.lib;
  23. import python.internal.UBuiltins;
  24. import python.Syntax;
  25. @:pythonImport("builtins", "tuple")
  26. extern class Tuple<X> implements ArrayAccess<X> {
  27. @:overload(function ():Void {})
  28. public function new (a:Array<X>):Void;
  29. public var length(get_length,never):Int;
  30. inline function get_length():Int {
  31. return UBuiltins.len(this);
  32. }
  33. public inline function toArray ():Array<X>
  34. {
  35. return UBuiltins.list(this);
  36. }
  37. }
  38. extern class Tup2 <A,B> extends Tuple<Dynamic>
  39. {
  40. public static inline function create <A,B>(a:A, b:B):Tup2<A,B> return Syntax.tuple(a,b);
  41. public var _1(get, null):A;
  42. public inline function get__1():A return this[0];
  43. public var _2(get, null):B;
  44. public inline function get__2():B return this[1];
  45. }
  46. extern class Tup3 <A,B,C> extends Tuple<Dynamic>
  47. {
  48. public static inline function create <A,B,C>(a:A, b:B,c:C):Tup3<A,B,C> return Syntax.tuple(a,b,c);
  49. public var _1(get, null):A;
  50. public inline function get__1():A return this[0];
  51. public var _2(get, null):B;
  52. public inline function get__2():B return this[1];
  53. public var _3(get, null):C;
  54. public inline function get__3():C return this[2];
  55. }
  56. extern class Tup4 <A,B,C,D> extends Tuple<Dynamic>
  57. {
  58. public static inline function create <A,B,C,D>(a:A, b:B,c:C,d:D):Tup4<A,B,C,D> return Syntax.tuple(a,b,c,d);
  59. public var _1(get, null):A;
  60. public inline function get__1():A return this[0];
  61. public var _2(get, null):B;
  62. public inline function get__2():B return this[1];
  63. public var _3(get, null):C;
  64. public inline function get__3():C return this[2];
  65. public var _4(get, null):D;
  66. public inline function get__4():D return this[3];
  67. }
  68. extern class Tup5 <A,B,C,D,E> extends Tuple<Dynamic>
  69. {
  70. public static inline function create <A,B,C,D,E>(a:A, b:B,c:C,d:D,e:E):Tup5<A,B,C,D,E> return Syntax.tuple(a,b,c,d,e);
  71. public var _1(get, null):A;
  72. public inline function get__1():A return this[0];
  73. public var _2(get, null):B;
  74. public inline function get__2():B return this[1];
  75. public var _3(get, null):C;
  76. public inline function get__3():C return this[2];
  77. public var _4(get, null):D;
  78. public inline function get__4():D return this[3];
  79. public var _5(get, null):E;
  80. public inline function get__5():E return this[4];
  81. }