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 红包祝福语简短10字
18 周六早晨祝福语简短