Result has its own withDefault function. You do not need to convert the
Result to a Maybe.

On Tue, May 24, 2016 at 9:15 AM, Thomas Coopman <[email protected]>
wrote:

> I do not completely agree that the solution is not so nice.
> The app can return an invalid string and here you are enforced to do
> something with it explicitly.
>
> You do have to check if this implementation is acceptable for you, because
> now, when the user enters an invalid string, you will change his text to 0.
> So if the user types 123a, you will revert his input to 0. It's probably
> better to keep his input and put a parsed Int in the model too.
>
>
> On Tue, 24 May 2016 at 17:43 Herwig Habenbacher <
> [email protected]> wrote:
>
>> Thanks!
>>
>> The Solution just don't look that nice ;-)
>>
>> update : Msg -> Applications -> Applications
>>>>
>>>> update action model =
>>>>
>>>>   case action of
>>>>
>>>>     AID app ->
>>>>
>>>>       { model | appID = String.toInt app |> Result.toMaybe |>
>>>>> Maybe.withDefault 0 }
>>>>
>>>>
>>>>>     Name nname ->
>>>>
>>>>       { model | name = nname }
>>>>
>>>>
>>>>>     ClientID cid ->
>>>>
>>>>       { model | clientID = cid }
>>>>
>>>>
>>>> --
>> 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.
>>
> --
> 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.
>

-- 
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