Skip to content

Instantly share code, notes, and snippets.

View Steven24K's full-sized avatar
🤹‍♂️
Enjoying life

Steven Steven24K

🤹‍♂️
Enjoying life
View GitHub Profile
@Steven24K
Steven24K / ForceDirectedGraph.ts
Created March 26, 2020 14:38
A Force directed graph layouting algorithm based on Fruchterman and Reingold's principle, written in Typescript.
/**
* Force directed graph layout algorithm according to Fruchterman and Reingold's principle.
* The algorithm can be summarized as follows:
* algorithm SPRING(G:graph);
* place vertices of G in random locations;
* repeat N times
* calculate the force on each vertex;
* move the vertex c4
* draw graph on canvas, plotter or any drawing tool.
*
@Steven24K
Steven24K / Fun.ts
Created March 4, 2020 08:24
Monadic operators for category theory
export interface Func<a, b> {
f: (_: a) => b
then: <c>(this: Func<a, b>, g: Func<b, c>) => Func<a, c>
repeat: (this: Func<a, a>) => Func<number, Func<a, a>>
repeatUntil: (this: Func<a, a>) => Func<Func<a, boolean>, Func<a, a>>
}
export let Func = <a, b>(f: (_: a) => b): Func<a, b> => {
return {
f: f,