4 ms·
What a good transactional API is like is an interesting question. public void modify(K key, Function<Optional<V>,Optional<V>> modifier) or something along
by PaulHoule 11mo ago
What a good transactional API is like is an interesting question.
public void modify(K key, Function<Optional<V>,Optional<V>> modifier)
or something along those lines covers the race of a single value being changed out from under you, but if you want to update one or more keys you might want
public void modifyMany(Set<K> key, Consumer<Map<K,V>> modifier)
where the modifier gets passed a modifiable view that has just the keys in the set.
There is also the Clojure-style immutable API for maps though I can say I never really enjoyed working with that the way I enjoyed immutable lists (which are Lispier than Lisp: I went through all the stages of grief reading On Lisp and couldn't help think "If he was using Clojure he wouldn't be struggling with nconc)
- deleted 11mo ago[deleted]
- mrkeen 11mo agoSTM containers does it right. lookup :: k -> Map K v -> STM (Maybe v) insert :: v -> k -> Map K v -> STM () It won't execute until you wrap it with atomically, so you're forced to be explicit about whether these things should happen in one logical step or separately. https://hackage-content.haskell.org/package/stm-containers/docs/StmContainers-Map.html https://hackage-content.haskell.org/package/stm-containers/d...