Haskell语言Maybe模块中函数catMaybes的用法及代码示例。
用法类型:
[Maybe a] -> [a]
从Maybe列表创建Just值列表
示例1:
源码:
a = [(1,'A'),(2,'B'),(3,'C')]
输入:
catMaybes [lookup 0 a, lookup 1 a, lookup 3 a, lookup 12 a]
输出:
"AC"
示例2:
源码:
b = [(1,11),(2,22),(3,33)]
输入:
catMaybes [lookup 0 b, lookup 1 b, lookup 3 b, lookup 12 b]
输出:
[11,33]
注:本文由纯净天空筛选整理自 haskell catMaybes。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。