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 婚前女儿生日祝福语简短