Skip to content

Instantly share code, notes, and snippets.

View ecancino's full-sized avatar

Eduardo Cancino ecancino

View GitHub Profile
@ecancino
ecancino / fetch.js
Created April 22, 2019 19:01
Fetch explained
function addUser(details) {
return fetch('https://api.example.com/user', {
mode: 'cors',
method: 'POST',
credentials: 'include',
body: JSON.stringify(details),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-XSRF-TOKEN': getCookieValue('XSRF-TOKEN')
function logColor(color, args) {
console.log(`%c ${args.join(' ')}`, `color: ${color}`);
}
const log = {
aliceblue: (...args) => { logColor('aliceblue', args)},
antiquewhite: (...args) => { logColor('antiquewhite', args)},
aqua: (...args) => { logColor('aqua', args)},
aquamarine: (...args) => { logColor('aquamarine', args)},
azure: (...args) => { logColor('azure', args)},
@ecancino
ecancino / compose.js
Created November 24, 2017 19:13
Compose
export const compose = (...fs) => fs.reduce((a, f) => (...as) => f(a(...as)), x => x)

Standardized Ladder of Functional Programming

The LambdaConf Ladder of Functional Programming (LOFP) is a standardized progression of different concepts and skills that developers must master on their journey to becoming expert-level functional programmers. LOFP can be used to rank workshops, talks, presentations, books, and courseware, so that aspiring functional programmers have a better understanding of what material is appropriate for them given their current experience.

Fire Keramik

Concepts

  • Immutable Data
  • Second-order Functions
@ecancino
ecancino / curry.js
Created May 25, 2017 20:22 — forked from amatiasq/curry.js
Simple way to recursively curry javascript functions http://jsfiddle.net/amatiasq/osrsomq0/
/**
* @param {Function} fn Function to curry.
* @param {Number} lenght The arguments required to invoke the function. Optional. By default is fn.length
* @returns {Function} The currified function.
*/
function curry(fn, length) {
length = length || fn.length;
return function currified() {
var args = [].slice.call(arguments);
'use strict';
const { compose, curry, times, max, add, map, join, memoize } = require('ramda')
const toFixed = curry((p, n) => Number(n.toFixed(p)))
const format = compose(join('\n'), map(join(', ')), map(map(toFixed(3))))
const pascal = memoize((n, s = 1) => {
const result = [[s]]
@ecancino
ecancino / monoid.js
Created May 10, 2017 16:38
DrBoolean monoids
const Sum = x =>
({
x,
concat: ({x: y}) => Sum(x + y),
inspect: () => `Sum(${x})`
})
Sum.empty = () => Sum(0)
const Product = x =>
const Task = require('data.task')
const Either = require('data.either')
const { Left, Right } = Either
const request = require('request')
const { List } = require('immutable-ext')
const { drop, prop, map } = require('lodash/fp')
const effect = f => x => {
f(x)
return x
@ecancino
ecancino / catDir.js
Created May 10, 2017 16:29
Cat files in folder
const { readdir, readFile, stat } = require('fs-extra');
const { Future } = require('ramda-fantasy');
const { traverse, join, curry } = require('ramda');
//:: String -> Future Error [String]
const ls = path => Future((reject, resolve) =>
readdir(path, (err, files) => err ? reject(err) : resolve(files)));
//:: String -> Future Error String
const cat = curry((path, file) => Future((reject, resolve) =>
const range = length => [...Array(length).keys()];
const divBy = n => v => (v % n === 0)
const divBy3 = divBy(3);
const divBy5 = divBy(5);
const all = (n, xs) => xs.reduce((p, c) => p && c(n), true);
const divBy15 = n => all(n, [ divBy3, divBy5 ]);
const fizbuzz = n => range(n)
.map(n =>
divBy15(n) ? `FizzBuzz (${n})` :