Skip to content

Instantly share code, notes, and snippets.

View AlexeyRaga's full-sized avatar

Alexey Raga AlexeyRaga

  • Arbor Networks
  • Sydney, Australia
View GitHub Profile
@AlexeyRaga
AlexeyRaga / 1 - Either.cs
Created March 7, 2024 14:31
Either in C#
public abstract record Either<TLeft, TRight>
{
// there can be no more cases defined!
private Either() {}
public sealed record Left(TLeft Value) : Either<TLeft, TRight>;
public sealed record Right(TRight Value) : Either<TLeft, TRight>;
}
@AlexeyRaga
AlexeyRaga / 1 - Option.cs
Last active September 6, 2023 08:50
Maybe in C#
public readonly struct Option<T> : IEquatable<Option<T>>
{
private readonly T? _value;
public bool HasValue { get; }
public T Value
{
get
{
@AlexeyRaga
AlexeyRaga / ChatSession.md
Last active February 26, 2023 03:17
ChatGPT: F# Aggregate

Show me an implementation of an Organisation Aggregate in F# that can handle "Register", "Suspend" and "ChangeAddress" commands


Here is a simple implementation of an organization aggregate in F# that can handle the "Register", "Suspend", and "ChangeAddress" commands:

type Address = {
@AlexeyRaga
AlexeyRaga / shell.nix
Last active December 7, 2022 10:02
Nix shell with pinned packages
with import <nixpkgs> {};
let
# a function that takes a descriptive name and a hash of nixpkgs-unstable to pin
# and returns the package from the channel at that version
pinned = name: hash:
let pinnedPkgs =
import
(builtins.fetchGit {
# Descriptive name to make the store path easier to identify
# ...
@AlexeyRaga
AlexeyRaga / OptionLinq.cs
Created August 17, 2022 01:27
LINQ for Option
namespace CSharpTests;
// I know this is ugly and bad encoding of Option
// but it's OK for this demo
public interface Option<T> {}
public record None<T>() : Option<T>;
public record Some<T>(T Value) : Option<T>;
// let's make LINQ work
public static class EnvelopeExtensions
@AlexeyRaga
AlexeyRaga / TestFramework.fs
Created April 17, 2022 12:27
Given-When-Then Test "framework"
[<Microsoft.FSharp.Core.AutoOpen>]
module TestFramework
open EP.EventSourcing.Aggregates
open Xunit
type Given<'Cmd, 'Res> = private Given of 'Cmd * 'Res
type TestBuilder<'State, 'Command, 'Event, 'Error>
( aggregate : Aggregate<'State, 'Command, 'Event, 'Error>,
@AlexeyRaga
AlexeyRaga / 1 - Either.fs
Created January 12, 2022 10:35
Either for dotnet
namespace Prelude.Core
type Either<'TLeft, 'TRight> = Left of 'TLeft | Right of 'TRight
module Either =
let inline either f g value =
match value with
| Left value -> f value
| Right value -> g value
@AlexeyRaga
AlexeyRaga / main.hs
Last active October 29, 2021 10:20
Haskell + JSON with keywords
{-# LANGUAGE DerivingVia, DataKinds, DeriveGeneric, TypeApplications #-}
module Main where
import Control.Lens ((^.))
import Data.Aeson
import Deriving.Aeson
import GHC.Generics (Generic)
import Network.Wreq (Response, asJSON, get, responseBody)
data User = User
open System
open System.Security.Cryptography
open System.Text
[<RequireQualifiedAccess>]
module Guid =
let private hashProvider = SHA1.Create()
let private sha1 (bytes: byte array) = hashProvider.ComputeHash(bytes)
@AlexeyRaga
AlexeyRaga / shell.nix
Created June 21, 2021 12:54
Postgres in Nix shell
with import <nixpkgs> {};
let
pg_root = builtins.toString ./. + "/.postgres";
pg_user = "postgres";
pg_db = "service";
pg_bind = "127.0.0.1";
svc_pg_user = "dev";
svc_pg_password = "changeme";