Created
August 31, 2015 18:32
-
-
Save dela3499/8f8e329c93a54dc3e7b8 to your computer and use it in GitHub Desktop.
Implementation of swipe gestures in Elm
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
import Graphics.Element exposing (show, Element) | |
import Touch exposing (Touch) | |
import Signal | |
import Set | |
type alias Swipe = Touch | |
touches': Signal (List Touch, List Touch) | |
touches' = | |
Signal.foldp | |
(\touches (a, _) -> (touches, a)) | |
([], []) | |
Touch.touches | |
getSwipes: (List Touch, List Touch) -> List Swipe | |
getSwipes (newTouches, oldTouches) = | |
let getIds touches = | |
List.map | |
(\touch -> touch.id) | |
touches | |
|> Set.fromList | |
swipeIds = | |
Set.diff | |
(getIds oldTouches) | |
(getIds newTouches) | |
|> Set.toList | |
in | |
List.filter | |
(\touch -> List.member touch.id swipeIds) | |
oldTouches | |
swipes: Signal (List Swipe) | |
swipes = Signal.map getSwipes touches' | |
main: Signal Element | |
main = Signal.map show swipes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment