Closed gavinking closed 9 years ago
+1
Indeed +1
I can already do this in Ceylon:
value list = ["1","2","3"];
list.each(print);
I'm guessing this proposal applies to more complex anonymous void functions?
@lukedegruchy pretty sure that's the case yes
@lukedegruchy your example is a function reference. I'm taking about anonymous functions, particularly multi-line anon functions.
So, in other words, you want to do this:
list.each((x) {
y = x + x;
print(y);
});
But need to do this instead:
list.each(void (String x) {
value y = x + x;
print(y);
});
This is done, but I need to document it in the spec.
Done.
OK, I've found one minor issue here that I'm not sure what to make of. This anonymous function:
() { throw; }
Used to be assigned the type Nothing
, but now it's assigned the type Anything
. I'm not sure that's a good thing,
I think this is all good. Closing.
Currently we let you drop the
function
keyword for anonymous functions that return a value, but we don't let you dropvoid
for anonymous functions which don't return anything. It seems to me that this is too heavy-handed, and isn't very friendly for use with methods likeIterable.each()
. I don't see why we couldn't relax this, letting you write: