Skip to content

Instantly share code, notes, and snippets.

(*
WHAT'S GOING ON HERE?!
Sometimes you don't care about a particular type, you're interested in one field only, let's say `EntityId`.
Instead of using interface (which isn't even possible if don't own a type),
we can do structural typing in F# using SRTP and Active Patterns.
Active patterns are not required for this, but they do make code much easier to use.
*)
// So we have 2 types with field `EntityId: string`:
@atsapura
atsapura / TestInterpreter.fs
Last active June 20, 2019 13:14
Mocking interpreter for testing execution trees
module TestingInterpreter =
open CardManagement
open System
open CardDomain
open CardManagement.Common.Errors
open CardManagement.Common.CommonTypes
open CardManagement.Common.CountryModule
open CardProgramBuilder
open CardManagement.Common
[<AutoOpen>]
module PriorityQueue =
[<AutoOpen>]
module private Heap =
type 'a Node =
| Empty
| Node of 'a NodeData
and 'a NodeData =
@atsapura
atsapura / TryParse.fs
Created October 3, 2019 14:04
TryParse shortcut for Int.TryParse, Guid.TryParse etc.
let inline tryParse<'a when 'a: (static member TryParse: string * byref<'a> -> bool)> x =
let mutable res = Unchecked.defaultof<'a>
if (^a: (static member TryParse: string * byref<'a> -> bool) (x, &res))
then Some res
else None
let a = tryParse<int>("19")
let b = tryParse<Guid>("4A9FA193-26D6-4D21-8610-02B060D43744")
let c = tryParse<DateTimeOffset>("ddd")
@atsapura
atsapura / fsharpjobs.md
Created December 20, 2019 10:36 — forked from swlaschin/fsharpjobs.md
My suggestions on how to look for F# jobs

How to find F# jobs

People often ask me how to find F# jobs. I don't have any special connections to companies using F#, and I don't have any special tricks either. I wish I did!

So, given that, here's my take on F# jobs.

Job hunting

For job hunting my suggestions are:

@atsapura
atsapura / fsharpjobs.md
Created December 20, 2019 10:36 — forked from swlaschin/fsharpjobs.md
My suggestions on how to look for F# jobs

How to find F# jobs

People often ask me how to find F# jobs. I don't have any special connections to companies using F#, and I don't have any special tricks either. I wish I did!

So, given that, here's my take on F# jobs.

Job hunting

For job hunting my suggestions are:

@atsapura
atsapura / HexGrid.fs
Created April 14, 2020 11:27
Hex grid using cubical coordinates.
module HexGrid =
[<Struct>]
type HexId =
{
X: int
Y: int
Z: int
}
with
let (|CosmosException|_|) (ex:exn) =
match ex with
| :? DocumentClientException as ex -> Some ex
| :? AggregateException as ex when (ex.InnerException :? DocumentClientException) ->
ex.InnerException :?> DocumentClientException |> Some
| _ -> None
let (|NotFoundInCosmos|_|) ex =
match ex with
| CosmosException ex when (ex.StatusCode = Nullable HttpStatusCode.NotFound) -> Some ex
namespace Fsion
open System.Threading
[<Struct;NoEquality;NoComparison>]
type Cancel =
private
| Cancel of bool ref * children: Cancel list ref
module internal Cancel =
@atsapura
atsapura / AppEnvExample.fs
Created August 4, 2020 13:23
An example of managing application dependencies with `IAppEnv` interface from a real application.
type CosmosDbConfig =
{
Endpoint: string
AuthKey: string
}
type ProductBlobConfig =
{
ConnectionString: string
ContainerName: string