[Haskell-cafe] Lenses: Changing/creating values deep inside JSON or HashMap

Jan von Löwenstein jan.loewenstein at gmail.com
Tue Dec 20 13:26:29 UTC 2016


I guess I haven't explained well what I am looking for.

I want to set values deep inside a json structure, no matter if the full
structure already exists.

Go into "outer", if it doesn't exist make it an empty object.
>From there go into "inner" and set it to "new-value".

The first part should be arbitrarily deep.

Best
Jan

Benjamin Edwards <edwards.benj at gmail.com> schrieb am Di., 20. Dez. 2016 um
13:42 Uhr:

> If the desired function doesn't inspect the input then why not just use
> const <<thing you want>> ?
>
> As to the lenses part: If you use a prism and it doesn't match, then it's
> a noop.
>
> On Tue, 20 Dec 2016 at 09:38 Jan von Löwenstein <jan.loewenstein at gmail.com>
> wrote:
>
> Hi,
>
> I want to have code that produces the following result no matter if input
> A or B was given:
>
> Result:
> {
>   "outer" : {
>                   "inner" : "new-value"
>                 }
> }
>
> A:
> {
>   "outer" : {
>                   "inner" : "old-value"
>                 }
> }
>
> B:
> {}
>
> `json & key "outer"._Object.key "inner" .~ "new-value"` didn't work.
>
> Is what I want even possible with lenses?
>
> Best
> Jan
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20161220/b283669a/attachment.html>


More information about the Haskell-Cafe mailing list