0

I'm confused by this code:

/**
 * Lift a function of one argument to a function which accepts and returns values wrapped with the type constructor `F`
 */
export function lift<F extends URIS3>(
  F: Functor3<F>
): <A, B>(f: (a: A) => B) => <U, L>(fa: Type3<F, U, L, A>) => Type3<F, U, L, B>
export function lift<F extends URIS3, U, L>(
  F: Functor3C<F, U, L>
): <A, B>(f: (a: A) => B) => (fa: Type3<F, U, L, A>) => Type3<F, U, L, B>
export function lift<F extends URIS2>(
  F: Functor2<F>
): <A, B>(f: (a: A) => B) => <L>(fa: Type2<F, L, A>) => Type2<F, L, B>
export function lift<F extends URIS2, L>(
  F: Functor2C<F, L>
): <A, B>(f: (a: A) => B) => (fa: Type2<F, L, A>) => Type2<F, L, B>
export function lift<F extends URIS>(F: Functor1<F>): <A, B>(f: (a: A) => B) => (fa: Type<F, A>) => Type<F, B>
export function lift<F>(F: Functor<F>): <A, B>(f: (a: A) => B) => (fa: HKT<F, A>) => HKT<F, B>
/**
 * Lift a function of one argument to a function which accepts and returns values wrapped with the type constructor `F`
 * @function
 */
export function lift<F>(F: Functor<F>): <A, B>(f: (a: A) => B) => (fa: HKT<F, A>) => HKT<F, B> {
  return f => fa => F.map(fa, f)
}

I found this in the fp=ts repo

I am fairly confused by this. the initial signature looks the same for each function <A, B>(f: (a: A) => B).

how is typescript determining which is the correct invocation?

dagda1
  • 26,856
  • 59
  • 237
  • 450

2 Answers2

1

I don't know about fp-ts, but presumably the lift() overload is chosen according to whether the F argument passed in is a Functor3<>, Functor3C<>, Functor2<> or Functor2C<>. Which I assume are different enough to allow the compiler to pick one.

As @Sam mentioned in a comment, you seem to be looking at the return type of lift(), which doesn't enter in to the equation for which overload is chosen. lift() returns another function, which might be confusing you?

Hope that helps.

jcalz
  • 264,269
  • 27
  • 359
  • 360
0

(f: (a: A) => B) uses generic typings in defenition.

You can read more here https://www.typescriptlang.org/docs/handbook/generics.html

Oleksandr Poshtaruk
  • 2,062
  • 15
  • 18