Folding or concatMap-ing an Aeson Array via lenses

天大地大妈咪最大 提交于 2020-08-10 21:22:38

问题


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 the Vector.
  • 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!