我有以下代码片段,用于读取由镜头(lens-aeson
)表达式指定的值:
import Control.Lens ((^?))
import Data.Aeson (Value)
import Data.Aeson.Key (fromString)
import Data.Aeson.Lens (key)
import Data.Text (pack)
-- >>> readValue
-- Just (String "value")
readValue :: Maybe Value
readValue = json ^? path
where
path = key (fromString "key") . key (fromString "of") . key (fromString "interest")
json = pack "{\"key\": {\"of\": {\"interest\": \"value\"}}}"
现在我想通过将列表传递给来path
从配置中动态构建表达式。["key","of","interest"]
readValue
我如何path
从列表中动态创建?
我想是这样的:
foldr
如果您对此有强烈的感觉,您可以手动融合和列表理解。