Skip to content

Instantly share code, notes, and snippets.

View semmel's full-sized avatar

Matthias Seemann semmel

View GitHub Profile
@semmel
semmel / the_wheel.ts
Last active November 20, 2025 17:17
In a world without Ramda and fp-ts we have to reinvent them
// :: ((l, r) -> s) -> [l, r] -> s
const applyBin =
<L, R, S>(fn: (l: L, r: R) => S) =>
([l, r]: [L, R]): S =>
fn(l, r);
// :: number -> (number, number) -> [number]
const range = (step: number) => (start: number, stop: number) =>
Array.from(
{ length: Math.ceil((stop - start) / step) },
@semmel
semmel / rxjs_vs_most.md
Last active April 14, 2026 17:01
RxJS vs. @most/core

Differences between RxJS and @most/core

RxJs @most/core Remarks Rx.NET
Creation
from(px) fromPromise(px) :: Promise x → S x .ToObservable(), Observable.FromAsync
of(x) now(x) :: x → S x Return(x)
EMPTY or of() empty() EMPTY :: S *, empty :: () → S * Empty()
throwError :: Error → S void Observable.Throw(ex)
bindCallback((cb) =&gt; {})() never() :: () → S *
@semmel
semmel / parallel_task_pool_comparison.ts
Last active November 11, 2025 14:10
Parallelism in Promise (Task) Queues
import * as M from '@most/core';
import { newDefaultScheduler } from '@most/scheduler';
import { pipe } from 'fp-ts/function';
import * as T from 'fp-ts/Task';
import * as A from 'fp-ts/Array';
import { o } from 'ramda';
import {last as lastM } from 'most-last';
import * as Rx from 'rxjs';
const taskReducer = <A>(acc: Promise<A[]>, ta: T.Task<A>) =>
@semmel
semmel / eventStream.test.ts
Created February 21, 2025 10:54
Operations on node:events::EventEmitter
import assert from 'node:assert/strict';
import { filter } from '../src/eventStream';
import { EventEmitter } from 'node:events';
describe("eventStream filter", function() {
const
passPattern = /^great/i,
channelName = "landscape",
filterGreatLandscapes = filter(channelName)((payload: string) => passPattern.test(payload));
@semmel
semmel / StateMachineImplWithSumTypes.md
Created November 18, 2023 19:23
State Machine with Sum/Union Type Libraries for JavaScript
Lib Creation TypeCheck cata Serialisable
[periodo,paldepind/union-type][union-type-gh] Type - [^1]
[JAForbes/sum-type][sum-type-gh]
[fantasyland/daggy][daggy-gh] tagged, taggedSum ✓ [^2]

FSM

action :: State → Args → State

@semmel
semmel / TypeTraversals.md
Last active September 4, 2023 14:49
Rearrange (Applicative or Functor) Types with Ramda

An Applicative type (e.g. a Maybe) is also a Functor with an ap method. Thus, for the observations in the table it can be used everywhere as an example.

Purpose Function Signature Example
swap types inside out sequence(TypeRep f) t (f a) → f (t a)[^1] sequence(M)([Just(1)]) // -> Just [1]
apply effect + wrap inside out traverse(TypeRep f) (a → f b) → t a → f (t b)[^1] traverse(M)(reciprocal, [2]) // -> Just [0.5]
swap data portion type inside out lens(identity) Functor f ⇒ s → f s yLens(identity)({x: 1, y: M.Just(2)}) // -> Just {x:1,y:2}
apply effect to data portion + wrap inside out lens Functor f ⇒ (a → f a) → s a → f (s a) yLens(reciprocal)({x: 1,y: 2}) // -> Just {x:1, y: 0.5}
@semmel
semmel / RamdaAPIByPurpose.md
Last active August 29, 2023 13:29
Ramda API for purpose

Operations[^1] on Collections with Ramda

Purpose List Object Signature(s)
update/insert individual update, assoc*, append, prepend assoc* Idx → a → {k: v} → {k: v}
insert range/collection concat merge* [a] → [a] → [a];{k: v} → {k: v} → {k: v}
retrieve by key/index nth, path, prop prop, path Idx → {a} → a
retrieve many by key/index props
@semmel
semmel / Useful Combinators in Ramda.md
Last active June 18, 2024 17:32
Function Combinators with Ramda

Function Combinators with Ramda

Original Idea comes from [Avaq/combinators.js][avaq].

Name # [Haskell][] [Ramda][] [Crocks][] Functional Signature Functor m ⇒ Function f, g, h Evaluation
identity I id identity identity a → a
constant K const always constant a → b → a
eager application¹ A ($) call
@semmel
semmel / NonInterleavingAsyncSocketWrite.hpp
Last active October 30, 2024 14:19
Synchronize asynchronous writes to a boost.asio socket.
/* Just my current implementation of Sam Miller's answer on Stack Overflow
* @see https://stackoverflow.com/questions/7754695/boost-asio-async-write-how-to-not-interleaving-async-write-calls
*/
/*
* File: NonInterleavingAsyncSocketWrite.hpp
* Author: Matthias Seemann <seemann@visisoft.de>
* @see https://stackoverflow.com/questions/7754695/boost-asio-async-write-how-to-not-interleaving-async-write-calls
*
* When using boost::asio::async_write:
@semmel
semmel / lamda2stdFunc.cpp
Last active January 14, 2017 20:33
Convert a Lambda to std::function e.g. for currying
#include <iostream>
#include <functional>
#include <memory>
#include <iterator>
#include <algorithm>
using namespace std;
template<typename T>
struct memfun_type