Using transducers
As we discussed in previous sections, transducers are a way to compose algorithmic transformations over iterable objects; to see this in action, let's first use a transducer in the most simple iterable object, an array.
To run a transducer over an array we first need a method to run a given transformation in a given iterable object.
For this we use the into()
method, which has the following signature:
transducers.into(emptyIterable,transformation,iterable)
It receives three parameters and they are all mandatory:
emptyIterable
: It is an empty iterable used to store the result of the application of the transformation over the iterable objecttransformation
: It is the function or transducers to be applied over theiterable
objectiterable
: It is theiterable
object to be transformed
With the usage of this function we can implement transformations over an array, let's see how we can implement a simple map with it:
var t = require('transducers-js'); var iterableObject = [1,2,3,4]...