Ported from https://github.com/mattstyles/lambda-snippets