pipe2

C Function(A) pipe2<A, B, C>(

  1. B f1(
    1. A
    ),
  2. C f2(
    1. B
    )
)

Composes functions with different input/output types.

This is a more flexible version of compose that allows for type transformations through the composition chain.

Example:

final toString = (int x) => x.toString();
final addExclaim = (String s) => '$s!';
final getLength = (String s) => s.length;

final pipeline = pipe3(toString, addExclaim, getLength); print(pipeline(42)); // 3 (length of "42!")

Implementation

C Function(A) pipe2<A, B, C>(B Function(A) f1, C Function(B) f2) =>
    (a) => f2(f1(a));