Skip to content

Instantly share code, notes, and snippets.

View michael-newton-15below's full-sized avatar

Michael Newton michael-newton-15below

View GitHub Profile
@michael-newton-15below
michael-newton-15below / build.fsx
Created February 13, 2013 13:23
Literate build.fsx
(**
## References
As they aren't part of a project, fsx files need
to reference all of their dependencies within the
file.
You'll always want to reference FakeLib. VersionUpdater
is an inhouse tool we use for handling feature branch
@michael-newton-15below
michael-newton-15below / build.fsx
Created February 13, 2013 13:20
Literate build file.
(**
## References
As they aren't part of a project, fsx files need
to reference all of their dependencies within the
file.
You'll always want to reference FakeLib. VersionUpdater
is an inhouse tool we use for handling feature branch
@michael-newton-15below
michael-newton-15below / Interval.fs
Created January 22, 2013 15:52
Adaptive polling interval
let interval i =
let x = float i
let maxWait = 60. * 10.
let raisePower x = pown (x /10.) 4
(maxWait * (raisePower x)) / (raisePower x + 1.)
|> (*) 1000. |> int
@michael-newton-15below
michael-newton-15below / AuditedCode.fs
Last active December 11, 2015 07:19
Example audit { }
let agent =
AutoCancelAgent.Start(fun inbox -> async {
while true do
audit {
use! client = audit { return getClient () }
Log "Checking email..."
do! audit { return CollectMessages client }
expunge client
} |> doAuditedProcess
do! Async.Sleep(match pollInterval with Interval s -> s)
@michael-newton-15below
michael-newton-15below / correctedTestBuilder.fs
Created January 18, 2013 16:31
Corrected builder implementation to use a lazy continuation style computational expression.
type TestErrorBuilder () =
member this.Bind (expr, func) =
try
match expr () with
| None -> fun () -> None
| Some r ->
func r
with
| _ as e ->
printfn "%A" e
@michael-newton-15below
michael-newton-15below / correctedInterfaces.fs
Created January 18, 2013 16:29
Corrected error handling interface and helper types/functions
open System
type AuditedProcess<'T> = unit -> Option<'T>
let runAuditedProcess (auditedProcess : AuditedProcess<_>) =
auditedProcess ()
let doAuditedProcess (auditedProcess : AuditedProcess<_>) =
runAuditedProcess auditedProcess |> ignore
@michael-newton-15below
michael-newton-15below / DecomposeUse.fs
Last active December 11, 2015 05:09
Decompose error handling computation expression with use
// Our basic cexpr, fully sugared
let calculate input =
audit {
use! thing = Some input
return (possibleGoWrongThing thing)
}
// Rest of this might not be valid f# code at every step.
// Expanding using documentation at http://msdn.microsoft.com/en-us/library/dd233182.aspx
@michael-newton-15below
michael-newton-15below / Decompose.fs
Created January 16, 2013 20:00
Decomposing error handling computational expression without use
// Our builder
type TestErrorBuilder () =
member this.Bind (expr, func) =
match expr with
| None -> None
| Some r ->
try func r
with
| _ as e ->
printfn "%A" e
@michael-newton-15below
michael-newton-15below / ExampleService.fs
Created January 14, 2013 21:20
Error handler builder usage
open EasyNetQ
type IService =
abstract member Start : unit -> unit
type Service (log : ILog, bus : IBus, indexer : IIndex, audit : IErrorHandlerBuilder) =
member this.Start () =
bus.Subscribe<PasngrEmail>("Archive",
fun (email : PasngrEmail) ->
audit {
@michael-newton-15below
michael-newton-15below / TestErrorBuilder.fs
Created January 14, 2013 21:13
Test error handler builder
type TestErrorBuilder () =
member this.Bind (expr, func) =
match expr with
| None -> None
| Some r ->
try func r
with
| _ as e ->
printfn "%A" e
None