Skip to content

Instantly share code, notes, and snippets.

@evancz
Created February 11, 2014 11:24
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 evancz/8933129 to your computer and use it in GitHub Desktop.
Save evancz/8933129 to your computer and use it in GitHub Desktop.
module Animal where
data Either a b = Left a | Right b
-- Left 42 <=> { "tag":"Left", "contents":[42] }
-- Right "cat" <=> { "tag":"Right", "contents":["cat"] }
port animal : Signal (Either Int String)
port animal = always (Right "cat") <~ every second
var animal = Elm.worker(Elm.Animal);
animal.ports.animal.subscribe(function(either) {
switch (either.tag) {
case "Left":
errorCode = either.contents[0];
break;
case "Right":
animal = either.contents[0];
break;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment