-
Notifications
You must be signed in to change notification settings - Fork 0
/
GremlinQueries.Issue.fs
52 lines (45 loc) · 2.37 KB
/
GremlinQueries.Issue.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
namespace FSharp.IssueDemo
open System
open ExRam.Gremlinq.Core
module GremlinQueries =
// This method supposed to work even without specifying the types of the lambda function parameters
// It perfectly works in C#, but not in F#.
// See the 'GetDepartmentUsers_CompilableVersion' method to find the changes that make it work
let GetDepartmentUsersQuery_UncompilableButValidVersion
(gremlinQuerySource: IGremlinQuerySource)
(departmentId: Guid)
=
let resultQuery =
gremlinQuerySource
.V(departmentId)
.OfType<Department>()
.As (fun query departmentStepLabel ->
query
.Out<EdgeUserToDepartment>()
.OfType<User>()
.As (fun query userStepLabel ->
query
.Where(fun currentUser -> currentUser.Name <> "Admin")
.Select (userStepLabel)))
resultQuery
// Same implementation but with some types specified explicitly to make it compilable.
// We have to specify the second parameter type of the lambda function passed to 'As' method
// Also we have to specify the type of the lambda function parameter passed to 'Where' method
// 'Where' is not a linq method but a method of the 'IGremlinQuery' interface
let GetDepartmentUsers_CompilableVersion (gremlinQuerySource: IGremlinQuerySource) (departmentId: Guid) =
let resultQuery =
gremlinQuerySource
.V(departmentId)
.OfType<Department>()
// It doesn't compile without specifying the type of 'departmentStepLabel'
.As (fun query (departmentStepLabel: StepLabel<_, Department>) ->
query
.Out<EdgeUserToDepartment>()
.OfType<User>()
// It doesn't compile without specifying the type of 'userStepLabel':
.As (fun query (userStepLabel: StepLabel<_, User>) ->
query
// It doesn't compile without specifying the type of 'currentUser':
.Where(fun (currentUser: User) -> currentUser.Name <> "Admin")
.Select userStepLabel))
resultQuery