Skip to content

Instantly share code, notes, and snippets.

@joefiorini
Created January 9, 2015 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joefiorini/7639ff48f25e5067c97d to your computer and use it in GitHub Desktop.
Save joefiorini/7639ff48f25e5067c97d to your computer and use it in GitHub Desktop.
Signal.toggle for Elm
import Signal
import Html
import Html (div, text, button)
import Html.Events (onClick)
toggle s1 s2 s =
Signal.foldp
(\prev curr ->
if prev == s1 then s2 else s1) s1 s
toggler = Signal.channel "blah"
main = Signal.map scene
<| toggle "blah" "diddy"
<| Signal.subscribe toggler
scene s =
Html.toElement 500 500
<| div
[]
[ text s
, button
[onClick <| Signal.send toggler s]
[text "Toggle That"]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment