Skip to content

Instantly share code, notes, and snippets.

Yassine Elouafi yelouafi

Block or report user

Report or block yelouafi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
yelouafi / multishot-callcc.js
Created Sep 21, 2018
multi shot continuations
View multishot-callcc.js
function isGenerator(x) {
return x != null && typeof === "function"
function isFrame(x) {
return x != null && x._type_ === 'call_frame'
function call(genFunc, ...args) {

In this tutorial we're going to build a set of parser combinators.

What is a parser combinator?

We'll answer the above question in 2 steps

  1. what is a parser?
  2. and.. what is a parser combinator?

So first question: What is parser?

yelouafi /
Last active Jul 24, 2019
Implementing Algebraic Effects and Handlers

Algebraic Effects in JavaScript part 4 - Implementing Algebraic Effects and Handlers

This is the final part of a series about Algebraic Effects and Handlers.

So we've come to the core topic. The reality is that we've already covered most of it in the previous parts. Especially, in the third part, where we saw delimited continuations at work.

yelouafi /
Last active Jul 22, 2019
Operational Introduction to Algebraic Effects and Continuations

Algebraic Effects in JavaScript part 1 - continuations and control transfer

This is the first post of a series about Algebraic Effects and Handlers.

There are 2 ways to approach this topic:

  • Denotational: explain Algebraic Effects in terms of their meaning in mathematics/Category theory
  • Operational: explain the mechanic of Algebraic Effects by showing how they operate under a chosen runtime environment

Both approaches are valuables and give different insights on the topic. However, not everyone (including me), has the prerequisites to grasp the concepts of Category theory and Abstract Algebra. On the other hand, the operational approach is accessible to a much wider audience of programmers even if it doesn't provide the full picture.

yelouafi / delimited-continuations.js
Last active Jul 9, 2019
delimited continuations using javascript generators
View delimited-continuations.js
// We model the call stack using a linked list of Generators
// Each Generator has a _return field pointing back to its parent
function stepGen(gen, arg) {
const {done, value} =
if(done) {
if(gen._return) {
stepGen(gen._return, value)


In Redux, reducer composition with combineReducers offers a powerful way to handle complex update logic of an application. A reducer can encapsulate all the ways a part of the state is mutated because it can react to multiple types of actions.

But in some cases there is also a need for another type of factoring: often the update logic is simple (for example setting a single value), and the there are many places in the state shape where the update logic is the same.

View data-driven.js
// Getter a :: () -> a
// gmap :: ((a -> b), Getter a), Getter b
function gmap(fn, getter) {
return () => fn(getter())
// gcombine2 :: ((a,b) -> c, Getter a, Getter ab) -> Getter c
function gcombine2(fn, getter1, getter2) {
View adt.js
function eachKey(obj, f) {
for(var key in obj) {
if( obj.hasOwnProperty(key) )
f(key, obj[key]);
function adtcase (base, proto, key) {
return (...args) => {
var inst = new base();
yelouafi /
Last active Mar 19, 2019
Capturing continuations with Generators

Algebraic Effects in JavaScript part 2 - Capturing continuations with Generators

This is the second part of a series about Algebraic Effects and Handlers.

Note: initially I planned a 3-part series, but since the current post on undelimited continuations ended up taking

You can’t perform that action at this time.