You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that the example comparing imperative vs functional approaches uses fold vs sum.
One can argue that fold is classically thought of as functional, but I think that the objective of the example is the functional flavor, thus sum would be more appropriate.
let sum_of_squared_odd_numbers:u32 =
(0..).map(|n| n * n)// All natural numbers squared.take_while(|&n_squared| n_squared < upper)// Below upper limit.filter(|&n_squared| is_odd(n_squared))// That are odd.fold(0, |acc, n_squared| acc + n_squared);// Sum them
vs
let sum_of_squared_odd_numbers:u32 =
(0..).map(|n| n * n)// All natural numbers squared.take_while(|&n_squared| n_squared < upper)// Below upper limit.filter(|&n_squared| is_odd(n_squared))// That are odd.sum();// Sum them
The text was updated successfully, but these errors were encountered:
I noticed that the example comparing imperative vs functional approaches uses
fold
vssum
.One can argue that
fold
is classically thought of as functional, but I think that the objective of the example is the functional flavor, thussum
would be more appropriate.vs
The text was updated successfully, but these errors were encountered: