File tree Expand file tree Collapse file tree 2 files changed +61
-15
lines changed
Expand file tree Collapse file tree 2 files changed +61
-15
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ object test1 :
2+
3+ trait Trait
4+
5+ trait Managed [T ](x : T ) {
6+
7+ def flatMap (f : T => Managed [T ]): Managed [T ] = new Managed [T ](x) {
8+
9+ def make () = new Trait {
10+ val t : T = x
11+ val u =
12+ try {
13+ f(t)
14+ } catch {
15+ case e : Exception => ()
16+ }
17+ }
18+ }
19+ }
20+
21+ object test2 :
22+
23+ trait Trait
24+
25+ trait Managed [T ](x : T ) {
26+ def xx = x
27+
28+ def flatMap (f : T => Managed [T ]): Managed [T ] = new Managed [T ](x) {
29+ def make () = new Trait {
30+ val t : T = x
31+ val u = {
32+ def foo = f(t)
33+ assert(foo.xx == 22 )
34+ foo
35+ }
36+ }
37+ make()
38+ }
39+ }
40+
41+ object test3 :
42+
43+ trait Trait
44+
45+ trait Managed [T ]:
46+
47+ def flatMap [U ](f : T => Managed [U ]) =
48+ class C :
49+ def make () =
50+ class D :
51+ def bar (): T = ???
52+ val t : T = ???
53+ val u =
54+ def foo = (f(t), f(bar()))
55+ foo
56+ new D ().u
57+ ()
58+
59+ @ main def Test () =
60+ val m = new test2.Managed [Int ](22 ) {}
61+ m.flatMap(x => new test2.Managed (x) {})
You can’t perform that action at this time.
0 commit comments