Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Learn more about F# at http://fsharp.org
- // See the 'F# Tutorial' project for more help.
- open LiteDB
- module Db=
- let db=new LiteDatabase("data.db")
- type Data={Id:string}
- let find<'a> (predicate:'a->bool) (col:LiteCollection<'a>)= let res=col.Find predicate
- match res|>Seq.isEmpty with
- |true->None
- |false->Some (res|>Seq.head)
- let col=db.GetCollection<Data>("data")
- type Message=Find of (Data->bool)*AsyncReplyChannel<Data option>
- let inbox=MailboxProcessor.Start(fun box->let rec loop()=
- async{
- let! msg=box.Receive()
- match msg with
- |Find (p,rc)->find p col|>rc.Reply
- }
- loop()
- )
- type Api={Find:(Data->bool)->Data option}
- let instance={Find=(fun p->inbox.PostAndReply(fun rc->Find(p,rc)))}
- [<EntryPoint>]
- let main argv =
- printfn "%A" argv
- let a=instance.Find(fun d->true)
- 0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement