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
open System.Collections.Generic | |
let CHUNK_SIZE = 2048 | |
let INIT_SIZE = 32 | |
[<AllowNullLiteral>] | |
type private CNode<'T>() = | |
let data = Array.zeroCreate<'T> INIT_SIZE | |
member val Tail = Unchecked.defaultof<CNode<'T>> with get, set | |
member val Data = data 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
let MyView model = | |
stackPanel { | |
children [ | |
label { content "FontSize is:" } | |
label { content <@ model.FontSize @> ; fontSize <@ model.FontSize @> } | |
button { | |
content "Increase Font Size" | |
onClick (<@ model.FontSize @> ,fun _ _ -> model.FontSize + 2.) } | |
] | |
} |
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
///////////////// | |
/// My Model defs | |
type SubModel = { | |
mutable Value1:string | |
mutable Counter:int | |
mutable MyRow : int | |
mutable MyCol : int | |
} | |
type MyModel = { |
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 Work = | |
| Idle | |
| Working of cts:CancellationTokenSource | |
let jsonView model = | |
let working = ref Idle | |
button { | |
content "json request" ; | |
onClick (<@ working.Value @>,<@ model.Message @>, fun _ _ (ct:CancellationToken) -> task { | |
use client = new System.Net.Http.HttpClient() |
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
/////////////////// | |
// Model definitions | |
type SubModel = { | |
Value1:Var<string> | |
Counter:Var<int> | |
Visible:Var<Visibility> | |
IsVisible:Var<bool> | |
} | |
type MyModel = { |
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
/// Node Types | |
/// ////////////////// | |
type ChoiceNode<'T>(inext:INode<'T>,ifail:INode<'T>,current:Zapp<'T>) = | |
let mutable next = inext | |
let mutable fail = ifail | |
interface INode<'T> with | |
member __.Next with get () = next and set v = next <- v | |
member __.Fail with get () = fail and set v = fail <- v |
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
member inline x.Zero() = | |
// Zero presumes a true, failing must be explicit, progressing is implicit | |
x.DNode.Next.Apply x | |
member inline x.Return(result: bool) = | |
if result then | |
x.DNode.Next.Apply x // same as `next` | |
else | |
x.DNode.Fail.Apply x // same as 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
type INode<'T> = | |
abstract member Next : INode<'T> with get, set | |
abstract member Fail : INode<'T> with get, set | |
abstract member Apply : State<'T> -> unit | |
and State<'T>(hctx: HttpContext, deps: 'T,amb: AsyncTaskMethodBuilder) = | |
let buffer = MemoryStreamPool.Get() | |
member val MethodBuilder : AsyncTaskMethodBuilder = amb with get | |
member val HttpContext = hctx with get | |
member val Dependencies = deps with get // alternative typed basic dependency injection system |
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
member inline x.Bind(taskLike:^abl, continuation : ^inp -> unit) : unit = | |
let awt = (^abl : (member GetAwaiter : unit -> TaskAwaiter< ^inp>)(taskLike)) | |
if awt.IsCompleted then | |
continuation (awt.GetResult()) | |
else | |
let mutable awtref <- awt | |
let mutable smref <- GenericStateAwaiter< ^inp>(awt,continuation,x.MethodBuilder) | |
x.MethodBuilder.AwaitUnsafeOnCompleted(&awtref,&smref) |
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 bindTask (task : 'a Task) (continuation : 'a -> Step<'b>) = | |
let awt = task.GetAwaiter() | |
if awt.IsCompleted then // Proceed to the next step based on the result we already have. | |
continuation(awt.GetResult()) | |
else // Await and continue later when a result is available. | |
Await (awt, (fun () -> continuation(awt.GetResult()))) | |
NewerOlder