calmm-js / partial.lenses

Partial lenses is a comprehensive, high-performance optics library for JavaScript
MIT License
915 stars 36 forks source link

Isomorphism in L.array called with undefined #178

Closed shtanton closed 6 years ago

shtanton commented 6 years ago

If I slightly modify the example for L.array and add some logs

const something = L.getInverse(L.array([L.log("a"), L.pick({x: "y", z: "x"}), L.log("b")]), [
    {x: 2, z: 1},
    {x: 4, z: 3},
]);

It seems to be getting L.pick with undefined

a get undefined
b get undefined
b set { x: 2, z: 1 }
a set { y: 2, x: 1 }
a get undefined
b get undefined
b set { x: 4, z: 3 }
a set { y: 4, x: 3 }

I don't know if this is intended behavior or a bug, thought I expect this is completely intentional.

Thanks

polytypic commented 6 years ago

Yes, this is expected behavior. It happens due to the way partial isomorphisms are implemented in this library. Inverse operations call L.set(iso, data, undefined).

shtanton commented 6 years ago

Thanks for clearing that up, I suspected it was intentional but just wanted to be sure