Skip to content

Instantly share code, notes, and snippets.

View tjaskula's full-sized avatar
🎸
C++

Tomasz Jaskula tjaskula

🎸
C++
View GitHub Profile
@tjaskula
tjaskula / Fiber.fs
Created March 31, 2020 10:26 — forked from Horusiath/Fiber.fs
Custom fibers implementation in F#
open System
open System.Threading
type FiberResult<'a> = Result<'a, exn> option
[<Sealed;AllowNullLiteral>]
type Cancel(parent: Cancel) =
let mutable flag: int = 0
let mutable children: Cancel list = []
new() = Cancel(null)
@tjaskula
tjaskula / Fibers.cs
Created March 8, 2020 23:06 — forked from Horusiath/Fibers.cs
Minimal example of working async method builder
using System;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Threading;
namespace Fibers
{
public struct AsyncFiberMethodBuilder<T>
{
private Fiber<T>? fiber;
f(events) -> state
match f(state, event) -> state
f(state, command) -> events

Recursion and Trampolines in Scala

Recursion is beautiful. As an example, let's consider this perfectly acceptable example of defining the functions even and odd in Scala, whose semantics you can guess:

def even(i: Int): Boolean = i match {
  case 0 => true
  case _ => odd(i - 1)
}

def odd(i: Int): Boolean = i match {

@tjaskula
tjaskula / NesGateway.fs
Created May 7, 2017 13:42 — forked from bartelink/NesGateway.fs
Dump of ProtoBuf serialization spike for http://github.com/bartelink/FunDomain
module FunDomain.Persistence.NEventStore.NesGateway
open FunDomain.Persistence.Serialization
open NEventStore
open NEventStore.Persistence
open NEventStore.Persistence.Sql.SqlDialects
open Microsoft.FSharp.Reflection
open System
// Udi style w Static Domain Events
var dispatcher = new RecordingDomainEventsDispatcher();
DomainEvents.Dispatcher = dispatcher;
var customer = new Customer(new Address());
customer.Move(new Address());
Console.WriteLine("Customer moved: " + dispatcher.RecordedDomainEvent(new CustomerMoved()));