Hi! I am reading Rust std now and I found something confusing. In this example for
[2.4, f32::NAN, 1.3]
How about this
reduce here? The std tells me it should take a closure as a parameter but there is only a return value
f32::max here? The result, 2.4 is also confusing. Could you explain what happen in
March 24, 2023, 3:05am
reduce doesn't just take a closure. It takes
FnMut(Self::Item, Self::Item) -> Self::Item, which means any closure or function that takes 2 arguments and returns an item.
. It takes two arguments: one is
f32::max is a method on the f32 type
self, and the other is the other number. You typically call it like
. Rust calls that universal function call syntax (
f32::max(x,y) works too
Thank you so much for this detailed answer! I get it now!