问题
I've been starting at https://www.stackage.org/haddock/lts-12.1/lens-aeson-1.0.2/Data-Aeson-Lens.html and https://www.stackage.org/haddock/lts-12.1/lens-4.16.1/Control-Lens-Fold.html trying to figure out how to write an expression that allows me to construct something of the following type:
import Data.Aeson as A
functionIWant
:: (Vector A.Value)
-> (A.Value -> [a])
-> [a]
回答1:
There are two lens functions that are used to "lift" regular Foldable
-related functions to the lensy world:
- folded that folds over all the elements of a
Foldable
container, in this case it would be theVector
. - folding that lifts a function that returns a
Foldable
result.
You can compose them into a new Fold
and then use toListOf to obtain the final list.
There is also an analogue of folded
for Traversable
, called traversed.
来源:https://stackoverflow.com/questions/51906616/folding-or-concatmap-ing-an-aeson-array-via-lenses