Skip to content

Instantly share code, notes, and snippets.

@dela3499
Created August 31, 2015 18:32
Show Gist options
  • Save dela3499/8f8e329c93a54dc3e7b8 to your computer and use it in GitHub Desktop.
Save dela3499/8f8e329c93a54dc3e7b8 to your computer and use it in GitHub Desktop.
Implementation of swipe gestures in Elm
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