Using LINQ in F#
F# has query expressions that help to easily build Language Integrated Query (LINQ) queries. Query expressions can be declared as query { ... }
. It is a type of computation expression, just like the sequence expression. An example code is given as follows:
let data = [| 1..10 |]
let simpleExpression() =
query {
for d in data do
select d
contains 5
}
> simpleExpression();;
val it : bool = true
Query expressions have a list of query operators with which we can use the LINQ-like operations on the data:
let designations = [| "CEO"; "CTO"; "Manager"; "Employee" |] type Employee = { FirstName: string LastName: string Designation: string Salary: int } with static member DummyData() = let r = new System.Random() seq { for i = 0 to 10 do let e = { ...