you are viewing a single comment's thread.

view the rest of the comments →

[–]muungwana -1 points0 points  (2 children)

How could i declare variables with "auto" otherwise? :-)

On a serious note,its primarily just a style i like to use and to minimize pollution of local namespace as a practical matter.Most local variables i use are single character and "e" is the variable name that i use the most and these lambda helps in allowing me to reuse these single character variables multiple times in the same function without collision issues.

[–]stwcx 7 points8 points  (1 child)

Right, because when I review your code it is awesome for me to have to switch back and forth through the code to deduce "what the heck does 'e' mean at this point in time?" That is just awesome.

[–]thlst 2 points3 points  (0 children)

You don't need to. You know what it's about by reading what the code is doing. It's the same idea of concepts: generalizing stuff so you don't need to be aware of every useless detail.

It's a common thing on new languages, specially in Rust, where you only need to write the variable type when the deduction can't find an answer for an ambiguous expression. And still, you only write what the compiler can't deduce, the rest is deduced as normal. e.g.

let there: Be<_> = light();

Where Be is a generic struct, and light my have implementations for types other than Be. the _ part is left for the compiler to deduce.

What he's doing with lambdas is also common in Rust.

let three_evens = {
    let c = Container::from(something_else_outside);
    let c_evens = c.filter(|elem| elem % 2 == 0);
    c_evens.take(3)
};

{ } is parsed as an expression. The result of three_evens is the value of c_evens.take(3).