Created
October 31, 2015 20:28
-
-
Save artisonian/2193dff11dd25ff05290 to your computer and use it in GitHub Desktop.
Delay the value of a signal for a specified period of time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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