1

csvData1 contains the data in a .csv file. I've created a sequence out of just two of the columns in the spreadsheet ("GIC-ID", "COVERAGE DESCRIPTION")

let mappedSeq1 = 
   seq { for csvRow in csvData1 do yield (csvRow.[2], csvRow.[5]) }

Looking in the Visual Studio debugger x winds up being a System.Tuple<string,string>.

for x in mappedSeq1 do
    printfn "%A" x
    printfn "%A" x.ToString

Here is the result of executing

for x in mappedSeq1

("GIC-ID", "COVERAGE DESCRIPTION")
<fun:main@28>

I am having difficulty figuring out how to access x, so I can extract the first element.

octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131

2 Answers2

1

You can use pattern matching to deconstruct the tuple

for (a, b) in mappedSeq1 do
  // ...

or

for x in mappedSeq1 do
  let a, b = x

Alternatively for a 2-tuple you can use the built-in function fst and snd

Sehnsucht
  • 5,019
  • 17
  • 27
  • @octopusgrabbus `x` shouldn't be a `seq` anyway but a 2-tuple (from the sample you gave) and so should work (or there are missing information in the question) – Sehnsucht Sep 13 '16 at 19:45
  • When I print out x, it's a function. I cannot use .fst, because it's not a method of the object. – octopusgrabbus Sep 13 '16 at 19:55
  • 1
    @octopusgrabbus `x` isn't a function ; you think it is because of `printfn "%A" x.ToString`. `ToString` is a function and `ToString ()` (note the parens) is the result of calling that function. Also you don't "dot into" to use `fst` it's a "free function" and have to be used this way `let firstPart = fst x` – Sehnsucht Sep 13 '16 at 20:23
1

Use Seq.map and fst to get a sequence of only the first component of a tuple:

let firstOnly = mappedSeq |> Seq.map fst
PiotrWolkowski
  • 8,408
  • 6
  • 48
  • 68