Effect CommunityEC
Effect Community2y ago
14 replies
Wheelwright

Working with Tuples and Type Errors

I have a question about working with tuples
    const formatNumber = flow((n: number) => (n * 2 - 1).toFixed(2), Number);

    const x = (e.clientX - left) / width;
    const y = (e.clientY - top) / height;

    // I want this but it type errors
    // function angleFromOrigin(x: [number: number]): number;
    // this works but the input type wouldn't error for angleFromOrigin([2])
    // function angleFromOrigin(x: number[]): number;
    pipe([x, y], RA.map(formatNumber), angleFromOrigin);

    // I don't want to do this
    pipe(
      T.make(x, y),
      T.mapBoth({ onFirst: formatNumber, onSecond: formatNumber, }),
      angleFromOrigin
    );
Was this page helpful?