This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
Monadic interface for commands and The Elm Architecture
version 1.2.1
license MIT
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 1.2.1
Committed At 2017-12-10 16:27:07 UTC
elm-lang/virtual-dom 2.0.4 <= v < 3.0.0 2.0.4
elm-lang/html 2.0.0 <= v < 3.0.0 2.0.0
elm-lang/core 5.1.1 <= v < 6.0.0 5.1.1

README

Elm-IO

Documentation

This projects provide pure Elm tools whose aim is to make programming in Elm more composable.

Currently it offers two monadic interfaces for Elm commands and The Elm Architecture. I'm completely aware that this goes against the Elm architecture philosphy but in practice it helps.

The CmdM monad

The CmdM monad is the command type (Cmd) turned into a monad. It enables to chain effects easily using classic monadic operations without having to encode complex scheduling in the update function.

The IO monad

The IO monad is CmdM augmented with state altering effect. Thus command effects and model modifictions can be mixed easily. Furthermore the view and subscritptions can not only emmit messages but also IOs.

IO is certainly the most terrible offense to the Elm architecture. But sometimes (often?) it is cleaner and simpler to send as message an IO than polluting the model or encode complex scheduling logic in the message type while turning the update function into complex interpreter.

Example

Here is a complete example of a simple page showing a counter

module Hello exposing (..)

import Html exposing (..)
import Html.Events exposing(..)
import IO exposing (..)

type alias Model  = Int 
type alias Msg = ()

increment : IO Model Msg
increment = IO.modify ((+) 1)

reset : IO Model Msg
reset = IO.set 0

view : Model -> Html (IO Model Msg) 
view m = 
  div [] [
    h1 [] [
      text "Example of an IO program"
    ],
    p [] [
      text ("Counter = " ++ (toString m))
    ],
    button [onClick increment] [
      text "increment"
    ],
    button [onClick reset] [
      text "reset"
    ]
  ]

main : IO.Program Never Model Msg 
main =
  IO.beginnerVDomProgram { init = 0, view = view , subscriptions = IO.dummySub }