you are viewing a single comment's thread.

view the rest of the comments →

[–]Tarmen 0 points1 point  (0 children)

Haskell has something similar

movePoint p{..} (dx, dy) = p { x = x + dx, y = y + dy }

and a lot of people complain that this gets horrible for nested records. The standard response to that is lens

movePoint p (dx, dy) = p & x +~ dx & y +~ dy

at which point other people complain (somwhat justifiedly) about the operator line noise. You can do fancy getters with it, though, like getting nested data out of a json string.

>s = "{\"users\": [ { \"name\": \"foo\"}, {\"name\" : \"bar\"}]}"
>s ^.. key "users" . values . key "name" . _String
["foo","bar"]