Is it possible to map one of elements of a tuple simply in typescript? I'm looking for a gentle abstraction over the following operation
const arr: [string, string][] = [['a', 'b'], ['c', 'd'], ['e', 'f']]
const f = (str: string): number => str.length
arr.map((row) => [row[0], f(row[1])])
my first attempt was to implement it like
function mapSnd<A, B, C>(arr: [A, B][], f: (B) => C): [A, C][] {
return arr.map((row) => [row[0], f(row[1])])
}
but it doesn't scale up well (for three elements tuple i would need to define new set of functions and so on), so I'm looking for a generic solution