I was reading about Diode, and it made me think about lenses in Monocle / Scalaz:
If I (conditionally) modify deeply some part of a deeply nested data-structure using Monocle/Scalaz lens and want to compare if there was a change, is there a need to do a deep comparison, or is there a way to use reference equality to see if the two data-structures (before conditionaly modification and after) are the same ?
In other words:
val f_new=modifyWithMonocleIfTheSunIsUp(f_old)
Can the comparison f_new==f_old
be made efficient using reference equality (eq
) at the root (f_old
, f_new
) of the data-structure ?
In other words,
is it true that f_new==f_old
is true if and only if f_new.eq(f_old)
is true ? (Equation 1)
If not, why not ?
If not, is it possible to make Equation 1
true ? How ?
Maybe you can use
modifyF
instead ofmodify
to return anOption
so you don't have to check if something has changed.For example :