Either cata
https://github.com/eu81273/jsfiddle-console
by dimitrs_papadimitriou
HTML
<script src="https://rawgit.com/eu81273/jsfiddle-console/master/console.js"></script>
<script src="https://code.jquery.com/jquery-3.4.0.js"></script>
JavaScript
const right = (v) => ({
map: (f) => right(f(v)),
matchWith: (pattern) => pattern.right(v),
});
const left = (v) => ({
map: () => left(v),
matchWith: (pattern) => pattern.left (v),
});
right(4).map(x=>x*x).matchWith({
right:v=>console.log(v),
left:v=>console.log("left"+v)
})
left(4).map(x=>x*x).matchWith({
right:v=>console.log(v),
left:v=>console.log("left "+v)
})