1
votes

I'm trying to accomplish something like the following:

jsonStr = "{\"a\": \"hello\", 
            \"b\": [\"world\", \"everyone\", \"42\"]}"
someALens = ...
someBLens = ...
combinedJson = jsonStr ... someALens ... someBLens

to get as a result:

combinedJson == ["hello world", "hello everyone", "hello 42"]

However, the combination operators I've been finding (like <>~) seem to require a set value to mappend (or otherwise combine) over a lens. How could I create a compound lens which can combine values from multiple lenses?

1
I think stackoverflow.com/questions/17552835/… is what you're looking for. Once you define the Monoid instance as described over yonder, you'll be able to write combinedJson = jsonStr ^.. (someALens <> someBLens). - hao
@haoformayor that monoid instance is included in more recent lens releases. Just make ^.. (someALens <> someBLens) an answer. - leftaroundabout
That was what I needed. Thanks! As soon as someone puts it as an answer, I'll mark it as correct. - Michael Anderson

1 Answers

4
votes

As discussed in the comments, the answer is the rather-anticlimactic jsonStr ^.. (someALens <> someBLens). Two getters mappend into a fold. Monoids, our friends forever.