Tuple.hx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package python.lib;
  2. import python.lib.Builtin;
  3. import python.Syntax;
  4. @:pythonImport("builtins", "tuple")
  5. extern class Tuple<X> implements ArrayAccess<X> {
  6. @:overload(function ():Void {})
  7. public function new (a:Array<X>):Void;
  8. public var length(get_length, null):Int;
  9. inline function get_length():Int {
  10. return Builtin.len(this);
  11. }
  12. public inline function toArray ():Array<X>
  13. {
  14. return Builtin.list(this);
  15. }
  16. }
  17. extern class Tup2 <A,B> extends Tuple<Dynamic>
  18. {
  19. public static inline function create <A,B>(a:A, b:B):Tup2<A,B> return Syntax.tuple(a,b);
  20. public var _1(get, null):A;
  21. public inline function get__1():A return this[0];
  22. public var _2(get, null):B;
  23. public inline function get__2():B return this[1];
  24. }
  25. extern class Tup3 <A,B,C> extends Tuple<Dynamic>
  26. {
  27. public static inline function create <A,B,C>(a:A, b:B,c:C):Tup3<A,B,C> return Syntax.tuple(a,b,c);
  28. public var _1(get, null):A;
  29. public inline function get__1():A return this[0];
  30. public var _2(get, null):B;
  31. public inline function get__2():B return this[1];
  32. public var _3(get, null):C;
  33. public inline function get__3():C return this[2];
  34. }
  35. extern class Tup4 <A,B,C,D> extends Tuple<Dynamic>
  36. {
  37. 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);
  38. public var _1(get, null):A;
  39. public inline function get__1():A return this[0];
  40. public var _2(get, null):B;
  41. public inline function get__2():B return this[1];
  42. public var _3(get, null):C;
  43. public inline function get__3():C return this[2];
  44. public var _4(get, null):D;
  45. public inline function get__4():D return this[3];
  46. }
  47. extern class Tup5 <A,B,C,D,E> extends Tuple<Dynamic>
  48. {
  49. 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);
  50. public var _1(get, null):A;
  51. public inline function get__1():A return this[0];
  52. public var _2(get, null):B;
  53. public inline function get__2():B return this[1];
  54. public var _3(get, null):C;
  55. public inline function get__3():C return this[2];
  56. public var _4(get, null):D;
  57. public inline function get__4():D return this[3];
  58. public var _5(get, null):E;
  59. public inline function get__5():E return this[4];
  60. }