View Source mix has.smart.put (Lens 2 v0.2.1)

Is the data type smart about "put" operations that produce identical structures?

A naive implementation of Map would be such that:

iex> Map.get(map, :key)
:some_value
iex> Map.put(map, :key, :some_value)

... would allocate a completely new map. Maps and structs are, in fact, smarter than that. put just returns the original map.

This matters for the current implementation of lenses because Deeply.get_all will do such equality-preserving puts (and then throw the result away). Naive implementations of a container data type will do extra work that get_in avoids.

If you're implementing lenses for a new data structure, you nmight want to know whether it's smart or naive.

$ mix has.smart.put
Is the data structure smart enough to not create an identical copy?
List: false
Map: true
Struct: true
MapSet: true