opvasger/enumerable

Enumerate custom-types in Elm!


License
BSD-3-Clause
Install
elm-package install opvasger/enumerable 1.0.0

Documentation

Elm Enumerable

This package is intended to reward you with some functions, should you decide to implement an enumeration over the values of a given type.

Custom types have limited semantics in Elm. You can't, for example, get a list of each value without implementing it yourself.

module Example exposing (N, everyN)

import Enumerable exposing (Enumerable)

type N = One | Two | Three

-- [ One, Two, Three ]
everyN : List N
everyN = Enumerable.toList enumerable One

-- this one forms a loop using a pattern-match, which is usually what you want.
enumerable : Enumerable N
enumerable n =
    case n of
        One ->   Two
        Two ->   Three
        Three -> One