Advertisement
Guest User

Untitled

a guest
Aug 10th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.33 KB | None | 0 0
  1.   def weirdFold[T,B](s:List[T], init:B, f:(T,List[T], B) => (T,B)) = {
  2.     def helper(s:List[T], b:B, i:Int) = {
  3.       val ts = s.toVector
  4.       if (i > ts.length - 1) {
  5.         (s, b)
  6.       } else {
  7.         val t = ts(i)
  8.         val (newT, newB) = f(t, s, b)
  9.         (ts.updated(i, newT), newB)
  10.       }
  11.     }
  12.     helper(s, init, 0)
  13.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement