3 ms·
There's the simple good stuff: single assignment in a method/function, filter/map/reduce. Some better stuff: Option/List & flat_map, Either/Result & and_then, e
by karmakaze 4y ago
There's the simple good stuff: single assignment in a method/function, filter/map/reduce. Some better stuff: Option/List & flat_map, Either/Result & and_then, elimination of most mutable state in OOP. The initializer/constructor is pretty much used for DI and other fixed context rather than mutable state.
The best part is thinking in terms of data and transformations of that data, whether you compose the functions first or run data through a pipeline.
I've been applying this for some projects in a RoR codebase and the team seems to like it way more than others' more Ruby idiomatic but widely-varying styles. It wouldn't be nearly as useful without Sorbet static typing.
I was doing the Advent of Code in Rust and was disappointed to find that using for loops is substantially more convenient than functional constructions.