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