3 ms·
With Trine this would be function process () { return this ::filter(isOk) ::map(toOtherType) ::flatten(); } and then lat
by quinnirill 11y ago
With Trine this would be
function process () {
return this
::filter(isOk)
::map(toOtherType)
::flatten();
}
and then later:
groupsOfItems::map(process);
Granted, the `flatten` function is not in the Trine yet, somehow forgot that from the initial release.
- CrossEye 11y agoOk, that helps make it a bit more palatable to me. Thanks for the information. One question, though: How do user functions interact in here? If you didn't include `flatten`, but I had my own version of it, would it be straightforward for me to build `process` using my own `flatten`? Do I have to modify some Trine objects, or can I use some simple function references? Obviously I haven't yet actually dug into the Trine code. Perhaps this weekend.
- quinnirill 11y agoHappy to help! Yes, you can use just simple function references, e.g. you could just define flatten as so function * flatten () { for ( const item of this ) { yield * item; } } And it would work just like it was part of Trine - in fact that's probably how it's going to be implemented in Trine. The chaining is not a feature of Trine, but the function bind syntax proposal ( https://github.com/zenparsing/es-function-bind https://github.com/zenparsing/es-function-bind ), Trine has merely been designed to work well with this syntax.