Skip to content

Instantly share code, notes, and snippets.

@unscriptable
Created October 21, 2016 15:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unscriptable/189e013cdfec2dcee0f95deea6f7a409 to your computer and use it in GitHub Desktop.
Save unscriptable/189e013cdfec2dcee0f95deea6f7a409 to your computer and use it in GitHub Desktop.
Code snippet used in an IoC blog post
import _ from "lodash"
export const smsMessage = (template, isValidPhone) => {
const createMessage = _.template(template)
const validate = throwIfInvalidPhone(isValidPhone)
return _.compose(validate, createMessage)
}
const throwIfInvalidPhone = isValidPhone => user => {
if (!isValidPhone(user.phone)) {
throw new Error(`Invalid phone for user ${ user.id }.`);
}
return user
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment