I would add a deps for this :D it's just in my test-deps, besides it might be useful in the rest of your app. I mean in the front-end we often have to show text with some values that we fetch from different places: using an utility or making your own to get that type of code:
"List too short by {} element{}"|>interpolate[String.fromInt(n+1),pluralize(n+1)"""s"]
furthermore, I'd actually make a interpolate function that takes a list of a custom type:
1st define a type like this:
type InterpolationValue a
= IntValue Int
| StringValue String
| CurrencyValue Float
| ...
| CustomValue (a -> String) a
this way my interpolate function would look like this:
To be clear, I really meant that in this project that I'm working on I won't add a dependency for it. Since this particular function, nthElement, is quite insignificant.
However, I do agree that if I'm working on a project where I am doing a lot of this sort of stuff then abstracting the task will have its benefits.
I would add a deps for this :D it's just in my test-deps, besides it might be useful in the rest of your app. I mean in the front-end we often have to show text with some values that we fetch from different places: using an utility or making your own to get that type of code:
furthermore, I'd actually make a
interpolate
function that takes a list of a custom type:1st define a type like this:
this way my interpolate function would look like this:
then I think my code would be much easier to read and also potentially much easier to i18nize it later on :)
But that's again just a matter of personal taste!
To be clear, I really meant that in this project that I'm working on I won't add a dependency for it. Since this particular function, nthElement, is quite insignificant.
However, I do agree that if I'm working on a project where I am doing a lot of this sort of stuff then abstracting the task will have its benefits.
This discussion reminds me of Formatting in Haskell. Which I first came across in "Related Work" in url's README.
Sorry I didn't mean to come across aggressive or arogant :)
the formatting article is an interesting read! thanks for the link.
I didn't think so at all. But, no worries. Thanks for sharing your thoughts. I appreciated it.
Cheers mate.
Keep up writing, your posts are cool!