How can i convert between F# List and F# Tuple?

前端 未结 5 1016
Happy的楠姐
Happy的楠姐 2020-11-30 10:45

Is there some way to convert between F# List and F# Tuple?

For example:

[1;2;3] -> (1,2,3)    
(1,2,3,4) -> [1;2;3;4]

I need

5条回答
  •  广开言路
    2020-11-30 11:39

    Well, it ain't pretty but:

    let tuple_to_array input =
        let temp_str = input.ToString()
        temp_str.Substring(1, temp_str.Length - 2)
        |> Array.map (fun (x:string) -> x.TrimStart(' '))
    

    I'm not sure how you'd go back the other way though. And I'm really not sure this would be sensible, but if you really have to.

提交回复
热议问题