- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
final HCons<String, HCons<Integer, HCons<Boolean, HNil>>> a =
nil().extend(true).extend(3).extend("Foo");
final HCons<Double, HCons<String, HCons<Integer[], HNil>>> b =
nil().extend(new Integer[]{1, 2}).extend("Bar").extend(4.0);
// A lot of type annotation
final HAppend<HNil, HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
HCons<Double, HCons<String, HCons<Integer[], HNil>>>> zero = append();
final HAppend<HCons<Boolean, HNil>, HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>> one = append(zero);
final HAppend<HCons<Integer, HCons<Boolean, HNil>>, HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
HCons<Integer, HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>>> two = append(one);
final HAppend<HCons<String, HCons<Integer, HCons<Boolean, HNil>>>,
HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
HCons<String, HCons<Integer, HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>>>>
three = append(two);
// And all of that lets us append one list to the other.
final HCons<String, HCons<Integer, HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>>>
x = three.append(a, b);
// And we can access the components of the concatenated list in a type-safe manner
System.out.println(x.head()); // Foo
System.out.println(x.tail().tail().tail().tail().head()); // Bar
Это вот такая она, функциональщина, упрощающая жизнь.
http://functionaljava.googlecode.com/svn/artifacts/3.0/demo/1.5/HList_append.java