只需阅读精彩的“ Lens/Aeson Traversals/Prisms”文章并拥有一个真实世界的应用程序。鉴于以下匿名 JSON 结构,我将如何提取集合而不是特定值?
{"Locations" : [ {"id" : "2o8434", "averageReview": ["5", "1"]},{"id" : "2o8435", "averageReview": ["4", "1"]},{"id" : "2o8436", "averageReview": ["3", "1"]},{"id" : "2o8437", "averageReview": ["2", "1"]},{"id" : "2o8438", "averageReview": ["1", "1"]}]}
我有:
λ> locations ^? key "Locations" . nth 0 . key "averageReview" . nth 0
Just (String "5")
我想要的是:
λ> locations ^? key "Locations" . * . key "averageReview" . nth 0
["5", "4", "3", "2", "1"]
我错过了棱镜的全部意义吗?或者这是一个合法的用例?
干杯!