DEV Community

Discussion on: Getting started with fp-ts: Reader

Collapse
 
cyberixae profile image
Toni Ruottu

Do we have a standard name for (r: Reader<R,A>) => A?

import { Reader } from 'fp-ts/lib/Reader';

type Provider<R> = <A>(r: Reader<R,A>) => A

type Name = string
type Age = number

type Customer = {
  name: Name,
  age: Age,
}

const john: Provider<Customer> = (r) => r({
  name: 'John Doe',
  age: 42,
})

const getAge: Reader<Customer, Age> = ({age}) => age

const ageJohn: Age = john(getAge);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
gcanti profile image
Giulio Canti

Yoneda? Provider<R> is isomorphic to R

Collapse
 
fp_apprentice profile image
λ fp-apprentice

Whoops, my brain is starting to melt, but I like all of this. :)

Collapse
 
fp_apprentice profile image
λ fp-apprentice

Wait, wait, I get it now