Mostly Adequate with fp-ts
1.0.0
1.0.0
  • Welcome
  • Chapter 01: What Ever Are We Doing?
  • Chapter 04: Currying
  • Chapter 05: Coding by Composing
  • Chapter 06: Example Application
  • Chapter 08: Tupperware
  • Chapter 09: Monadic Onions
  • Chapter 10: Applicative Functors
Powered by GitBook
On this page

Was this helpful?

Chapter 06: Example Application

PreviousChapter 05: Coding by ComposingNextChapter 08: Tupperware

Last updated 4 years ago

Was this helpful?

The only "new" concept is just theprop function. , but a more powerful library called is recommended for this purpose. There is also a library called which offer this function, among others to help bring feature parity to fp-ts.

I've modified the so it can be used without any additional dependency for the purpose of this book:

const prop = curry((property, object) => object[property]);
export function prop<K extends string>(k: K): <T extends Record<K, any>>(obj: T) => T[K];
export function prop<K extends keyof T, T extends object>(k: K, obj: T): T[K];
export function prop<K extends string, T extends Record<K, any>>(k: K, obj?: T): T[K] | ((obj: T) => T[K]) {
  if (obj === undefined) {
    return <T extends Record<K, any>>(obj: T): T[K] => obj[k];
  } else {
    return obj[k];
  }
}

fp-ts does not provide an equivalent function
monocle-ts
fp-ts-ramda
fp-ts-ramda implementation