Skip to content

Instantly share code, notes, and snippets.

@nicuveo
nicuveo / Main.hs
Last active Jan 27, 2022
Minimalistic JSON parser, using a Parsec-like approach
View Main.hs
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
import Control.Applicative (liftA2)
import Data.Char
import Data.Foldable (for_)
import Data.Functor
import qualified Data.HashMap.Strict as M
import Data.List (intercalate)
import Prelude hiding (any)
@karol-majewski
karol-majewski / flatMap.ts
Last active Jan 25, 2022
The simplest flatMap implementation in TypeScript
View flatMap.ts
export function flatMap<T, U>(array: T[], callbackfn: (value: T, index: number, array: T[]) => U[]): U[] {
return Array.prototype.concat(...array.map(callbackfn));
}
@jorgebucaran
jorgebucaran / index.html
Last active Jul 14, 2020
Getting started with Hyperapp
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<script type="module">
import { h, text, app } from "https://unpkg.com/hyperapp"
app({
init: () => 0,
view: state =>
h("main", {}, [
@gcanti
gcanti / fp-ts-technical-overview.md
Last active Apr 17, 2022
fp-ts technical overview
View fp-ts-technical-overview.md

Technical overview

A basic Option type

// Option.ts

// definition
export class None {
 readonly tag: 'None' = 'None'
@vivekhaldar
vivekhaldar / church.js
Created Mar 4, 2016
Church numerals in ES6.
View church.js
//#!/usr/bin/env node --harmony
/*jshint esversion: 6 */
'use strict';
// Church numerals in ES6.
// c.f. https://en.wikipedia.org/wiki/Church_encoding
// Zero is the identity function.
let zero = (f => x => x);
@Avaq
Avaq / combinators.js
Last active May 11, 2022
Common combinators in JavaScript
View combinators.js
const I = x => x
const K = x => y => x
const A = f => x => f (x)
const T = x => f => f (x)
const W = f => x => f (x) (x)
const C = f => y => x => f (x) (y)
const B = f => g => x => f (g (x))
const S = f => g => x => f (x) (g (x))
const S_ = f => g => x => f (g (x)) (x)
const S2 = f => g => h => x => f (g (x)) (h (x))
@Integralist
Integralist / 1. TCO description.md
Last active Jan 20, 2020
JS Tail Call Optimisation
View 1. TCO description.md

The problem

If a function calls itself recursively then the JavaScript engine has to create a new 'stack' (i.e. allocate a chunk of memory) to keep track of the function's arguments.

Let's look at an example of this happening:

function sum(x, y) {
    if (y > 0) {
 return sum(x + 1, y - 1);