Skip to content

Instantly share code, notes, and snippets.

View MarkusPfundstein's full-sized avatar

Markus Pfundstein MarkusPfundstein

View GitHub Profile
@MarkusPfundstein
MarkusPfundstein / example.js
Created March 27, 2017 06:47
Javascript Reader.T(Task) example (why to use Monads)
const Task = require('data.task');
const Maybe = require('data.maybe');
const { Reader, ReaderT } = require('ramda-fantasy');
const R = require('ramda');
const mysql = require('mysql');
const request = require('request');
const ReaderTask = Reader.T(Task);
@MarkusPfundstein
MarkusPfundstein / prod_comonad.js
Last active May 25, 2018 10:38
Product Comonad example
const Prod = t => ({
extract : () => t[1],
extend : f => Prod([t[0], f([t[0], t[1]])]),
map : f => Prod([t[0], f(t[1])]),
duplicate : () => Prod([t[0], Prod(t)])
});
@MarkusPfundstein
MarkusPfundstein / func.js
Created March 10, 2017 15:05
example of Reader.T(Task) and express
const Task = require('data.task');
const { Reader, Maybe } = require('ramda-fantasy');
const ReaderTask = Reader.T(Task);
const R = require('ramda');
const express = require('express');
const app = express();
const MOCK_DB = {
5 : {
@MarkusPfundstein
MarkusPfundstein / fluent_vs_composition_in_FL.js
Last active February 24, 2017 20:54
fluent_vs_composition_in_FL.js
/*
* According to the applicative functor laws, any applicative functor F must satisfy the composition law:
*
* pure (.) <*> F (+ 2) <*> F (* 2)
* ===
* F (+ 2) <*> (F (* 2) <*> F 3)
*
* Let's see how we can show this with two Applicative Functors. Data.Task from folktale and Fluture.
* Data.Task implements the pre v1.0 spec of fantasy-land, while Fluture is up to date.
*
const tailRec = (f) => (a) => {
let v = f(a)
while (!v.done) {
v = f(v.value)
}
return v.value
}
const done = (v) => ({ value: v, done: true })
const next = (v) => ({ value: v, done: false })
@MarkusPfundstein
MarkusPfundstein / comp.js
Created October 1, 2016 13:58
(partly) lazy list comprehensions js using ramda and generators
//take((e, a) => e+a*a, when(isEven, xs), when(isOdd, ys))
//take((e, a) => e+a*a, [when(isEven, xs), ys])
const R = require('ramda');
// not lazy
const flatxprod = (x, y) => R.map(R.flatten, R.xprod(x, y));
function * nprod(...args) {
function * rec(accum, xs) {
@MarkusPfundstein
MarkusPfundstein / javascript.js
Last active November 6, 2019 00:01
pattern matching function using ramda
/*
* examples - code for matchC is below
* to test: copy&paste into http://ramdajs.com/repl
*/
function main() {
// its all good if all output lines have true in first tuple ;-)
const m1 = matchC('Hello')
.when('string', a => [true, a.toUpperCase()])
.when('number', a => [false, a])
@MarkusPfundstein
MarkusPfundstein / IO.js
Last active September 16, 2016 09:29
eventually correct implementation of IO Monad in JS
class IO extends Monad {
constructor(fn) {
super();
this.__value = fn;
}
static of(fn) {
const io = new IO(() => fn);
Object.freeze(io);
return io;
@MarkusPfundstein
MarkusPfundstein / beautiful.js
Last active September 4, 2016 15:43
Beautiful ES6
const fs = require('fs');
const head = ([x, ...t]) => x;
const tail = ([x, ...t]) => t;
const compose = (f, ...rest) => (x) =>
rest.length === 1
? head(rest)(f(x))
: compose(head(rest), ...tail(rest))(f(x));
https://www.youtube.com/watch?v=GquJWqNvEPw
Why does the 3rd world need longer to catch up?
- widespread internet use
- great democratisation of education taking place in the 3rd world (MOOC)
- 35$ notebook, down to 10$ within 2 years
- 3d printing of clothing
- educational system must change -> prices of higher education are way too high. industry must be transformed and equalised.
- cultures must adept as well