Open brigand opened 10 years ago
What's interesting about this suggestion is that it's already sort of available. Consider this:
var names = [],
sequence = Lazy(names).map(function(name) {
var parts = name.split(' ');
return {
first: parts[0],
last: parts[1],
full: name
};
});
names.push("John Doe");
names.push("Ann Robljsakld");
sequence.toArray(); // you'll see it contains the output you suggested
Which demonstrates that a Lazy.Sequence
is not a "snapshot" but rather provides a view into an underlying data source.
I guess the missing piece would be an interface for specifying a sequence with no underlying source (i.e. without needing a reference to an empty array), or for "swapping out" one source for another. I'll think on this!
Cool :-)
I'm working on a project which needs this kind of functionality. It's a JSON transformation library, and users need a way to specify the transformations before data is available, and then apply it to multiple pieces of data.
On Tue, Dec 31, 2013 at 4:31 PM, Dan Tao notifications@github.com wrote:
What's interesting about this suggestion is that it's already sort of available. Consider this:
var names = [], sequence = Lazy(names).map(function(name) { var parts = name.split(' '); return { first: parts[0], last: parts[1], full: name }; }); names.push("John Doe");names.push("Ann Robljsakld"); sequence.toArray(); // you'll see it contains the output you suggested
Which demonstrates that a Lazy.Sequence is not a "snapshot" but rather provides a view into an underlying data source.
I guess the missing piece would be an interface for specifying a sequence with no underlying source (i.e. without needing a reference to an empty array), or for "swapping out" one source for another. I'll think on this!
— Reply to this email directly or view it on GitHubhttps://github.com/dtao/lazy.js/issues/61#issuecomment-31416113 .
It'd be great to be able to create pure functional behaviors, and then later apply them to values. A jsfiddle of the below.
Something along the lines of this:
The result would be:
Suggested implementation: