Skip to content

Instantly share code, notes, and snippets.

@cskardon
Created January 7, 2014 14:53
Show Gist options
  • Save cskardon/8300420 to your computer and use it in GitHub Desktop.
Save cskardon/8300420 to your computer and use it in GitHub Desktop.
Updated version of neo4j-fsharp-basic.fs (https://gist.github.com/cskardon/7673426) to use a Lambda expression for the return.
open System
open Neo4jClient
open Neo4jClient.Cypher
open System.Linq
open Microsoft.FSharp.Linq.RuntimeHelpers
[<CLIMutable>]
type Person = { Name:string; Twitter:string }
[<CLIMutable>]
type Knows = { How:string }
[<EntryPoint>]
let main argv =
let client = new GraphClient(new Uri("http://localhost.:7474/db/data"));
client.Connect();
let createPerson person =
client.Cypher
.Create("(p:Person {param})")
.WithParam("param", person)
.Return<Person>("p")
.Results
.Single()
let pA = createPerson { Name = "PersonA"; Twitter = "tA" }
let pB = createPerson { Name = "PersonB"; Twitter = "tB" }
let pC = createPerson { Name = "PersonC"; Twitter = "tC" }
let pD = createPerson { Name = "PersonD"; Twitter = "tD" }
let follows target source =
client.Cypher
.Match("(s:Person)", "(t:Person)")
.Where(fun s -> s.Twitter = source.Twitter)
.AndWhere(fun t -> t.Twitter = target.Twitter)
.CreateUnique("s-[:follows]->t")
.ExecuteWithoutResults()
pB |> follows pA
pC |> follows pA
pD |> follows pB
pD |> follows pC
let knows target (details : Knows) source =
client.Cypher
.Match("(s:Person)", "(t:Person)")
.Where(fun s -> s.Twitter = source.Twitter)
.AndWhere(fun t -> t.Twitter = target.Twitter)
.CreateUnique("s-[:knows {knowsData}]->t")
.WithParam("knowsData", details)
.ExecuteWithoutResults()
pB |> knows pC {How = "colleagues"}
let createExpression quotationExpression = LeafExpressionConverter.QuotationToLambdaExpression quotationExpression
//let resultExpression = createExpression <@ Func<ICypherResultItem, Person>(fun (e : Cypher.ICypherResultItem) -> e.As<Person>()) @>
let pAfollowers =
client.Cypher
.Match("n<-[:follows]-e")
.Where(fun n -> n.Twitter = "tA")
.Return(createExpression <@ Func<ICypherResultItem, Person>(fun (e : Cypher.ICypherResultItem) -> e.As<Person>()) @>)
//.Return(resultExpression)
.Results
.Select(fun x -> x.Name)
for follower in pAfollowers do
printfn "%s" follower
0 // return an integer exit code
@n074v41l4bl34u
Copy link

You can replace:

.Return(createExpression <@ Func<ICypherResultItem, Person>(fun (e : Cypher.ICypherResultItem) -> e.As()) @>)
//.Return(resultExpression)
.Results
.Select(fun x -> x.Name)

with just:

.Return(fun (e : Cypher.ICypherResultItem) -> e.As().Name)
.Results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment