Accessing a specific member in a F# tuple

前端 未结 4 599
南旧
南旧 2021-02-03 18:20

In F# code I have a tuple:

let myWife=(\"Tijana\",32)

I want to access each member of the tuple separately. For instance this what I want to ac

4条回答
  •  爱一瞬间的悲伤
    2021-02-03 18:54

    You want to prevent your wife from aging by making her age immutable? :)

    For a tuple that contains only two members, you can fst and snd to extract the members of the pair.

    let wifeName = fst myWife;
    let wifeAge = snd myWife;
    

    For longer tuples, you'll have to unpack the tuple into other variables. For instance,

    let _, age = myWife;;
    let name, age = myWife;;
    

提交回复
热议问题