Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upProposal: Array.prototype.feed #42
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ghost
May 30, 2015
Very cryptically written. As I understand you want something like in: in Pharo Smalltalk. AFAICT this construct is not Array-specific, it is useful in any object, if it would be added. What complicates it, is if result is null or undefined (which is not a problem in "everything is an object" Smalltalk). BTW what's wrong with plain
console.log([1,2,3].map(function(v){
return v+1;
}));except it is a bit awkward? In ES6, a more awkward
((_=[1,2,3].map(function(v){
return v+1;
})) => console.log(_))()is probably possible as well.
ghost
commented
May 30, 2015
|
Very cryptically written. As I understand you want something like console.log([1,2,3].map(function(v){
return v+1;
}));except it is a bit awkward? In ES6, a more awkward ((_=[1,2,3].map(function(v){
return v+1;
})) => console.log(_))()is probably possible as well. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Youmoo
May 31, 2015
@Herby Thank you , your description is more clear
Let everything in js have a feed method is all I want .
Youmoo
commented
May 31, 2015
|
@Herby Thank you , your description is more clear |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
michaelficarra
May 31, 2015
Member
// with the proposed Object.prototype.feed
[1,2,3].map(function(v){ return v + 1; }).feed(console.log.bind(console));
// or:
[1,2,3].map(_ => _ + 1).feed(_ => console.log(_));
// without it:
console.log([1,2,3].map(function(v){ return v + 1; }));
// or:
console.log([1,2,3].map(_ => _ + 1));I can't see any justification for this.
// with the proposed Object.prototype.feed
[1,2,3].map(function(v){ return v + 1; }).feed(console.log.bind(console));
// or:
[1,2,3].map(_ => _ + 1).feed(_ => console.log(_));
// without it:
console.log([1,2,3].map(function(v){ return v + 1; }));
// or:
console.log([1,2,3].map(_ => _ + 1));I can't see any justification for this. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Youmoo
May 31, 2015
@michaelficarra It will make a more fluent and chain-able (like jQuery method chaining) programming experience.
Youmoo
commented
May 31, 2015
|
@michaelficarra It will make a more fluent and chain-able (like jQuery method chaining) programming experience. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
michaelficarra
May 31, 2015
Member
@Youmoo Libraries like underscore do this without extending Object.prototype:
_([1,2,3]).map(_ => _ + 1).feed(_ => console.log(_)).done();|
@Youmoo Libraries like underscore do this without extending _([1,2,3]).map(_ => _ + 1).feed(_ => console.log(_)).done(); |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bterlson
Sep 22, 2015
Member
Closing this now. Proposals should have an identified champion and repository set up where work happens. This is not the place to brainstorm about proposals.
|
Closing this now. Proposals should have an identified champion and repository set up where work happens. This is not the place to brainstorm about proposals. |
Youmoo commentedMay 30, 2015
Array has some methods which supports functional coding ,such as map,reduce..
Say I wanna do some transforming with an array and log the result :
It'll be better if we can log the result without declaring variable result
First I think about this:
But this is aginst the purpose of
some.I need something like this:
In practice, we often need map / filter / reduce arrays and deal with the result. So it'will be a pleasure if array has a feed method (more than a pleasure if Object.prototype also has that:) to support more functional programming
Sorry for my poor English, Hope I can be understood:)