Skip to main content
added 2 characters in body
Source Link

I need to implement a function (flow) that makes a functional composition of its two arguments.

Requirements:

  • The flow function should take two functions as arguments (called fab and fbc) and return a new function that applies fab to its input parameter and then applies fbc to the resulting value.

Hints:

  • The first function is called fab because it maps a value from type A to type B. The same for fbc.

The problem is that I don't know what to pass as a parameter to fab function, I'm a Typescript newbie, would appreciate any help!

This is my code so far:

  fab: (a: A) => B, // Takes a function from A to B
  fbc: (b: B) => C // Takes a function from B to C
) => (a: A) => C; // Returns a function from A to C

export const flow: Flow = (fab, fbc) => {
  return fbc(fab());
};
type Flow = <A, B, C>(
  fab: (a: A) => B, // Takes a function from A to B
  fbc: (b: B) => C // Takes a function from B to C
) => (a: A) => C; // Returns a function from A to C

export const flow: Flow = (fab, fbc) => {
  return fbc(fab());
};

I need to implement a function (flow) that makes a functional composition of its two arguments.

Requirements:

  • The flow function should take two functions as arguments (called fab and fbc) and return a new function that applies fab to its input parameter and then applies fbc to the resulting value.

Hints:

  • The first function is called fab because it maps a value from type A to type B. The same for fbc.

The problem is that I don't know what to pass as a parameter to fab function, I'm a Typescript newbie, would appreciate any help!

This is my code so far:

  fab: (a: A) => B, // Takes a function from A to B
  fbc: (b: B) => C // Takes a function from B to C
) => (a: A) => C; // Returns a function from A to C

export const flow: Flow = (fab, fbc) => {
  return fbc(fab());
};

I need to implement a function (flow) that makes a functional composition of its two arguments.

Requirements:

  • The flow function should take two functions as arguments (called fab and fbc) and return a new function that applies fab to its input parameter and then applies fbc to the resulting value.

Hints:

  • The first function is called fab because it maps a value from type A to type B. The same for fbc.

The problem is that I don't know what to pass as a parameter to fab function, I'm a Typescript newbie, would appreciate any help!

This is my code so far:

type Flow = <A, B, C>(
  fab: (a: A) => B, // Takes a function from A to B
  fbc: (b: B) => C // Takes a function from B to C
) => (a: A) => C; // Returns a function from A to C

export const flow: Flow = (fab, fbc) => {
  return fbc(fab());
};
Source Link

Function composition in Typescript

I need to implement a function (flow) that makes a functional composition of its two arguments.

Requirements:

  • The flow function should take two functions as arguments (called fab and fbc) and return a new function that applies fab to its input parameter and then applies fbc to the resulting value.

Hints:

  • The first function is called fab because it maps a value from type A to type B. The same for fbc.

The problem is that I don't know what to pass as a parameter to fab function, I'm a Typescript newbie, would appreciate any help!

This is my code so far:

  fab: (a: A) => B, // Takes a function from A to B
  fbc: (b: B) => C // Takes a function from B to C
) => (a: A) => C; // Returns a function from A to C

export const flow: Flow = (fab, fbc) => {
  return fbc(fab());
};