samhh / fp-ts-std

The missing pseudo-standard library for fp-ts.
https://samhh.github.io/fp-ts-std/
MIT License
207 stars 27 forks source link

Add typesafe get for struct #184

Closed forno closed 1 year ago

forno commented 1 year ago

Close #183

samhh commented 1 year ago

(Moved comment from the issue.)

Thanks! This could be a useful shorthand that's cheaper than lenses.

"Lookup" to me implies a record. Maybe get, or _ (thinking of PureScript), could make more sense?:

const getX1 = S.get('X')
const getX2 = S._('X')

Probably get given the namespacing norm in fp-ts. WDYT?

forno commented 1 year ago

I see. I picked up the name from Record and Array. I thought it was a common name at the time.

However, I'm a begginer for Functional Programming. I believe it would be better to name this operation as "get", which does not fail, instead of "lookup" which may fail.

samhh commented 1 year ago

Thanks!