Comments (3)
Interesting! Sequences are evaluated lazily, which seems to be involved.
If you resolve the map sequence first via toList it prints twice only, since the where is only on the list
var bar = [1, 2].map{|x| Foo.new(x) }.toList.where{|x| x.num > 0}.toList
from wren.
from wren.
I thought this was surprising too - as mhermier says it is because of the way WhereSequence
calls iteratorValue
on its 'upstream' sequence (at least) once to find a value that satisfies the filter and once to actually get the value (see below). Specifically iteratorValue
calls back though the chain every time, in this case calling the map function on the way to the source list [1,2]
If you have two where clauses then it prints 'Creating foo' six times
var bar = [1, 2].
map{|x| Foo.new(x) }.
where{|x| x.num > 0}.
where{|x| x.num < 10}.
toList
An option would be to have WhereSequence
's iterator memoise the last result but assuming you don't want to change the code, would it be possible to make this a bit clearer in the iterator protocol docs?
Thanks!
Lines 168 to 182 in c2a75f1
from wren.
Related Issues (20)
- [RFC] Object.responds(_) method HOT 10
- [RFC] Add routines for degrees/radians conversions HOT 21
- [RFC] Adding a `Tuple` with language support HOT 11
- [RFC] Adding `const` versions of `Object`s. HOT 9
- Class reflection for embedding HOT 3
- [RFC] `veery` lang transpiler to `wren` lang HOT 3
- [RFC] Object method message passing syntax HOT 28
- [RFC] Add `static Object.typeOf(_)` (and deprecate `Object.type` ?) HOT 9
- How can i stop wren script running? HOT 3
- Calling wren method handle from inside a bound foreign method body HOT 5
- Whitespace bugs? HOT 4
- Serialize (suspended) fibers or serialize the vm HOT 4
- wren_debug.c should use vm->config.writeFn instead of printf HOT 1
- Should we document this aspect of for loop control variable behavior?
- How do I pass a foreign object to a function call? HOT 3
- is Wren dead? HOT 2
- How to return other foreign class obj from a foreign class ? HOT 7
- wrenCall -> foreign call causes memory corruption HOT 11
- Compound Assignments HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wren.