-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(iterables): iterables are non-stateful
BREAKING CHANGE: iterables were stateful and one could only iterate over them once, refferential transparency could not be guaranteed and extra care had to be taken, caching their items using `[...iterable]`. Now iterables are not stateful anymore and can be reused and iterated over multiple times.
- Loading branch information
Showing
13 changed files
with
636 additions
and
591 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,120 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`filter async compiles 1`] = ` | ||
"(async function* filter(ˆitems_2) { | ||
for await (const ˆitem_1 of ˆitems_2) { | ||
const item = ˆitem_1; | ||
const ˆresult_3 = (await item) % 2 === 0; | ||
if (ˆresult_3) yield ˆitem_1; | ||
} | ||
"(function filter(ˆitems_2) { | ||
return { | ||
async *[Symbol.asyncIterator]() { | ||
for await (const ˆitem_1 of ˆitems_2) { | ||
const item = ˆitem_1; | ||
const ˆresult_3 = (await item) % 2 === 0; | ||
if (ˆresult_3) yield ˆitem_1; | ||
} | ||
} | ||
}; | ||
});" | ||
`; | ||
|
||
exports[`filter compiles 1`] = ` | ||
"(function* filter(ˆitems_2) { | ||
for (const ˆitem_1 of ˆitems_2) { | ||
const item = ˆitem_1; | ||
const ˆresult_3 = item % 2 === 0; | ||
if (ˆresult_3) yield ˆitem_1; | ||
} | ||
"(function filter(ˆitems_2) { | ||
return { | ||
*[Symbol.iterator]() { | ||
for (const ˆitem_1 of ˆitems_2) { | ||
const item = ˆitem_1; | ||
const ˆresult_3 = item % 2 === 0; | ||
if (ˆresult_3) yield ˆitem_1; | ||
} | ||
} | ||
}; | ||
}); | ||
(function* filter(ˆitems_5) { | ||
for (const ˆitem_4 of ˆitems_5) { | ||
const [a, ...b] = ˆitem_4; | ||
const a_alone = a(andis_empty(b)); | ||
const ˆresult_6 = a_alone; | ||
if (ˆresult_6) yield ˆitem_4; | ||
} | ||
(function filter(ˆitems_5) { | ||
return { | ||
*[Symbol.iterator]() { | ||
for (const ˆitem_4 of ˆitems_5) { | ||
const [a, ...b] = ˆitem_4; | ||
const a_alone = a(andis_empty(b)); | ||
const ˆresult_6 = a_alone; | ||
if (ˆresult_6) yield ˆitem_4; | ||
} | ||
} | ||
}; | ||
}); | ||
(function* filter(ˆitems_9) { | ||
for (const ˆitem_7 of ˆitems_9) { | ||
let _do_result; | ||
(function filter(ˆitems_9) { | ||
return { | ||
*[Symbol.iterator]() { | ||
for (const ˆitem_7 of ˆitems_9) { | ||
let _do_result; | ||
{ | ||
const [...ˆitems_8] = ˆitem_7; | ||
_do_result = [ˆitems_8.slice(0, -1), ˆitems_8.slice(-1)]; | ||
{ | ||
const [...ˆitems_8] = ˆitem_7; | ||
_do_result = [ˆitems_8.slice(0, -1), ˆitems_8.slice(-1)]; | ||
} | ||
const [a, [b]] = _do_result; | ||
_do_result = undefined; | ||
const ˆresult_10 = b && is_empty(a); | ||
if (ˆresult_10) yield ˆitem_7; | ||
} | ||
} | ||
const [a, [b]] = _do_result; | ||
_do_result = undefined; | ||
const ˆresult_10 = b && is_empty(a); | ||
if (ˆresult_10) yield ˆitem_7; | ||
} | ||
}; | ||
});" | ||
`; | ||
|
||
exports[`filter compiles with accu 1`] = ` | ||
"(function* filter(ˆitems_3) { | ||
let ˆaccu_2 = 0; | ||
for (const ˆitem_1 of ˆitems_3) { | ||
const item = ˆitem_1; | ||
const cntr = ˆaccu_2; | ||
const ˆresult_4 = item < 1 && cntr % 2 === 0; | ||
if (ˆresult_4) yield ˆitem_1; | ||
ˆaccu_2 = cntr + 1; | ||
} | ||
"(function filter(ˆitems_3) { | ||
return { | ||
*[Symbol.iterator]() { | ||
let ˆaccu_2 = 0; | ||
for (const ˆitem_1 of ˆitems_3) { | ||
const item = ˆitem_1; | ||
const cntr = ˆaccu_2; | ||
const ˆresult_4 = item < 1 && cntr % 2 === 0; | ||
if (ˆresult_4) yield ˆitem_1; | ||
ˆaccu_2 = cntr + 1; | ||
} | ||
} | ||
}; | ||
});" | ||
`; | ||
|
||
exports[`filter compiles with accu 2`] = ` | ||
"(function* filter(ˆitems_3) { | ||
let ˆaccu_2 = false; | ||
for (const ˆitem_1 of ˆitems_3) { | ||
const is_even = ˆaccu_2; | ||
const ˆresult_4 = is_even; | ||
if (ˆresult_4) yield ˆitem_1; | ||
ˆaccu_2 = !is_even; | ||
} | ||
"(function filter(ˆitems_3) { | ||
return { | ||
*[Symbol.iterator]() { | ||
let ˆaccu_2 = false; | ||
for (const ˆitem_1 of ˆitems_3) { | ||
const is_even = ˆaccu_2; | ||
const ˆresult_4 = is_even; | ||
if (ˆresult_4) yield ˆitem_1; | ||
ˆaccu_2 = !is_even; | ||
} | ||
} | ||
}; | ||
});" | ||
`; | ||
|
||
exports[`filter compiles with accu 3`] = ` | ||
"(function* filter(ˆitems_3) { | ||
let ˆaccu_2 = false; | ||
for (const ˆitem_1 of ˆitems_3) { | ||
const is_even = ˆaccu_2; | ||
const ˆresult_4 = is_even; | ||
if (ˆresult_4) yield ˆitem_1; | ||
ˆaccu_2 = !is_even; | ||
} | ||
"(function filter(ˆitems_3) { | ||
return { | ||
*[Symbol.iterator]() { | ||
let ˆaccu_2 = false; | ||
for (const ˆitem_1 of ˆitems_3) { | ||
const is_even = ˆaccu_2; | ||
const ˆresult_4 = is_even; | ||
if (ˆresult_4) yield ˆitem_1; | ||
ˆaccu_2 = !is_even; | ||
} | ||
} | ||
}; | ||
});" | ||
`; |
Oops, something went wrong.