[elm-discuss] Re: Elm's compiler is trying to import a module that doesn't exist...?

2017-03-13 Thread Dan Willis
FYI, this totally fixes it.

On Thursday, 12 January 2017 09:57:51 UTC+13, Frederick Yankowski wrote:
>
> I've seen that error when `elm-lang/core` is missing from the dependencies 
> in elm-package.json.
>
> Try `elm package install elm-lang/core`.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Decoding JSON to Union types.

2017-03-01 Thread Dan Willis
Thanks so much, Peter & Brian,

I had earlier found your article re: dates, but revisiting it now has 
helped!
Yep, I like the idea of keeping that function as agnostic as possible, 
i.e., out of a Decoder.

Thanks again for your help, I really appreciate it.




On Thursday, 2 March 2017 03:40:12 UTC+13, Brian Hicks wrote:
>
> Seconding what Peter said! I think the approach you've got here (String -> 
> OrderStatus) is good. If you don't specialize it to a decoder you can do a 
> lot more with it (testing, other serialization methods.) Composing those 
> functions together is the way to go.
>
> I've also written about this, but in the context of dates: 
> https://www.brianthicks.com/post/2017/01/13/create-custom-json-decoders-in-elm-018/
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Decoding JSON to Union types.

2017-02-28 Thread Dan Willis
I'm new to Elm (I'm <2 weeks in) but am really loving it.

However, I'm finding it difficult to determine just how to successfully 
decode a JSON object into my model, what with changes between versions, and 
the number of related non-core packages.

Here's an example of the JSON data:

[
{ 
"id" : 1,
"day" : "today",
"time" : 12,
"product" : "ProductType",
"location" : "locationOne",
"quantity" : 25,
"status" : "Draft"
},
{ 
"id" : 2,
"day" : "tomorrow",
"time" : 15,
"product" : "ProductType",
"location" : "locationTwo",
"quantity" : 15,
"status" : "Cancelled"
},
...
]


...and here are my Elm type descriptions:

type OrderStatus
= Draft
| Ordered
| Inbound
| Delivered
| Cancelled


type alias Order =
{ id : Int
, day : String
, time : Int
, product : Product
, location : String
, quantity : Int
, status : OrderStatus
}

Focussing specifically on Order and OrderStatus, I've got something along 
the lines of this, so far:

orderListDecoder : Decoder (List Order)
orderListDecoder =
list orderDecoder


orderDecoder : Decoder Order
orderDecoder =
map7 Order
("id" field int)
("day" field string)
("time" field int)
("product" field productDecode)
("location" field string)
("quantity" field int)
("status" field orderStatusDecoder)


orderStatusDecoder : Decoder OrderStatus
orderStatusDecoder =
string |> andThen fromStringOrderStatus


fromStringOrderStatus : String -> Result String OrderStatus
fromStringOrderStatus string =
case string of
"Draft" ->
Ok Draft

"Ordered" ->
Ok Ordered

"Inbound" ->
Ok Inbound

"Delivered" ->
Ok Delivered

"Cancelled" ->
Ok Cancelled

other ->
Err ("Invalid OrderStatus: " ++ string)




So specifically, I can't figure out how to decode the 'status' JSON string 
into an OrderStatus type.


I'm sure there's a simple solution, but I'm getting confused with the many 
pre-0.18 examples of decoding, and the various extra packages available.


-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.