Skip to content

Instantly share code, notes, and snippets.

View essenmitsosse's full-sized avatar
🌿

Marcus Blättermann essenmitsosse

🌿
View GitHub Profile
@OliverJAsh
OliverJAsh / foo.ts
Last active August 11, 2024 16:19
Records and dictionaries in TypeScript
/*
In JavaScript, objects can be used to serve various purposes.
To maximise our usage of the type system, we should assign different types to our objects depending
on the desired purpose.
In this blog post I will clarify two common purposes for objects known as records and dictionaries
(aka maps), and how they can both be used with regards to the type system.
@dtipson
dtipson / cellular automata with quasi-comonads.js
Last active November 9, 2021 14:41
Using a comonad(ish) pattern to create cellular automata in a more functional way. Inspired by this episode of funfunfunction: https://www.youtube.com/watch?v=bc-fVdbjAwk
/*
Native Arrays are not great structures for cellular automata.
Non-empty, circular, doubly-linked lists would be ideal...
but all we really need to do is write a comonadic-like interface
such that it _pretends_ that the array is circular, and can thus
pass the exfn below a sort of "local" slice of an Array as if it were circular.
So you can mostly ignore the implementation mess below
*/
Array.prototype.extendNear = function(exfn){
const len = this.length;