Skip to content

Instantly share code, notes, and snippets.

View amsterdamharu's full-sized avatar

Harm Meijer amsterdamharu

  • Amsterdam Netherlands
View GitHub Profile
@amsterdamharu
amsterdamharu / partial application.js
Last active March 17, 2021 19:12
partial application
//using partially applied functions (closures) are used for sorting to
// demonstrate how to prevent duplicate implementation and writing
// imperative code. Most of your code should express "what it does"
// not "how it does it"
const data1 = [
{ id: 1, name: 'a', items: [1, 2, 3] },
{ id: 2, name: 'a', items: [1, 2] },
{ id: 3, name: 'b', items: [4, 5] },
{ id: 4, name: 'b', items: [4, 5, 6, 7] },
];
@amsterdamharu
amsterdamharu / useReducer with middleware.js
Last active March 17, 2021 19:12
useReducer with middleware
import React from 'react';
import ReactDOM from 'react-dom';
//for Stack overflow snippet that doesn't allow imports
const { useRef, useState } = React;
const compose = (...fns) =>
fns.reduce((result, fn) => (...args) =>
fn(result(...args))
);
const mw = () => (next) => (action) => next(action);