Reputation: 1427
The university example explains how to add and delete items of a map:
(departments composeLens at("Physics")).set(Some(physics))(uni)
(departments composeLens at("History")).set(None)(uni)
This does not work with Lists, though:
(lecturers composeOptional index(2)).set(Lecturer("New", "Lecturer", 50))(dep)
(lecturers composeOptional index(0)).set(None)(dep)
Adding does nothing, deleting throws a compilation error.
Edit: By now, I use quicklens, which is able to modify sequences.
Upvotes: 4
Views: 439
Reputation: 15641
Since there is no explicit question in the OP, I will try answering a couple of possible questions:
The answer is given in "What is the difference between at and index? When should I use one or the other?" halfway across the page:
In other words,
index
can update any existing values whileat
can alsoinsert
anddelete
.
Just below the text quoted above:
Since
index
is weaker thanat
, we can implement an instance ofIndex
on more data structure thanAt
. For instance,List
orVector
only have an instance ofIndex
because there is no way to insert an element at an arbitrary index of a sequence.
So it may not be possible... I have no Monocle here to test a few things, though.
Upvotes: 1