Both param <key>
and params
are lenses:
param :: Text -> Lens' Options [Text]
params :: Lens' Options [(Text, Text)]
Without going too much into details, you can think of a lens focusing something, e.g. param "foo"
focuses on some [Text]
in Options
that belong to the parameter foo
(*). You can then change/query/manipulate those values with the correct function (see the lens package).
You've already used (.~)
to replace the current values, and you can use it again with params
:
default & params .~ [("key1", "value1"), ("key2", "value2"), ("key3", "value3")]
You can think of (.~)
in this context as
(.~) :: Lens' a b -> b -> a -> a
-- concrete:
(.~) :: Lens' Options [(Text, Text)] -> [(Text, Text)] -> Options -> Options
(*) That's not 100% true, since lenses allow you to do all kinds of stuff, but good enough for this context.