3 ms·
> I can write code like that (and worse), and it doesn’t make any sense to me I'm learning FP and I see value with writing code with map, reduce etc as those a
by jve 4y ago
> I can write code like that (and worse), and it doesn’t make any sense to me
I'm learning FP and I see value with writing code with map, reduce etc as those are expressions instead of statements. Expressions guarantee you have a result of particular type (with possible side effects if you prefer), but statements DO side effects. The loop may or may not insert some value into resulting list because some branching happened or you forgot some else condition, with map you guarantee you get same number of objects of particular type back.
Plus that enables composition (like in C# LINQ) - by not extending some loop with different kind of responsibilities but just passing result to next function that modifies/filters the result.
https://fsharpforfunandprofit.com/posts/expressions-vs-statements/ https://fsharpforfunandprofit.com/posts/expressions-vs-state...