Advertisement
Guest User

Untitled

a guest
May 28th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.41 KB | None | 0 0
  1. // Learn more about F# at http://fsharp.org
  2. // See the 'F# Tutorial' project for more help.
  3. open LiteDB
  4. module Db=
  5.  let db=new LiteDatabase("data.db")
  6.  type Data={Id:string}
  7.  let find<'a> (predicate:'a->bool) (col:LiteCollection<'a>)= let res=col.Find predicate
  8.                                                             match res|>Seq.isEmpty with
  9.                                                             |true->None
  10.                                                             |false->Some (res|>Seq.head)
  11.  
  12. let col=db.GetCollection<Data>("data")
  13. type Message=Find of (Data->bool)*AsyncReplyChannel<Data option>                                              
  14. let inbox=MailboxProcessor.Start(fun box->let rec loop()=
  15.                                            async{
  16.                                             let! msg=box.Receive()
  17.                                             match msg with
  18.                                             |Find (p,rc)->find p col|>rc.Reply
  19.                                            
  20.                                            }
  21.                                           loop()
  22.                                 )
  23. type Api={Find:(Data->bool)->Data option}
  24. let instance={Find=(fun p->inbox.PostAndReply(fun rc->Find(p,rc)))}
  25. [<EntryPoint>]
  26. let main argv =
  27.        printfn "%A" argv
  28.        let a=instance.Find(fun d->true)
  29.        0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement