File: Main.hx

package info (click to toggle)
haxe 1%3A4.3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,520 kB
  • sloc: ml: 137,268; ansic: 2,491; makefile: 456; java: 386; cs: 336; cpp: 318; python: 318; sh: 75; objc: 64; php: 50; xml: 31; javascript: 11
file content (55 lines) | stat: -rw-r--r-- 1,078 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class Main {
	static function main() {
		var comp = new AComponent([1, 2, 3]);
		trace(comp.doSomething());
	}
}

interface Component<T> {
	function doSomething():T;
}

@:forward
@:multiType
abstract AComponent<T>(Component<T>) {
	public function new(value:T);

	@:to public static inline function toInt(t:Component<Int>, value:Int):IntComponent {
		return new IntComponent(value);
	}

	@:to public static inline function toIntArray(t:Component<Array<Int>>, value:Array<Int>):ArrayComponent<Int> {
		return new ArrayComponent(value);
	}
}

@:generic
@:remove
class ArrayComponent<T> implements Component<Array<T>> {
	final value:Array<T>;

	public function new(value:Array<T>) {
		this.value = value;
		var x = [];
		for (i in 0...value.length) {
			var y = new AComponent(this.value[i]).doSomething();
			x.push(y);
		}
	}

	public function doSomething():Array<T> {
		return this.value;
	}
}

class IntComponent implements Component<Int> {
	final value:Int;

	public function new(value:Int) {
		this.value = value;
	}

	public function doSomething():Int {
		return value;
	}
}