jotaijs / jotai-optics

Jotai integration library for optics-ts
MIT License
24 stars 5 forks source link

Standalone optic API #17

Open mrjackdavis opened 2 weeks ago

mrjackdavis commented 2 weeks ago

optic-ts contains a standalone api which looks a bit more like this

O.compose(
  'foo',
  O.optional,
  O.when((value: number) => value > 42)
)

I've come across instances where this API is preferable, especially if I'm reusing complex optics

e.g.

const myComplexOptic = O.compose(
  'foo',
  O.optional,
  O.guard((obj:{type:string}) => obj.type === 'bar')
)

const bazAtom = focusAtom(dataAtom,O.compose(myComplexOptic,'baz'));
const quxAtom = focusAtom(dataAtom,O.compose(myComplexOptic,'qux'));

This might also contribute to solving such issues as #15 without introducing new concepts

I think this would be worth implementing

dai-shi commented 2 weeks ago

Would you be interested in implementing it? I think we should create a completely new function.