Talamori
Talamori

Reputation: 11

F# filtering a list (newbie)

I'm recently new to f# so please bear with me. the problem i have is I'm trying to display only yo parts of a list but unsure of the coding for example

int * int * float * float * int * float * float =

but only want

int * int

any help would be appreciated

Upvotes: 0

Views: 61

Answers (2)

PiotrWolkowski
PiotrWolkowski

Reputation: 8782

The example you presented:

int * int * float * float * int * float * float 

is a signature of a tuple. It means your tuple has 7 items of float and int type in the order specified in the signature. So an example of it would be:

let myTuple = (2, 4, 6.0, 8.0, 10, 12.0, 14.0)

You can create a function to extract first two items and ignore remaining ones.

let frstAndScd (a, b, _, _, _, _, _) = (a, b)

The underscore means that you are not interested in these items. You only take those marked by letters and return them as a new tuple.

Upvotes: 1

John Palmer
John Palmer

Reputation: 25516

So one way would be

l |> List.map (fun (a,b,_,_,_,_,_) -> (a,b))

Upvotes: 1

Related Questions