News for hackers. Stuff that matters.
Re:Lenses by unhammer on Monday June 27, 2022 @04:27AM (#31891928)
I prefer non-powerful functions for trivial problems:

    > sum $ map (fromMaybe 0) [Just 1, Just 2]
    3
Re:Lenses by lucasdicioccio on Monday June 27, 2022 @04:51AM (#31892059)
I wouldn't call that trivial but "common", and for these cases we could even use something like catMaybes:

> sum . catMaybes

Lenses (imho) shine when you have to write data-extractors for arbitrary-complex and ill-documented APIs with corner cases or things like HTML scrapping. The beauty of lenses is that you get one composable language across libraries. For instance, if your HTTP-library has lenses and your XML-library has lenses, you can write things like safely composing a getElementsByTagName with some XML-parsing and data extractions:

> response ^.. responseBody . xml . folding universe . named (only "p") . text

and the bonus is that if you need to filter, you can do that with a similar mechanism (e.g., filtering based on some html meta-tag)

overall it feels like SQL-for-arbitrary-structures: dense but powerful

Re:Lenses by ParetoOptimal on Monday June 27, 2022 @09:23AM (#31894258)
I prefer a general polymorphic solution to optimize for global simplicityand consistency rather than lots of different ad-hoc simpler solutions that are more complex and/or less composable altogether.