SHOW:
|
|
- or go back to the newest paste.
1 | - | def weirdFold[T,B](s:List[T], init:B, f:(T,List[T], B) => (T,B)) = { |
1 | + | def weirdFold[T,B](s:List[T], init:B, f:(T,List[T], B) => (T,B)) = { |
2 | - | var ts = s.toVector |
2 | + | var ts = s.toVector |
3 | - | var v = init |
3 | + | var v = init |
4 | - | for (i <- 0 until ts.length) { |
4 | + | for (i <- 0 until ts.length) { |
5 | - | val t = ts(i) |
5 | + | val t = ts(i) |
6 | - | val (newV, newT) = f(t, ts.toList, v) |
6 | + | val (newT, newV) = f(t, ts.toList, v) |
7 | - | v = newV |
7 | + | v = newV |
8 | - | ts = ts.updated(i, newT) |
8 | + | ts = ts.updated(i, newT) |
9 | - | } |
9 | + | } |
10 | - | (ts.toList, ov) |
10 | + | (ts.toList, v) |
11 | } |