Guest User

Untitled

a guest
Dec 11th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1.  
  2. where = (list,func) -> item for item in list when (func.call _ :item) select = (list, prefix,postfix) -> "#{prefix}#{item}#{postfix}" for item in list
  3. getnums = (x) -> [1..x]
  4.  
  5.  
  6. # is there any easier way i can write the following below
  7. results = select( (where (getnums 10) ,-> @_ > 5) , "pre","post" )
  8.  
  9.  
  10. alert res for res in results
  11.  
  12.  
  13. ###
  14. what it really would like to do is beable, whether using | or say |> for a pipe do
  15. getnum | where -> @_ > 5 | select "pre","post"
  16.  
  17.  
  18. 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..
  19.  
  20.  
  21. with my own pipe i can do something like
  22. pipe getnum .to where, -> @_ > 5 .to select , "pre","post"
  23.  
  24.  
  25. kaffiene though not complete lets me do this with
  26.  
  27.  
  28. getnums = { [1,2,3,4,5,6,7,8,9,10] }select = (list,prefix,postfix) {
  29. res = []
  30. for x of list {
  31. res.push("#{prefix}#{x}#{postfix}")
  32. }
  33. return res
  34. }
  35.  
  36.  
  37. getnums | select "pre","post"
  38.  
  39.  
  40.  
  41. generates the following javascript
  42.  
  43.  
  44. var getnums, select; getnums = function() { return [1,2,3,4,5,6,7,8,9,10] }select = function(list,prefix,postfix) {
  45. var _a, x, res; res = []
  46. for(_a = 0; _a < list.length; _a++) { x = list[_a];
  47. res.push("" + (prefix) + (x) + "" + (postfix) + "")
  48. }
  49. return res
  50. }
  51.  
  52.  
  53. __.select.call(this, getnums, "pre","post")
  54.  
  55.  
  56.  
  57. and
  58. getnums | select "pre","post" | select "yo","dude"
  59.  
  60.  
  61. __.select.call(this, __.select.call(this, getnums, "pre","post"), "yo","dude")
  62. ###
Add Comment
Please, Sign In to add comment