Skip to content

Instantly share code, notes, and snippets.

View CraftyFella's full-sized avatar

Dave Craft CraftyFella

View GitHub Profile
// See https://aka.ms/new-console-template for more information
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
public static class Program
{
public static void Main(string[] args)
{
var build = CreateHostBuilder(args).Build();
@CraftyFella
CraftyFella / csharpchallenge.cs
Last active November 16, 2021 20:33
try and write chsarp in an fsharp style
using System;
// Trying to replicate https://github.com/ijrussell/FSharpForTheMasses/blob/main/IntroductionToFSharp/4-demo-ddd-3.fsx
namespace csharpchallenge
{
record EligibleRegisteredCustomer(string Name, string Email) : Customer;
record RegisteredCustomer(string CustomerName, string? Email) : Customer;
record UnregisteredCustomer(string Name) : Customer;
@CraftyFella
CraftyFella / marten.cs
Last active July 22, 2021 15:23
Marten.cs
public abstract record StreamName;
public record AnEvent(string Description) : StreamName;
public static class DocumentStoreFactory
{
public static DocumentStore Create()
{
const string connectionString =
"PORT = 5432; HOST = 127.0.0.1; TIMEOUT = 15; POOLING = True; MINPOOLSIZE = 1; MAXPOOLSIZE = 100; COMMANDTIMEOUT = 20; DATABASE = 'postgres'; PASSWORD = 'Password12!'; USER ID = 'postgres'";
var store = DocumentStore.For(options =>
{
open FParsec
let ws = spaces
let str_ws s = pstring s >>. ws
[<RequireQualifiedAccess>]
type QueryComparison =
| Equal
| NotEqual
open FParsec
[<RequireQualifiedAccess>]
type QueryComparison =
| Equal
| NotEqual
[<RequireQualifiedAccess>]
type TableOperators =
| And
@CraftyFella
CraftyFella / FParsec.fs
Created October 19, 2020 15:06
Issue with FParsec
open FParsec
[<RequireQualifiedAccess>]
type QueryComparison =
| Equal
| NotEqual
[<RequireQualifiedAccess>]
type TableOperators =
| And
open Domain
let awardPoint player state =
let result = Domain.awardPoint state player
printfn "Point to %A. Game is now %A" player result.Score
result
[<EntryPoint>]
let main argv =
let player1 = "Foo"
@CraftyFella
CraftyFella / Program1.cs
Created June 29, 2020 11:45
Map and Bind in csharp with Option.
using System;
namespace ConsoleApp1
{
public class Option<T>
{
private bool hasValue;
private T value;
@CraftyFella
CraftyFella / Program1.cs
Created June 29, 2020 11:45
Map and Bind in csharp with Option.
using System;
namespace ConsoleApp1
{
public class Option<T>
{
private bool hasValue;
private T value;
type Person =
{ FirstName: string
MiddleInitial: string option
LastName: string }
module String50 =
let create (thing: string) =
if thing = null then Error "Its null" else Ok thing
module Result =