通过镜头折叠或连接Aeson阵列 [英] Folding or concatMap-ing an Aeson Array via lenses

查看:62
本文介绍了通过镜头折叠或连接Aeson阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从

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]

推荐答案

有两种镜头功能可用于将与常规 Foldable 相关的功能提升"到镜头世界:

There are two lens functions that are used to "lift" regular Foldable-related functions to the lensy world:

  • folded 折叠在 Foldable 容器的所有元素上,在这种情况下,它将是 Vector .
  • folding 会提升一个返回 Foldable 结果的函数.
  • 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.

您可以将它们组合成新的 Fold ,然后使用

You can compose them into a new Fold and then use toListOf to obtain the final list.

对于 Traversable ,还有一个 folded 的类似物,称为

There is also an analogue of folded for Traversable, called traversed.

这篇关于通过镜头折叠或连接Aeson阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆