from F# tour i have this example
type Person = {
First : string
Last : string
}
/// A Discriminated Union of 3 different kinds of employees
type Employee =
| Engineer of engineer: Person
| Manager of manager: Person * reports: List<Employee>
| Executive of executive: Person * reports: List<Employee> * assistant: Employee
let rec findDaveWithOpenPosition(emps: List<Employee>) =
emps
|> List.filter(function
| Manager({First = "Dave"}, []) -> true
| Executive({First = "Dave"}, [], _) -> true
| _ -> false
)
However I would like to get access to object after matching object, something like this:
let rec findDaveWithOpenPos2(emps: List<Employee>) =
List.filter (fun (e:Employee) ->
match e with
| Manager({First = "Dave"}, []) -> e.Last.Contains("X") //Does not compile
| Executive({First = "Dave"}, [], _) -> true
| _ -> false
) emps
So i would like to have statically typed "e" as Person or Employee or Manager variable on right hand side with access to it's properties. Is it possible? Is there a better construction?