I saw this mentioned in another channel but not di...
# language-proposals
b
I saw this mentioned in another channel but not discussed here-- Lambdas that disallow capture. Use
{{}}
instead of `{}`:
chain.map{{ input -> /* capture throws a compiler error */ }}
👍 3
🤔 3
e
What is your use-case for this feature?
b
My apologies. Use-case is to avoid leaks from lambdas, and minimize number of generated classes
d
If you want to explicitly avoid capturing, use a function reference that isn't bounded to any local variable
d
Would also be useful for Native? Instead of the whole
@VolatileLambda
thing.
b
we typically do use a function reference, but it isn’t as convenient as inlining a single-use lambda
e
Why this should be a language feature? Are you looking, maybe, for an IDE inspection/highlight that brings attention to captured values?
I mean, I don’t see how it adds to the language.
b
Yes-- it would enable IDE highlighting (errors in
{{}}
where there may be warnings in
{}
), lint rules, guaranteed compiler optimizations
l
I personally set my code scheme to underline with purple green dots captured values, so I'm always aware of that.
3
v
guaranteed compiler optimizations
That's already there
p
Proposed something similar in March - allowing lambdas to capture weakly as swift does with
[weak self]
(however from my private and not my work account)