Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array lens created through Prism sets array element to undefined #17

Closed
tuxslayer opened this issue Oct 3, 2017 · 2 comments
Closed
Assignees

Comments

@tuxslayer
Copy link

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
@blacktaxi
Copy link
Member

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.

@blacktaxi
Copy link
Member

Tracking this in #18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants