You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It works very similar to the styled-components. Each interpolation can act as a function that receives the data, for example:
R.template`${data=> ...} some text ${data=> ...}`(data)
// if interpolation value isn't a function, it is used as raw valueconstgreet="Hello"constyellGreet=RA.template`${greet}, ${R.toUpper}`yellGreet('Renato')// => "Hello, RENATO"constformatFullName=RA.template`${R.prop('firstName')}${R.prop('lastName')}`formatFullName({firstName: "Renato",lastName: "Ribeiro"})conststrong=RA.template`<strong>${R.identity}</strong>`strong('More bold than ever')// => "<strong>More bold than ever</strong>"
As the behavior of a tagged template literals is quite different from a common function, it would not be possible to curry it. But it works as well: RA.template`${...}`(data)
The same problem for partial application (I guess).
Signature?
?
If it sounds good, let me know. I'd love to be able to create my first pull request here.
The text was updated successfully, but these errors were encountered:
It's an interesting idea for sure. It allows the template literals to become lazy interpolation mechanism, retaining all the semtantics.
1. As the behavior of a tagged template literals is quite different from a common function, it would not be possible to curry it.
I think currying should also be possible. When the function gets called as a template literal tag, it can return function which configuration (currying) can be assumed from the arguments of original function call.
2. The same problem for partial application (I guess).
Same case as 1.)
3. Signature
I'll help with the signature. Shouldn't be that big of a deal.
Name of the function
I'm not sure the RA.template is appropriate. I'd image template function to provide some mechanism similar to _.template. This is more about making template strings functional. What do you think ? During writing this comment I wasn't able to come up with better name ;]
Go ahead and create a prototype PR so that we can experiment with the concept.
This is just a suggestion. If it sounds good, let me know. I'd love to be able to create my first pull request here.
The case
I see that composing a string from my data is something that is not very simple yet, despite having quite a few common cases.
This works fine for the case in question, although it is verbose, but it's not very flexible in case I want to build a more complex string.
RA.template
I see there's room for an elegant solution using Tagged Template Literals so we can do things like this:
It works very similar to the styled-components. Each interpolation can act as a function that receives the data, for example:
A dirty implementation (demo purpose) can be seen here.
The problems
RA.template`${...}`(data)
The text was updated successfully, but these errors were encountered: