2016-05-12 22:26:52 -04:00
|
|
|
module Strain exposing (..)
|
2015-10-13 11:56:46 -07:00
|
|
|
|
|
|
|
import List
|
|
|
|
|
2016-03-16 21:38:51 -04:00
|
|
|
|
|
|
|
keep : (a -> Bool) -> List a -> List a
|
|
|
|
keep predicate list =
|
2016-06-19 17:46:13 -04:00
|
|
|
List.foldr (consIf predicate) [] list
|
2016-03-16 21:38:51 -04:00
|
|
|
|
2015-10-13 11:56:46 -07:00
|
|
|
|
|
|
|
discard : (a -> Bool) -> List a -> List a
|
2016-03-16 21:38:51 -04:00
|
|
|
discard predicate list =
|
2016-06-19 17:46:13 -04:00
|
|
|
List.foldr (consIf (\v -> not <| predicate v)) [] list
|
2016-03-16 21:52:25 -04:00
|
|
|
|
|
|
|
|
|
|
|
consIf : (a -> Bool) -> a -> List a -> List a
|
|
|
|
consIf predicate value list =
|
2016-06-19 17:46:13 -04:00
|
|
|
if predicate value then
|
|
|
|
value :: list
|
|
|
|
else
|
|
|
|
list
|