Skip to content

Instantly share code, notes, and snippets.

View lupuszr's full-sized avatar

Viktor Pelle lupuszr

View GitHub Profile
@lupuszr
lupuszr / HigherOrderReducer.js
Created February 11, 2016 18:30
Higher Order Reducer WIP
const horeducer = (callback,...reducers) => (state, action) => {
var fnamed ={}
reducers.map( r => fnamed[r.name]=s=> r(s,action) )
return callback(state,action,fnamed)
}
const red1 = (state=0,action) =>{
console.log("r1state");
//implementation
//compose, curry, partial
var compose = curry(function(f, g, x) {
return f(g(x))
})
@lupuszr
lupuszr / introrx.md
Created May 28, 2016 12:53 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
import React, { Component } from 'react';
// schema = {name: 'Name', position: 'Position', office: 'Office', age: 'Age', startDate: 'Start date', salary: 'Salary'}
// data = [{ name: 'Tiger Nixon', position: 'System Architect', office: 'Edinburgh', age: 61, startDate: '2011/04/25', salary: '$320,800'}, ...]
export const DataTableHeader = ({ name }) => (
<div className="card-header">
<i className="fa fa-table"></i>{name}
</div>
);
@lupuszr
lupuszr / Purescript FFI example for react-native.md
Last active December 25, 2018 21:21 — forked from dwhitney/README.md
Quick React Native with PureScript
  1. create-react-native-app purescript-app; cd purescript-app

  2. pulp init --force

  3. pulp build

  4. src/Main.js

var React = require("react");
var RN = require("react-native");

exports.text = function(props){
@lupuszr
lupuszr / combinators.js
Created February 20, 2019 10:59 — forked from Avaq/combinators.js
Common combinators in JavaScript
const I = x => x;
const K = x => y => x;
const A = f => x => f(x);
const T = x => f => f(x);
const W = f => x => f(x)(x);
const C = f => y => x => f(x)(y);
const B = f => g => x => f(g(x));
const S = f => g => x => f(x)(g(x));
const P = f => g => x => y => f(g(x))(g(y));
const Y = f => (g => g(g))(g => f(x => g(g)(x)));
@lupuszr
lupuszr / IOMonad.ts
Created March 28, 2019 07:54
IO monad example in typescript
interface IO<T> {
(unsafeIO: Function): IO<T>;
chain(fn: (a: T) => IO<T>): IO<T>
of(performUnsafeIO: (a: T) => T): IO<T>;
fork(): IO<T>;
map(fn: (a: T) => T): IO<T>;
value: Function
};
type KIO<T> = (a: T) => T;
@lupuszr
lupuszr / trampoline.js
Created March 28, 2019 10:33
trampoline
const trampoline = fn => (...args) => {
let result = fn(...args)
while (typeof result === 'function') {
result = result()
}
return result
}
@lupuszr
lupuszr / complex.js
Created March 28, 2019 13:27
Simple Complex number lib
function Complex(re, im) {
this.re = re;
this.im = im;
return this;
}
Complex.of = function (r, i) {
return new Complex(r,i);
}
type lazy_node_t('a) =
| Delayed(unit => 'a)
| Value('a)
| Exn(exn);
type lazy_t('a) = ref(lazy_node_t('a));
let lazy_from_fun = f => ref(Delayed(f));
let force = x_lazy =>
switch (x_lazy^) {
| Value(x) => x