Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
module Customers exposing (Error, Customers, init, toLoading, toFailure, toSuccess)
type alias Error = String
type Customers
= NotAsked
| Loading (Maybe Error) (Maybe (List Customer))
| Failure Error (Maybe (List Customer))
| Success (List Customer)
init : Customers
init = NotAsked
toLoading : Customers -> Customers
toLoading current =
case current of
NotAsked -> Loading Nothing Nothing
Loading me ml -> Loading me ml
Failure e ml -> Loading (Just e) ml
Success l -> Loading Nothing (Just l)
toFailure : Error -> Customers -> Customers
toFailure error current =
case current of
NotAsked -> Failure error Nothing
Loading _ ml -> Failure error ml
Failure _ ml -> Failure error ml
Success l -> Failure error (Just l)
toSuccess : LIst Customer -> Customers -> Customers
toSuccess list current =
Success list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment