3 ms·
The post is interesting and highlights a true fact : it is not always easy to chain map/filter/reduce transformations when the processed values are compound and
by dwenzek 11y ago
The post is interesting and highlights a true fact : it is not always easy to chain map/filter/reduce transformations when the processed values are compound and call for processing that are specific to each part.
Nonetheless, the proposed solution is most in the component/object realm rather in the functional world.
As an evidence the use of nouns rather verbs as in :
splitter.input = hi_generator.his
lowercaser.input = splitter.left_part
uppercaser.input = splitter.right_part
This is not a judgement, just a remark. A functional solution would rather use transformation combinators to propagate a transformation on a specific value part.
For instance :
input |> map split_two_halves
|> map_fst to_lower
|> map_snd to_upper
Or even better, use lenses as a generic way to unpack a specific part of a data structure and to repack an updated value:
input |> map split_two_halves
|> map_lens fst to_lower
|> map_lens snd to_upper