4 ms·
I'm confused by .map(|row| { json::encode(row) }) .map(|val| some_new_value(val)) Over .map(json::encode) .map(some_new_value) Is the explic
by thomasahle 10y ago
I'm confused by
.map(|row| { json::encode(row) })
.map(|val| some_new_value(val))
Over
.map(json::encode)
.map(some_new_value)
Is the explicit extra layer of lambda generally prefered in Rust over just passing the functions?
- steveklabnik 10y agoIt's just a style thing, some people prefer one way, some another. I personally prefer the latter. They compile to the exact same thing.
- thomasahle 10y agoThe makes sense. Do you know if Rust already has an idiomatic correct style?
- steveklabnik 10y agoI don't think that there's ever been an explicit discussion about it. I'm not even sure how many people know the latter is possible, to be honest, it's a bit harder to learn about.
- digi_owl 10y agoI wonder if it is information used by the compiler to do error checks. Keep in mind that one of the goals of Rust is to catch common errors in C like languages at compile time rather than run time.
- tatterdemalion 10y agoNo. If there were a type error with either form, the compiler will catch it.
- inglor 10y agoIt makes the blog post more approachable for users. I have seen the exlicit style being used over the point-free style many times before since it seems like it's easier for newbies to grasp - I haven't seen any evidence to support it though.
- iopq 10y agoI find point-free style confusing sometimes. This is because I can't tell what is being encoded. Then in the first example I would be like "OK, we encode a row..."