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 /
Last active Nov 13, 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 Nov 13, 2019
Delimited Continuations
yelouafi /
Last active Nov 13, 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

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) {
yelouafi /
Last active Oct 26, 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)
yelouafi / abort.js
Last active Sep 6, 2018
callcc with javascript generators
View abort.js
function*example() {
const x = 10
const y = yield callcc(function*(k) {
// ...
yield k(20)
throw "Unreachable code"
console.log(x + y)

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 / App.js
Last active Jul 19, 2017
put your react component in a closure
View App.js
import React from 'react';
import reclass from './reclass';
import Greeter from './Greeter';
function App(ctx) {
ctx.state = { civility: 'Mr.' };
function changeCivility(e) {
ctx.setState({ civility: });
yelouafi / SimpleSagaMiddleware.html
Last active Mar 12, 2017
A simplified implementation of redux-saga middleware
View SimpleSagaMiddleware.html
<!doctype html>
<html lang="en">
const sagaMiddleware = store => gen => {
var resolve, reject
var done = new Promise((res, rej) => {
resolve = res
You can’t perform that action at this time.