Is there an existing function to apply a function to each member of a tuple?

f#

Solution

I don't think there is any standard library function that does this.

My personal preference would be to avoid too many custom operators (they make code shorter, but they make it harder to read for people who have not seen the definition before). Applying function to both elements of a tuple is logically close to the map operation on lists (which applies a function to all elements of a list), so I would probably define `Tuple2.map`:

module Tuple2 = 
  let map f (a, b) = (f a, f b)

Then you can use the function quite nicely with pipelining:

let nums = (1, 2)
nums |> Tuple2.map (fun x -> x + 1)

Problem

I want to apply a function to both members of a homogenous tuple, resulting in another tuple. Following on from my previous question I defined an operator that seemed to make sense to me: ``` let (||>>) (a,b) f = f a, f b ``` However, again I feel like this might be a common use case but couldn't find it in the standard library. Does it exist?

Original source

Related problems