From 9dc1549431f34e4720453f8c579b66648526bb29 Mon Sep 17 00:00:00 2001 From: Max New Date: Tue, 24 Dec 2013 00:40:33 -0600 Subject: [PATCH] Uncomplicate keepWhen implementation --- libraries/Signal.elm | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/libraries/Signal.elm b/libraries/Signal.elm index a9b1163..9063e0d 100644 --- a/libraries/Signal.elm +++ b/libraries/Signal.elm @@ -32,7 +32,7 @@ the [`Time`](/docs/Signal/Time.elm) library. import Native.Signal import List (foldr) -import Basics (otherwise, not) +import Basics (fst, snd, not) import Native.Error import Maybe as M @@ -127,17 +127,7 @@ does not allow undefined signals, so a base case must be provided in case the first signal is not true initially. -} keepWhen : Signal Bool -> a -> Signal a -> Signal a keepWhen bs def sig = - let toMaybe : Bool -> a -> M.Maybe a - toMaybe b x = if b - then M.Just x - else M.Nothing - - fromJust : M.Maybe a -> a - fromJust m = case m of - M.Just x -> x - M.Nothing -> Native.Error.raise "Internal bug in keepWhen! Please report at https://github.com/evancz/Elm/issues?state=open" - in - fromJust <~ (keepIf M.isJust (M.Just def) (toMaybe <~ (sampleOn sig bs) ~ sig)) + snd <~ (keepIf fst (False, def) ((,) <~ (sampleOn sig bs) ~ sig)) {-| Drop events when the first signal is true. When the first signal becomes false, the most recent value of the second signal will be propagated. Until the