Thanks Ian for your suggestions!
As for pulling the common code into another function, my threshold is probably
still the python one ;-)
But I finally adopted your solution with the helper function defined in a let
expression. That's already much better than my initial code!
let
formatTime time =
String.pad 2 '0' <| toString time
in
String.join ":" [formatTime (hour date), formatTime (minute date)]
Thanks,
Matthieu
1. You could try
http://package.elm-lang.org/packages/mgold/elm-date-format/1.1.4/ if you're not
opposed to using a third party package.
2. Or pull the duplicate code out into a function:
|
formatTime :Int->String
formatTime time =
String.pad 2'0'<|toString time
anddo
String.join ":"[formatTime (hour date),formatTime (minute date)]
|
That's still not quite as tidy as string interpolation but I've found it's a
good habit to get into to pull anything you do more than once out into its own
function, especially in Elm; in Python my threshold tends to be three uses :)
--
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.