Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- where = (list,func) -> item for item in list when (func.call _ :item) select = (list, prefix,postfix) -> "#{prefix}#{item}#{postfix}" for item in list
- getnums = (x) -> [1..x]
- # is there any easier way i can write the following below
- results = select( (where (getnums 10) ,-> @_ > 5) , "pre","post" )
- alert res for res in results
- ###
- what it really would like to do is beable, whether using | or say |> for a pipe do
- getnum | where -> @_ > 5 | select "pre","post"
- basically the pipe takes the output of the previous command and puts it as teh first argument, and then takes any other arguments after that (so 1st argument becomes 2nd, and second becomes third..
- with my own pipe i can do something like
- pipe getnum .to where, -> @_ > 5 .to select , "pre","post"
- kaffiene though not complete lets me do this with
- getnums = { [1,2,3,4,5,6,7,8,9,10] }select = (list,prefix,postfix) {
- res = []
- for x of list {
- res.push("#{prefix}#{x}#{postfix}")
- }
- return res
- }
- getnums | select "pre","post"
- generates the following javascript
- var getnums, select; getnums = function() { return [1,2,3,4,5,6,7,8,9,10] }select = function(list,prefix,postfix) {
- var _a, x, res; res = []
- for(_a = 0; _a < list.length; _a++) { x = list[_a];
- res.push("" + (prefix) + (x) + "" + (postfix) + "")
- }
- return res
- }
- __.select.call(this, getnums, "pre","post")
- and
- getnums | select "pre","post" | select "yo","dude"
- __.select.call(this, __.select.call(this, getnums, "pre","post"), "yo","dude")
- ###
Add Comment
Please, Sign In to add comment