Skip to content

Instantly share code, notes, and snippets.

@Shwartz
Shwartz / curry.js
Created November 7, 2018 12:46
Helpers for curry, compose, apply to make functional approach to code
const {assign} = Object;
const pipe = (fn, ...fns) => (param, ...staticArgs) => fns.reduce((acc, f) => f(acc), fn(param, ...staticArgs));
const compose = (...fns) => pipe(...fns.reverse());
const pipeAsync = (fn, ...fns) => (param, ...staticArgs) => fns.reduce((acc, f) => acc.then(_ => f(_, ...staticArgs)), fn(param, ...staticArgs));
const composeAsync = (...fns) => pipeAsync(...fns.reverse());
const apply = (...fns) => (...args) => fns.map(fn => fn(...args));
const curry = (fn, ...args) => (fn.length <= args.length) ? fn(...args) : (...more) => curry(fn, ...args, ...more);
const match = (guard) => (left = _ => _, right = _ => _) => (...args) => (..._) => guard(...args) ? right(..._, ...args) : left(..._, ...args);
const extract = (_) => (...methods) => methods.reduce((acc, method) => assign(acc, {[method]: (...args) => _[method](...args)}), {});
export const simple = {
method: (param) => {
return `my param: ${param}`
}
};
export const shorter = {
method(param1) {
return `my param1: ${param1}`
}
@Shwartz
Shwartz / gatsby-config.js
Created August 26, 2019 03:39
gatsbyjs remark images and mdx config example
const path = require("path")
module.exports = {
/* Your site config here */
siteMetadata: {
title: "Generic Site Title",
},
pathPrefix: `/gby1`,
plugins: [
`gatsby-transformer-sharp`,
/**
* Original idea: https://github.com/necolas/normalize.css/tree/master
* Added box-sizing based on https://css-tricks.com/box-sizing/
**/
/**
* 1. Correct the line height in all browsers.
* 2. Prevent adjustments of font size after orientation changes in iOS.
*/