A previous version of the `andThen` documentation actually used circles and 
rectangles as the motivating example. It's since switched to versioned 
objects, which are maybe a little more realistic. Did you choose circles 
and rectangles as your example here for that reason, or are you really 
working with shapes? (I also wrote a blog post about `andThen` 
<https://www.brianthicks.com/post/2016/06/17/how-does-json-decode-andthen-work/>
 
that explains that example, but beware the 0.17 syntax.)

If you don't have any reason to separate your `Circle` and `Rectangle` 
types, you might also consider defining them in `Shape` directly. That way 
`CircleAsShape` would become `Circle`.

On Wednesday, December 21, 2016 at 7:53:56 AM UTC-6, Rupert Smith wrote:
>
> On Wednesday, December 21, 2016 at 1:18:52 PM UTC, Peter Damoc wrote:   
>>
>> shapeDecoder = 
>>   field "@type" string
>>     |> andThen toShape
>>
>> toShape str =
>>   case str of
>>     "Circle" -> 
>>       map CircleAsShape circleDecoder
>>     "Rectangle" -> 
>>       map RectangleAsShape rectangleDecoder
>>     _ -> 
>>       fail ("unknown shape: " ++ str) 
>>
>
> Thanks guys. :-) 
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to