Skip to content

Instantly share code, notes, and snippets.

@mgold
Last active February 12, 2016 01:34
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mgold/f3527359996fdf295843 to your computer and use it in GitHub Desktop.
Save mgold/f3527359996fdf295843 to your computer and use it in GitHub Desktop.
Elm mailbox revamp
-- a distilation of https://github.com/elm-lang/elm-plans/issues/7
{- Mailbox is renamed Dispatcher, although this name is the part I'm least certain about.
The address field is replaced with a dispatch field.
It's minor, but I've found it helpful to put dispatch second, since the signal is easier to explain.
-}
type alias Dispatcher a =
{ signal : Signal a
, dispatch : a -> Message -- the big change
}
{- same as the old mailbox function, just renamed -}
dispatcher : a -> Dispatcher a
{- remains opaque as before -}
type Message = ...
{- Rather than taking an Address and a value, now takes a Message
The x can be replaced by Never if we add that. -}
send : Message -> Task x ()
{- Dropped from the API: the Address type, the message function, and the forwardTo function.
Html.Events will need to be changed to look more like Svg.Events,
taking (a function that creates) a message, rather than an address and a value. -}
@rtfeldman
Copy link

This seems excellent!

@michaelsbradleyjr
Copy link

As someone who has only recently been studying Elm in a serious way, I find this really helpful, as forwardTo was quite confusing to me, and I have been doing functional(-like) programming with JavaScript and Clojure for more than a couple of years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment