I like Kotlins solution for this. If there is only one argument in the lambda/block and the type is clear from the context you don’t have to declare it and you can use the ‘it’ keyword instead.
people.filter { it.age > 42 } things.filter { its.age > 42 }
people.filter { their.age > 42 }
;)If I recall correctly, the canonical name for that parameter is 'it' as well (though I've never met a Perl programmer that calls it that . . . er, calls it 'it' . . . er, you get the idea).
(mac aif (expr . body)
`(let it ,expr
(if it
,@(if (cddr body)
`(,(car body) (aif ,@(cdr body)))
body))))
HN uses it quite a lot, e.g.: (defop logout req
(aif (get-user req)
(do (logout-user it)
(pr "Logged out."))
(pr "You were not logged in.")))In Ruby, the two-parameter hash-iteration case alone is common enough that that's not true.
> If you have more than one, you should probably name them anyway.
In a single line block, I think that often impairs rather than enhances readability.