1 people like it.
Like the snippet!
OminaisuusStorage-testi
Korjasin modulen P:n olemaan isolla... :-)
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:
53:
54:
|
module AripekanKuutioJuttu
// Tästä lähtien toimii interactivessa, voi testailla:
open System
type Entiteetti(nimi:string) =
member x.Nimi = nimi
type Ominaisuus = string
type StorageMethods =
| LisääEntiteetti of Ominaisuus * Entiteetti
| HaeEntiteetit of Ominaisuus * AsyncReplyChannel<Entiteetti list>
type OminaisuusStorage() =
let ominaisuusstorage = MailboxProcessor.Start(fun komento ->
let rec msgPassing kaikki =
async { let! k = komento.Receive()
match k with
| LisääEntiteetti(ominaisuus, entiteetti) ->
return! msgPassing((ominaisuus, entiteetti) :: kaikki)
| HaeEntiteetit(haettuOminaisuus, reply) ->
let entiteetit =
kaikki
|> List.filter(fun i -> fst i = haettuOminaisuus)
|> List.map(fun i -> snd i)
reply.Reply(entiteetit)
return! msgPassing(kaikki)
}
msgPassing [])
member x.Save (entiteetti) =
ominaisuusstorage.Post(LisääEntiteetti(entiteetti))
"saved"
member x.Get id =
ominaisuusstorage.PostAndReply(fun rep -> HaeEntiteetit(id,rep))
|> List.rev
// Tests for Interactive:
let storage = new OminaisuusStorage()
let ent1 = new Entiteetti("A")
let ent2 = new Entiteetti("B")
storage.Save("Lukutaito", ent1) |> ignore
storage.Save("Lukutaito", ent2) |> ignore
storage.Save("Kirjoitustaito", ent1) |> ignore
storage.Get("Lukutaito")
|
module AripekanKuutioJuttu
namespace System
Multiple items
type Entiteetti =
new : nimi:string -> Entiteetti
member Nimi : string
Full name: AripekanKuutioJuttu.Entiteetti
--------------------
new : nimi:string -> Entiteetti
val nimi : string
Multiple items
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = String
Full name: Microsoft.FSharp.Core.string
val x : Entiteetti
member Entiteetti.Nimi : string
Full name: AripekanKuutioJuttu.Entiteetti.Nimi
type Ominaisuus = string
Full name: AripekanKuutioJuttu.Ominaisuus
type StorageMethods =
| LisääEntiteetti of Ominaisuus * Entiteetti
| HaeEntiteetit of Ominaisuus * AsyncReplyChannel<Entiteetti list>
Full name: AripekanKuutioJuttu.StorageMethods
union case StorageMethods.LisääEntiteetti: Ominaisuus * Entiteetti -> StorageMethods
union case StorageMethods.HaeEntiteetit: Ominaisuus * AsyncReplyChannel<Entiteetti list> -> StorageMethods
type AsyncReplyChannel<'Reply>
member Reply : value:'Reply -> unit
Full name: Microsoft.FSharp.Control.AsyncReplyChannel<_>
type 'T list = List<'T>
Full name: Microsoft.FSharp.Collections.list<_>
Multiple items
type OminaisuusStorage =
new : unit -> OminaisuusStorage
member Get : id:Ominaisuus -> Entiteetti list
member Save : entiteetti:(Ominaisuus * Entiteetti) -> string
Full name: AripekanKuutioJuttu.OminaisuusStorage
--------------------
new : unit -> OminaisuusStorage
val ominaisuusstorage : MailboxProcessor<StorageMethods>
Multiple items
type MailboxProcessor<'Msg> =
interface IDisposable
new : body:(MailboxProcessor<'Msg> -> Async<unit>) * ?cancellationToken:CancellationToken -> MailboxProcessor<'Msg>
member Post : message:'Msg -> unit
member PostAndAsyncReply : buildMessage:(AsyncReplyChannel<'Reply> -> 'Msg) * ?timeout:int -> Async<'Reply>
member PostAndReply : buildMessage:(AsyncReplyChannel<'Reply> -> 'Msg) * ?timeout:int -> 'Reply
member PostAndTryAsyncReply : buildMessage:(AsyncReplyChannel<'Reply> -> 'Msg) * ?timeout:int -> Async<'Reply option>
member Receive : ?timeout:int -> Async<'Msg>
member Scan : scanner:('Msg -> Async<'T> option) * ?timeout:int -> Async<'T>
member Start : unit -> unit
member TryPostAndReply : buildMessage:(AsyncReplyChannel<'Reply> -> 'Msg) * ?timeout:int -> 'Reply option
...
Full name: Microsoft.FSharp.Control.MailboxProcessor<_>
--------------------
new : body:(MailboxProcessor<'Msg> -> Async<unit>) * ?cancellationToken:Threading.CancellationToken -> MailboxProcessor<'Msg>
static member MailboxProcessor.Start : body:(MailboxProcessor<'Msg> -> Async<unit>) * ?cancellationToken:Threading.CancellationToken -> MailboxProcessor<'Msg>
val komento : MailboxProcessor<StorageMethods>
val msgPassing : ((Ominaisuus * Entiteetti) list -> Async<'a>)
val kaikki : (Ominaisuus * Entiteetti) list
val async : AsyncBuilder
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.async
val k : StorageMethods
member MailboxProcessor.Receive : ?timeout:int -> Async<'Msg>
val ominaisuus : Ominaisuus
val entiteetti : Entiteetti
val haettuOminaisuus : Ominaisuus
val reply : AsyncReplyChannel<Entiteetti list>
val entiteetit : Entiteetti list
Multiple items
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
val filter : predicate:('T -> bool) -> list:'T list -> 'T list
Full name: Microsoft.FSharp.Collections.List.filter
val i : Ominaisuus * Entiteetti
val fst : tuple:('T1 * 'T2) -> 'T1
Full name: Microsoft.FSharp.Core.Operators.fst
val map : mapping:('T -> 'U) -> list:'T list -> 'U list
Full name: Microsoft.FSharp.Collections.List.map
val snd : tuple:('T1 * 'T2) -> 'T2
Full name: Microsoft.FSharp.Core.Operators.snd
member AsyncReplyChannel.Reply : value:'Reply -> unit
val x : OminaisuusStorage
member OminaisuusStorage.Save : entiteetti:(Ominaisuus * Entiteetti) -> string
Full name: AripekanKuutioJuttu.OminaisuusStorage.Save
val entiteetti : Ominaisuus * Entiteetti
member MailboxProcessor.Post : message:'Msg -> unit
member OminaisuusStorage.Get : id:Ominaisuus -> Entiteetti list
Full name: AripekanKuutioJuttu.OminaisuusStorage.Get
val id : Ominaisuus
member MailboxProcessor.PostAndReply : buildMessage:(AsyncReplyChannel<'Reply> -> 'Msg) * ?timeout:int -> 'Reply
val rep : AsyncReplyChannel<Entiteetti list>
val rev : list:'T list -> 'T list
Full name: Microsoft.FSharp.Collections.List.rev
val storage : OminaisuusStorage
Full name: AripekanKuutioJuttu.storage
val ent1 : Entiteetti
Full name: AripekanKuutioJuttu.ent1
val ent2 : Entiteetti
Full name: AripekanKuutioJuttu.ent2
member OminaisuusStorage.Save : entiteetti:(Ominaisuus * Entiteetti) -> string
val ignore : value:'T -> unit
Full name: Microsoft.FSharp.Core.Operators.ignore
member OminaisuusStorage.Get : id:Ominaisuus -> Entiteetti list
More information