@@ -32,6 +32,10 @@ the [`Time`](/docs/Signal/Time.elm) library.
32import Native.Signal
32import Native.Signal
33import List (foldr)
33import List (foldr)
35+import Basics (otherwise, not)
35data Signal a = Signal
39data Signal a = Signal
37{-| Create a constant signal that never changes. -}
41{-| Create a constant signal that never changes. -}
@@ -122,7 +126,18 @@ Until the first signal becomes false again, all events will be propagated. Elm
122does not allow undefined signals, so a base case must be provided in case the
126does not allow undefined signals, so a base case must be provided in case the
123first signal is not true initially. -}
127first signal is not true initially. -}
124keepWhen : Signal Bool -> a -> Signal a -> Signal a
128keepWhen : Signal Bool -> a -> Signal a -> Signal a
125−keepWhen = Native.Signal.keepWhen
129+keepWhen bs def sig =
130+ let toMaybe : Bool -> a -> M.Maybe a
135+ fromJust : M.Maybe a -> a
136+ fromJust m = case m of
138+ M.Nothing -> Native.Error.raise "Internal bug in keepWhen! Please report at https://github.com/evancz/Elm/issues?state=open"
140+ fromJust <~ (keepIf M.isJust (M.Just def) (toMaybe <~ (sampleOn sig bs) ~ sig))
127{-| Drop events when the first signal is true. When the first signal becomes
142{-| Drop events when the first signal is true. When the first signal becomes
128false, the most recent value of the second signal will be propagated. Until the
143false, the most recent value of the second signal will be propagated. Until the
@@ -130,7 +145,7 @@ first signal becomes true again, all events will be propagated. Elm does not
130allow undefined signals, s oa base case must be provided in case the first
145allow undefined signals, s oa base case must be provided in case the first
131signal is true initially. -}
146signal is true initially. -}
132dropWhen : Signal Bool -> a -> Signal a -> Signal a
147dropWhen : Signal Bool -> a -> Signal a -> Signal a
133−dropWhen = Native.Signal.dropWhen
148+dropWhen bs = keepWhen (not <~ bs)
135{-| Drop updates that repeat the current value of the signal.
150{-| Drop updates that repeat the current value of the signal.