elm/exercises/strain/Strain.example.elm
2016-12-17 17:29:40 -05:00

21 lines
424 B
Elm

module Strain exposing (..)
import List
keep : (a -> Bool) -> List a -> List a
keep predicate list =
List.foldr (consIf predicate) [] list
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