Haskell語言List模塊中函數mapAccumL的用法及代碼示例。
用法類型:
(a -> b -> (a,c)) -> a -> [b] -> (a,[c])
mapAccumLf s l將f應用於累加的"state"參數s並依次應用於l的每個元素
示例1:
輸入:
mapAccumL (\x y -> (x,x*y)) 5 [9,6,3]
輸出:
(5,[45,30,15])
示例2:
輸入:
mapAccumL (\x y -> (x+y,x*y)) 5 [2,4,8]
輸出:
(19,[10,28,88])
示例3:
輸入:
mapAccumL (\x y -> (x+y,y)) 5 [2,4,8]
輸出:
(19,[2,4,8])
示例4:
輸入:
mapAccumL (\x y -> (y,y)) 5 [2,4,8]
輸出:
(8,[2,4,8])
示例5:
輸入:
mapAccumL (\x y -> (x,x)) 5 [2,4,8]
輸出:
(5,[5,5,5])
相關用法
- haskell group用法及代碼示例
- haskell groupBy用法及代碼示例
- haskell inits用法及代碼示例
- haskell intersperse用法及代碼示例
- haskell mapAccumR用法及代碼示例
- haskell nub用法及代碼示例
- haskell nubBy用法及代碼示例
- haskell partition用法及代碼示例
- haskell sort用法及代碼示例
- haskell sortBy用法及代碼示例
- haskell tails用法及代碼示例
- haskell transpose用法及代碼示例
注:本文由純淨天空篩選整理自 haskell mapAccumL。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。