Open erikvanoosten opened 1 year ago
the java method uses a lot of magic null values which is something scala tries to avoid. how would the signature look in terms of Option?
and, since i can't remember ever having needed something like this: can you give an example where this method is useful?
the java method uses a lot of magic null values which is something scala tries to avoid. how would the signature look in terms of Option?
The whole point of merge is that options are not needed. My proposal is to not allow null arguments at all.
and, since i can't remember ever having needed something like this: can you give an example where this method is useful?
In zio-kafka we need to merge offsets, something like Map[Partition, Long] where we keep the largest offset per partition. The discussion (with code) that sparkled this issue is at https://github.com/zio/zio-kafka/pull/1079
Please consider adding the
merge
method tomutable.Map
. Java defines the method as follows, see java docsRationale
When we never remove a value, using
updateWith
is very cumbersome andmerge
gives better readable code.Translation to Scala
For discoverability and uniformity, the name could be changed to a variant of
updateWith
.We don't do nulls in Scala so we shouldn't allow that. The return type would be Option.
The Scala implementation could be equivalent to: