You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a Lens created through a Lens.index(...) prism with default value V it sets associated array element into undefined in being set with that value V.
E.g.:
const states = Atom.create([]) // Array of strings
states.set(['hidden', 'hidden'])
const lens = states.lens(Lens.index(0).compose(Lens.withDefault('hidden')))
// ...
lens.set('visible') // works just fine
lens.set('hidden') // sets states[0] to `undefined`
Two points here:
I assume expected behavior is to return default value if array[i] is undefined by set whatever is passed to lens.set()
Returning an optional from states.lens(Lens.index(0)) is not very convenient IMO
The text was updated successfully, but these errors were encountered:
Hi, thanks for reporting, I'll look into it – seems like a buggy behavior.
For your second point, returning an optional from an index lens is necessary to be type-safe, as the lens could be used to view the array for which the index will be out of bounds.
When a Lens created through a
Lens.index(...)
prism with default value V it sets associated array element into undefined in being set with that value V.E.g.:
Two points here:
lens.set()
states.lens(Lens.index(0))
is not very convenient IMOThe text was updated successfully, but these errors were encountered: