I need to learn the right way to do pattern matching on Pair types:
let pairToBeFiltered = Ok ([(1,[]);(2,[3;4]);(5,[6;7;8]);(9,[]);(10,[])])
let filterEmpty (pair: int * int list) =
match pair with
| (x,y) when y <> [] -> (x,y) //This gives error because of incomplete pattern matching!
let filtering = List.map(filterEmpty) pairToBeFiltered
Desired output:
Ok([(2,[3;4]);(5,[6;7;8])])
This should do it:
There are a number of issues here:
filterEmptyso it processes the entire list, rather than a single pair. This is where we apply the filtering function,List.where, using pattern matching. (In your code, note thatList.mapwith amatchexpression doesn't filter anything.)Result, you need to unwrap it viaResult.mapin order to process it. (Since you didn't specify a'TErrortype, I assumedstringto pacify the compiler.)