Started to follow the elm guide this weekend and got tripped up on the exercise in the partial functions section.
The exercise involves altering an existing °C to °F converter to highlight invalid inputs and adding more conversions. The text says to only alter the view code but I don’t know of a good way to accomplish this.
My solution is not pretty and I think I missed the point of the exercise.
Would be thankful for any pointers to get me started on solving it “as intended”.
I don’t know, at a glance the result seems pretty acceptable to me.
What is it you think is a problem?
I thought it was possible to solve altering only the
view function code.
Also since the exercise is in the “Maybe” and “Partial functions” section I thought that I have use those concepts, but that part stayed basically the same compared to the original version.
But since the result seems fine, I’ll just keep going.
I think the “only view code” is referencing where you are meant to do the conversion (which is what you did).
Keeping track of which unit the user wants to convert to does seem like a necessary thing to persist in the model.
I’d probably move each of the conversions out of the body of the HTML, which would help clean it up, and make it simpler to unit test.
Maybe something like:
convertTo : Unit -> Int -> String, and then you could partially apply the current unit over the function like:
Maybe.map (convertTo currentUnit) currentValue
|> Maybe.withDefault “”