Unit conversion exercise from the elm guide

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.
Thank you.

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

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.