elm/exercises/strain/Strain.example

22 lines
405 B
Text
Raw Normal View History

module Strain (..) where
2015-10-13 18:56:46 +00:00
import List
keep : (a -> Bool) -> List a -> List a
keep predicate list =
List.foldr (consIf predicate) [] list
2015-10-13 18:56:46 +00:00
discard : (a -> Bool) -> List a -> List a
discard predicate list =
List.foldr (consIf (\v -> not <| predicate v)) [] list
consIf : (a -> Bool) -> a -> List a -> List a
consIf predicate value list =
if predicate value then
value :: list
else
list