How can I refer to a specific member of a Tuple of any size in F#

前端 未结 4 996
囚心锁ツ
囚心锁ツ 2020-12-11 23:54

okay, this might be a silly question.

So I have some tuples of size 4 so like (int,int,int,int)

If it were a 2 tuple I could use fst(myTuple) to refer to th

4条回答
  •  萌比男神i
    2020-12-12 00:28

    If you want random access to a generally sized tuple, then it is not possible. For any given size, you can follow ildjarn's answer (extending it for four, five, etc.), but that it the only (functional) way.

    A possibility for tuples in general, is to convert it to a list first, as found here, but that's not too pretty as it requires reflection.

提交回复
热议问题