Haskell学习笔记--scanl/scanr

Haskell学习笔记--scanl/scanr

类似foldl/flodr

但是将每一步都记录下来,保存为list

scanl :: (b -> a -> b) -> b -> [a] -> [b]

scanr :: (a -> b -> b) -> b -> [a] -> [b]

 

eg.

scanl (+) 0 [1,2,3]

--[0,1,3,6]

scanr (+) 0 [1,2,3]

--[6,5,3,0]

 

 

  

 

posted @ 2021-10-22 21:34  liankewei123456  阅读(101)  评论(0编辑  收藏  举报