liveBook · Manning

Right-biased map operation

As explained in Data-Oriented Programming in Java

A right-biased map operation resolves duplicate keys by selecting the value from the right-hand map.

A right-biased map operation resolves duplicate keys by selecting the value from the right-hand map. It provides a concise default when collisions do not require custom combination logic. section 9.3.4

Listing 9.36 An exercise in tedium
UnbalancedCart refreshCart(ValidCart cart) {
  return new UnbalancedCart(
    cart.active().values().stream()     #A
     .map(this::preloadEverythingWeNeed) 
     .collect(toMap(ProductSeller::fromItem, Function.identity()), 
  cart.active().values().stream()                                 #B
    .map(this::preloadEverythingWeNeed)                           #B
    .collect(toMap(ProductSeller::fromItem, Function.identity()), #B
  );
}

The intersection utility delegates collision handling to a binary operation; its right-biased overload supplies the right value directly. section 9.3.4

Right-Biased Union

A right-biased union combines all keys from two maps while replacing any shared key’s value with the value from the second map.

How Data-Oriented Programming in Java covers it

How deep it goes
Defines the collision behavior and shows reusable Java overloads, without developing a deeper formal treatment.
Examples
Demonstrates right-biased intersection and union utilities that choose the right-hand value for shared keys.
What it assumes
Assumes familiarity with maps, duplicate-key collisions, and binary operations used to combine values.
What you can do after
Apply it via Java map utilities when duplicate keys should retain the right-hand value.
How it connects
Connects map intersection and union with binary operations, key collisions, and immutable map results.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming in Java. The section links point to the parts of the book it draws on.