rspeele / rezoom Goto Github PK
View Code? Open in Web Editor NEWImplements a resumption monad for .NET targeting data access with automatic batching and caching.
License: MIT License
Implements a resumption monad for .NET targeting data access with automatic batching and caching.
License: MIT License
Here:
Rezoom/src/Rezoom/Execution.fs
Line 147 in 00d4a07
Requiring this to be a type means that in order for the batch type to be initialized with a parameter, it must be represented by a sub-type. Additionally, this could enable a helper function which allows for simple wrapping of all of this. Is there any reason this couldn't be a constructor function instead?
Motivating Example:
open System
open Rezoom
open Rezoom.Execution
type OrgId = OrgId of Guid
with static member MakeOrgId () = OrgId (Guid.NewGuid())
type UserId = UserId of Guid
with static member MakeUserId () = UserId (Guid.NewGuid())
let org1Id = OrgId.MakeOrgId()
let org2Id = OrgId.MakeOrgId()
let orgs = dict [ org1Id, "Org 1"
org2Id, "Org 2" ]
let users = dict [ UserId.MakeUserId(), ("User 1", org1Id )
UserId.MakeUserId(), ("User 2", org1Id )
UserId.MakeUserId(), ("User 3", org1Id )
UserId.MakeUserId(), ("User 4", org1Id )
UserId.MakeUserId(), ("User 5", org1Id )
UserId.MakeUserId(), ("User 6", org2Id )
UserId.MakeUserId(), ("User 7", org2Id )
UserId.MakeUserId(), ("User 8", org2Id )
UserId.MakeUserId(), ("User 9", org2Id )
UserId.MakeUserId(), ("User 10", org2Id ) ]
let getOrg id = orgs.[id]
let getUser id = users.[id]
let getOrgs ids = ids |> Seq.map getOrg
let getUsers ids = ids |> Seq.map getUser
type StepBatch<'a, 'b>(runBatch: 'a seq -> 'b seq) =
let userIds = ResizeArray<'a>()
let batchResults = lazy (runBatch userIds |> Seq.toArray)
member this.AddToBatch(i) =
let index = userIds.Count
userIds.Add(i)
fun () -> batchResults.Value.[index]
let getCache<'a> () =
{ new CacheInfo() with
override this.Category = box typeof<'a>
override this.Identity = box "ignorefornow"
override this.Cacheable = true
override this.DependencyMask = BitMask.Zero
override this.InvalidationMask = BitMask.Zero
}
//can't do this
//type Errand<'a, 'b>(arg : UserId, factory: unit->StepBatch<'a, 'b>) =
// inherit SynchronousErrand<'b>()
//
// override this.CacheInfo = getCache<StepBatch<'a, 'b>> ()
// override this.CacheArgument = box arg
//
// override this.Prepare(context : ServiceContext) =
// let batch = context.GetService<UserStepBatch>(factory)
// batch.AddToBatch arg
//
//type UserErrand(arg: UserId) =
// inherit Errand<UserId, string*OrgId>(arg, fun () -> StepBatch<UserId, string*OrgId>(getUsers) )
//
//type OrgErrand(arg: OrgId) =
// inherit Errand<OrgId, string>(arg, fun () -> StepBatch<OrgId, string>(getOrgs))
//
// Can create as many of these as I want trivially now!
//have to do this instead
type UserStepBatch() = inherit StepBatch<UserId, string*OrgId>(getUsers)
type OrgStepBatch() = inherit StepBatch<OrgId, string>(getOrgs)
type UserErrand(arg : UserId) =
inherit SynchronousErrand<string*OrgId>()
override this.CacheInfo = getCache<UserStepBatch> ()
override this.CacheArgument = box arg
override this.Prepare(context : ServiceContext) =
let batch = context.GetService<StepLocal<UserStepBatch>, UserStepBatch>()
batch.AddToBatch arg
type OrgErrand(arg : OrgId) =
inherit SynchronousErrand<string>()
override this.CacheInfo = getCache<OrgStepBatch> ()
override this.CacheArgument = box arg
override this.Prepare(context : ServiceContext) =
// Get the batch for this execution step.
let batch = context.GetService<StepLocal<OrgStepBatch>, OrgStepBatch>()
// Add ourselves to the batch, return the result getter.
batch.AddToBatch arg
Hi @rspeele
We're interested in moving this to FsProjects as we have contributors doing improvements and trying to use it in production.
Also we'll need you to add the FsProjects account to the nuget.
Please let me know if you agree and I can give you more details about how to proceed.
Thanks !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.