Proposal: Downward Assignments
bugs.ruby-lang.org
bugs.ruby-lang.org
df = someFunctionThatReturnsADataFrame()
newDf = someFunctionThatTakesAndReturnsADataFrame(df)
doSomethingTo(df)
Since R lets you define your own operators, they took '%>%' and defined it as "pipe the return value from one function as the first argument to another function," so you can do this: someFunctionThatReturnsADataFrame() %>%
someFunctionThatTakesAndReturnsADataFrame() %>%
doSomethingTo()
No need to name either the temporaries or the function arguments.10 + 10 puts _ # prints 20
but that isn't available in ruby itself
There are several things that involve unnamed, shortlived plumbing vars; as well as various languages pipeline notations, therr is also this in scala lambdas:
xs.map(x => x + 1)
can be written as: xs.map(_ + 1)
and even: (xs, ys).zipped.map((x,y)=>x+y)
as: (xs, ys).zipped.map(_ + _)- partial application notation with numbered arguments
- pattern matching
- anaphoric if and related notations
- point-free form (no names at all)
instead of:
p(2 * 3 * 7) #=> 42
^^^^^var
Having: p(var1:[2*3] * var2: 7) => 42
p(var1) => 6
p(var2) => 7
The other requires ugly whitespacing. >>> print((v1 := 2 * 3) * (v2 := 7))
42
>>> print(v1)
6
>>> print(v2)
7
edit: formattingElixir's pipe is the same thing, though Clojure has a few extra forms to facilitate other variable passing patterns.
F(condition1,
Condition2)
Is worse than
F(
Condition1,
Condition2
)The problem isn't tabs or spaces, it's trying to align to the length of the function name instead of adding a new line