Skip to content

Instantly share code, notes, and snippets.

@artur-s
artur-s / ReaderAndFreeM.fsx
Last active March 18, 2019 04:19
Monadic DI: Reader and Free
// Monadic DI: Reader and Free monad
// https://www.youtube.com/watch?v=ZasXwtTRkio
module Reader =
type Reader<'d, 'a> = {Apply:('d -> 'a)}
let reader f = {Reader.Apply = f}
let (|Reader|) ({Reader.Apply = apply}) = apply
@artur-s
artur-s / memoizedYcombinator.csx
Last active October 11, 2020 21:36
A non-recursive implementation of Y-combinator with memoization in C#
// non-recursive implementation of Y-combinator, based on example from https://en.wikipedia.org/wiki/Fixed-point_combinator#Type_for_the_Y_combinator
// with memoization
using System;
using System.Diagnostics;
using System.Collections.Concurrent;
//type 'a Recc = In of ('a Recc -> 'a)
@artur-s
artur-s / scanLeftUsingFoldAndMap.fs
Created November 6, 2021 23:18
`scanLeft` in terms of `fold` and `map`
let scanLeft (s:'s) (f:'s -> 'a -> 's) (lst:'a list) : 's list =
lst
|> List.mapi (fun i _ ->
lst
|> List.take i
|> List.fold f s )
@artur-s
artur-s / 01.fsx
Last active December 20, 2021 06:09
AoC2021
// https://adventofcode.com/2021
let readings =
[|
199
227
229
|]
// part1