0

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());
};
3

1 Answer 1

1
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) => (a) => fbc(fab(a));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.