| 1 | fn mk_chan[T](f fn () T) chan T { |
| 2 | gench := chan T{cap: 1} |
| 3 | // // This does not work, yet |
| 4 | // go fn(ch2 chan T, f2 fn() T) { |
| 5 | // res := f2() |
| 6 | // ch2 <- res |
| 7 | // }(gench, f) |
| 8 | return gench |
| 9 | } |
| 10 | |
| 11 | fn g(x f64, y f64) f64 { |
| 12 | return x * x + y * y |
| 13 | } |
| 14 | |
| 15 | fn test_generic_chan_return() { |
| 16 | ch := mk_chan[f64](fn () f64 { |
| 17 | return g(3, 4) |
| 18 | }) |
| 19 | ch <- 13.4 |
| 20 | res := <-ch |
| 21 | assert res == 13.4 |
| 22 | } |
| 23 |