Elm筛选清单
例子
List.filter:(a->Bool)->Lista->Lista是一个高阶函数,它将一个参数函数从任何值转换为布尔值,并将该函数应用于给定列表的每个元素,仅保留该函数为其返回的那些元素True。List.filter以第一个参数为函数的函数通常称为谓词。
import String
catStory : List String
catStory =
["a", "crazy", "cat", "walked", "into", "a", "bar"]
-- Any word with more than 3 characters is so long!
isLongWord : String -> Bool
isLongWord string =
String.lengthstring > 3
longWordsFromCatStory : List String
longWordsFromCatStory =
List.filterisLongWord catStory在中对此进行评估elm-repl:
> longWordsFromCatStory ["crazy", "walked", "into"] : List String > >List.filter(String.startsWith "w") longWordsFromCatStory ["walked"] : List String
热门推荐
10 读书祝福语女生短句简短
11 感谢同事新婚祝福语简短
12 感谢教官文案祝福语简短
13 员工聚会蛋糕祝福语简短
14 元宵发客户祝福语简短
15 给团队信心祝福语简短
16 医美的祝福语大全简短
17 异国姻缘的祝福语简短
18 兄妹拍照祝福语简短的话