If you want to pass a tuple as function arguments you have to deconstruct the tuple, but miss point free syntax.
declare const f: (a: A, b: B) => C;
pipe(
tuple(a, b),
x => f(...x),
);
Use function apT to resolve this
declare const f: (a: A, b: B) => C;
// apT will apply the tuple as function arguments
const fT: (t: [A, B]) => C = apT(f);
pipe(
tuple(a, b),
fT,
);
This function could be implemented as
const apT: <A extends Array<unknown>, B>(f: (...a: A) => B) => (a: A) => B =
f => a => f(...a);
Every OS
| Software | Version(s) |
| ---------- | ---------- |
| fp-ts | 2.2.0 |
| TypeScript | 3.7.2 |
Is unary the right name for this functionality? It clashes with all other references and definitions of unary function or operator I have seen.
@gkamperis we can change the name, no problem. How can we name a combinator that accepts a function (a: A, b: B) => C and returns a function (x: [A, B]) => C?
Ideally should be a <name> such that
<name>: (f: (a: A, b: B) => C) => (t: [A, B]) => Cun<name>: (f: (t: [A, B]) => C) => (a: A, b: B) => C)(like the pair "curry" / "uncurry")
apT / unapT?unary / ununary?It's a tough one... But personally I would exclude unary.
Take the below with kindness... :)
untupleArg
destructureArg
In Scala there's tupled
@gcanti better than unary in my opinion
Thanks for the feature! :+1:
Are you considering adding unTupled yet?
export function unTupled<A extends Array<unknown>, B>(f: (a: A) => B): (...a: A) => B {
return (...a) => f(a)
}
Great!
Most helpful comment
@gcanti better than
unaryin my opinion