Re:Rust 1.32 released
by majewsky on Friday January 18, 2019 @06:49AM
(#18938649)
It also reminds me of Ruby's
For those of you who don't know Ruby, its map/filter/reduce functions chain like this:
So when you want to look at an intermediate result, there's the .tap() method that runs a lambda with that intermediate result, then passes it on to the next step in the chain.
This returns [4, 5] after printing [2, 3, 4, 5]. ("puts" is Ruby's println.)
[ Parent
| on HN ]
Took me a while to find it, but Rust's iterators have an `.inspect` method that gives you a read-only reference, so println debugging works fine. For more advanced tap-like stuff, use the `tap` crate (which allows you to write `array.tap(|xs| xs.sort())` for example, even though `sort` mutates in place and doesn't return the array).