This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unlike Suave bind format, the idea is that the handlers execute as pre-applied continuations, with the added benefit of | |
// allowing sync operations to be executed in a handler with no addional and wasteful async/task wrappers as the async/task | |
// of the subsequent succ/fail Continuation that is called can be returned, passed directly through, unlike bind | |
open System | |
open System.Text | |
open System.Threading.Tasks | |
open System.Collections.Generic | |
open Microsoft.AspNetCore.Http |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let bind (handler : HttpHandler) = | |
fun (result : HttpHandlerResult) -> | |
async { | |
let! ctxOpt = result | |
match ctxOpt with | |
| None -> return None | |
| Some ctx -> | |
match ctx.Response.HasStarted with | |
| true -> return Some ctx | |
| false -> return! handler ctx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// given a string path, return succssfull Some of HttpContext for binding | |
let route (path : string) = | |
fun (ctx : HttpContext) -> | |
if (getPath ctx).Equals path | |
then Some ctx | |
else None | |
|> async.Return | |
// given a list of handlers, itterate through list until a pipeline returns succssfull Some of HttpContext for binding | |
let rec choose (handlers : HttpHandler list) = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type HttpHandlerResult = Task<HttpContext option> // same as previous | |
type HttpCont = HttpContext -> HttpHandlerResult // continuation same as previous HttpHandler | |
type HttpHandler = HttpCont -> HttpContext -> HttpHandlerResult // (HttpCont -> HttpCont) : Handler now has two input parameters | |
let compose (handler : HttpHandler) (handler2 : HttpHandler) : HttpHandler = | |
fun (next:HttpCont) (ctx : HttpContext) -> | |
// 1. last next will ultimately be a (fun ctx -> Some ctx) but allows to compose / short circuit with continuations | |
// 2. We can apply next function at load so all handlers have thier next function refs and need only apply ctx on run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type GiraffeMiddleware (next : RequestDelegate, | |
handler : HttpHandler, | |
loggerFactory : ILoggerFactory) = | |
member __.Invoke (ctx : HttpContext) = | |
task { | |
let finalNext = (fun ctx -> task { Some ctx } ) | |
let! result = handler finalNext ctx | |
if (result.IsNone) then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let route (path : string) : HttpHandler = | |
fun Some' ctx -> | |
if (getPath ctx).Equals path | |
then Some' ctx | |
else Task.FromResult None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace CRUDSample | |
open System.IO | |
open NPoco | |
open Microsoft.Data.Sqlite | |
type LunchSpot() = | |
member val ID = 0 with get, set | |
member val Name = "" with get, set | |
member val Latitude = 0.0 with get, set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string func6 = "DelaySign"; | |
fsharpFunc2.Invoke((FSharpFunc<bool, Unit>) new FakeMsbuildTasks.getResponseFileFromTask\u004054\u002D5<a>(fsc)).Invoke(func6); | |
string func7 = "DisabledWarnings"; | |
fsharpFunc1.Invoke((FSharpFunc<string, Unit>) new FakeMsbuildTasks.getResponseFileFromTask\u004055\u002D6<a>(fsc)).Invoke(func7); | |
FSharpFunc<FSharpFunc<string, Unit>, FSharpFunc<string, Unit>> fsharpFunc1 = (FSharpFunc<FSharpFunc<string, Unit>, FSharpFunc<string, Unit>>) new FakeMsbuildTasks.bind\u004026(prop); | |
FSharpFunc<FSharpFunc<bool, Unit>, FSharpFunc<string, Unit>> fsharpFunc2 = (FSharpFunc<FSharpFunc<bool, Unit>, FSharpFunc<string, Unit>>) new FakeMsbuildTasks.bindBool\u004028(prop);``` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module App = | |
////////////////// | |
type Zapp<'T> = State<'T> -> unit // Zapp<'T> is temporary name for Zebra function handler | |
type DepContainer = { | |
Name :string | |
} | |
type Person = { | |
Name:string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ValueOption<'T> = | |
struct | |
val HasValue : bool | |
val Value: 'T | |
new(a,b) = {HasValue = a; Value = b} | |
end | |
let inline VSome v = ValueOption<_>(true,v) | |
let inline VNone () = ValueOption<'T>(false,Unchecked.defaultof<'T>) | |
type Parse = Parse with |
OlderNewer