Skip to content

Instantly share code, notes, and snippets.

@jeffchiou
jeffchiou / pipe.py
Last active September 2, 2020 15:05
Python pipeline / chaining that takes functions with multiple arguments (as long as the current function returns the correct iterable for the next function's arguments)
from functools import reduce
# Readable version
def pipe(*funcs):
def shortpipe(f,g):
return lambda *args: g(*f(*args))
return reduce(shortpipe, funcs)
# Short version
def pipe(*fs):
@jeffchiou
jeffchiou / wrap.js
Created December 14, 2019 22:13
Wrapping an Element with Another, using modern JS and compatible JS
/**
* Wrapper function with modern JS. May have issues with IE and Safari.
* Will preserve event handlers.
* @param {ChildNode} elToWrap The element you want to wrap.
* @param {ParentNode} wrapper The element to wrap with.
*/
const wrap = (elToWrap, wrapper) => {
elToWrap.before(wrapper) // so element doesn't move
wrapper.append(elToWrap) // automatically moves wrapped element.
}