💾*sequence()
JS ⟩ objects ⟩ built-in ⟩ Generator ⟩ generator function ⟩ compostion ⟩ *sequence()
yield the values of iterables sequentially.
yield* operator - can only be used within generator functions❗️
yield and yield* operator can only be used within generator functions❗️
replit:sequence(...iterables)
// ⭐ sequence()
// yield the values of iterables sequentially
function* sequence(...iterables) {
for (const iterable of iterables) {
yield* iterable;
}
}
// export
module.exports = sequence;💈範例:
require: Iterator, *integers()
// ⭐ import
const Iterator = require('./Iterator.js'); // extend iterators
const integers = require('./integers.js'); // integers()
const sequence = require('./sequence.js'); // sequence()
// --------------------------------------------------------------
sequence( // iterables:
integers().take(5), // • 0 , 1 , 2, 3, 4
"ab", // • 'a', 'b'
[0] // • 0
).toArray()
// [ 0, 1, 2, 3, 4, 'a', 'b', 0]*interleave() interleaves the values instead.
Last updated
Was this helpful?