September 2017
Intermediate to advanced
216 pages
6h 8m
English
Let's see how lazy evaluation works with more than one sequence operation. To do so, let's first implement a function to compose filter predicates, as follows:
const equals = first => (second) => { console.log(`${first} === ${second}`); return first === second;};
Now we have an easy way to build a simple predicate that logs what we're comparing and then returns the result of the actual comparison. Let's put equals() to use by chaining together several filters:
myList .toSeq() .filterNot(equals(1)) .filterNot(equals(3)) .filterNot(equals(5)) .forEach(item => console.log('myList', item)); // -> 1 === 1 // -> 1 === 2 // -> 3 === 2 // -> 5 === 2 // -> myList 2 // -> 1 === 3 // -> 3 === 3 // -> 1 === 4 // -> 3 === 4 // -> ...Read now
Unlock full access