Skip to content

Instantly share code, notes, and snippets.

@toretore
Created October 17, 2017 12:50
Show Gist options
  • Save toretore/54606e935753cc34011c755161445785 to your computer and use it in GitHub Desktop.
Save toretore/54606e935753cc34011c755161445785 to your computer and use it in GitHub Desktop.
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