View Source Migrating from Lens 1
Migration is supposed to be easy.
Note that you can migrate one module at a time.
There are perhaps gotchas yet to be discovered.
Put
use Lens2at the top of any module that defines or uses lenses.Code that makes lenses (
Lens.key(:a)) need not be changed.Replace the operations like
Lens.to_listandLens.mapwith theirLens2.Deeplyequivalents. Note that you have to change the argument order:Lens.put(lens, container, value) # Lens 1 Deeply.put(container, lens, value) # Lens 2Here is a list of changes:
Lens.each(lens, container, f) Deeply.each(container, lens, f) Lens.get_and_map(lens, container, f) Deeply.get_and_update(container, lens, f) Lens.map(lens, container, f) Deeply.update(container, lens, f) Lens.one!(lens, container) Deeply.get_only(container, lens) or Deeply.one!(container, lens Lens.put(lens, container, v) Deeply.put(container, lens, v) Lens.to_list(lens, container) Deeply.get_all(container, lens) or Deeply.to_list(container, lens)use Lens2will import macrosdeflensanddeflens_raw, so you don't have to change them. However, it also importsdefmakeranddef_raw_maker, which I prefer.If you use
TypedStructandTypedStructLens, you have to add analias Lens2.TypedStructLensto your existing modules. See the module documentation.