Haskell語言List模塊中函數find的用法及代碼示例。
用法類型:
(a -> Bool) -> [a] -> Maybe a
函數find返回滿足謂詞的列表的第一個元素;如果沒有這樣的元素,則返回Nothing。findIndex返回相應的索引。findIndices返回所有此類索引的列表。
示例1:
輸入:
find (>3) [0,2,4,6,8]
輸出:
Just 4
示例2:
輸入:
find (==3) [0,2,4,6,8]
輸出:
Nothing
示例3:
輸入:
find even [2,4,6,8]
輸出:
Just 2
示例4:
輸入:
find (\x -> 5**x > 10000) [2,4,6,8]
輸出:
Just 6.0
相關用法
- haskell elemIndex用法及代碼示例
- haskell elemIndices用法及代碼示例
- haskell findIndex用法及代碼示例
- haskell findIndices用法及代碼示例
注:本文由純淨天空篩選整理自 haskell find。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。