Skip to content

Instantly share code, notes, and snippets.

@artisonian
Created October 31, 2015 20:28
Show Gist options
  • Save artisonian/2193dff11dd25ff05290 to your computer and use it in GitHub Desktop.
Save artisonian/2193dff11dd25ff05290 to your computer and use it in GitHub Desktop.
Delay the value of a signal for a specified period of time
-- Maybe this should use a `foldp`?
import Graphics.Element exposing (..)
import Mouse
import Time
debounce : Time.Time -> a -> Signal a -> Signal a
debounce after initialValue signal =
let
isUpdating = Time.since after signal
currentValue = Signal.map2 (,) signal isUpdating
extract (value, updating) =
case updating of
True -> Nothing
False -> Just value
in
Signal.filterMap extract initialValue currentValue
debouncePosition =
debounce (150 * Time.millisecond) (0,0) Mouse.position
main =
Signal.map show debouncePosition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment