Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def weirdFold[T,B](s:List[T], init:B, f:(T,List[T], B) => (T,B)) = {
- def helper(s:List[T], b:B, i:Int) = {
- val ts = s.toVector
- if (i > ts.length - 1) {
- (s, b)
- } else {
- val t = ts(i)
- val (newT, newB) = f(t, s, b)
- (ts.updated(i, newT), newB)
- }
- }
- helper(s, init, 0)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement