Skip to content

Instantly share code, notes, and snippets.

@bfunc
Created August 3, 2019 08:37
Show Gist options
  • Save bfunc/320448ed235caf8703fd5391411d8a2e to your computer and use it in GitHub Desktop.
Save bfunc/320448ed235caf8703fd5391411d8a2e to your computer and use it in GitHub Desktop.
const lessThan = function(end, value) {
return function(value) {
return value < end;
};
}
// 25 alphabet character letters
const lessThan26 = lessThan(26);
const lazyMap = function* (iterable, callback) {
for (let value of iterable) {
yield callback.call(this, value);
}
};
const numberToAlphabet = function(value) {
//97 in ASCII is 'a'
//Our min value is 1
return String.fromCharCode(96 + value);
};
const numbers = [...randomNumberGenerator(10)];
console.log(numbers);
//[ 74, 16, 74, 24, 54, 96, 1, 71, 71, 77 ]
//Our chained generator object
let alphabebtCharIterator = lazyMap(filter(numbers), lessThan26), numberToAlphabet);
alphabetCharIterator.next();
//{ value: 'o', done: false }
alphabetCharIterator.next();
//{ value: 'w', done: false }
alphabetCharIterator.next();
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment