curry function
Implementation
Function curry(Function fn, {int argsLength: 2}) {
assert(argsLength <= 5);
return <T, E, A, B, C>([T? a, E? b, A? c, B? d, C? e]) {
final hasPlaceholder = (value) => value == LodaConstants.placeholder;
final hasFullValue = (args) => List.of(args).length == argsLength;
final hasNotPlaceholder = (values) => List.of(values).length == 0;
final valuesNotNull = (args) => args.where(isNotNil);
final valuesHasPlaceholder = (args) => args.where(hasPlaceholder);
final args = valuesNotNull([a, b, c, d, e]).toList();
final isEligible = flow([
valuesNotNull,
and([
flow([hasFullValue]),
flow([valuesHasPlaceholder, hasNotPlaceholder])
])
]);
if (isEligible([a, b, c, d, e])) {
return Function.apply(fn, args);
}
if (1 == argsLength) return curry1(fn)(a);
if (2 == argsLength) return curry2(fn)(a, b);
if (3 == argsLength) return curry3(fn)(a, b, c);
if (4 == argsLength) return curry4(fn)(a, b, c, d);
if (5 == argsLength) return curry5(fn)(a, b, c, d, e);
};
}