Skip to content

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

@tuxslayer

Description

@tuxslayer

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions