Haskell語言List模塊中函數mapAccumR的用法及代碼示例。
用法類型:
(a -> b -> (a,c)) -> a -> [b] -> (a,[c])
mapAccumR類似於mapAccumL除了列表是從右到左而不是從左到右處理
示例1:
輸入:
mapAccumR (\x y -> (x,x*y)) 5 [9,6,3]
輸出:
(5,[45,30,15])
示例2:
輸入:
mapAccumR (\x y -> (x+y,x*y)) 5 [2,4,8]
輸出:
(19,[34,52,40])
示例3:
輸入:
mapAccumR (\x y -> (x+y,y)) 5 [2,4,8]
輸出:
(19,[2,4,8])
示例4:
輸入:
mapAccumR (\x y -> (y,y)) 5 [2,4,8]
輸出:
(2,[2,4,8])
示例5:
輸入:
mapAccumR (\x y -> (x,x)) 5 [2,4,8]
輸出:
(5,[5,5,5])
相關用法
- haskell group用法及代碼示例
- haskell groupBy用法及代碼示例
- haskell inits用法及代碼示例
- haskell intersperse用法及代碼示例
- haskell mapAccumL用法及代碼示例
- haskell nub用法及代碼示例
- haskell nubBy用法及代碼示例
- haskell partition用法及代碼示例
- haskell sort用法及代碼示例
- haskell sortBy用法及代碼示例
- haskell tails用法及代碼示例
- haskell transpose用法及代碼示例
注:本文由純淨天空篩選整理自 haskell mapAccumR。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。