Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Ls [T](head: T,tail: Ls[T]){
- val tl = tail
- val hd = head
- def foldr[ACC](acc: ACC,fun:(ACC,T)=>ACC):ACC = {
- if (tl==null){
- fun(acc,hd)
- }else{
- tl.foldr(fun(acc,hd),fun)
- }
- }
- }
- object Main extends App{
- println("test")
- val ls = new Ls[Int](1,new Ls[Int](2,new Ls[Int](3,null)))
- println(ls.foldr[Int](0,(acc:Int,x:Int) => acc+x+1))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement