Created
October 21, 2016 15:28
-
-
Save unscriptable/189e013cdfec2dcee0f95deea6f7a409 to your computer and use it in GitHub Desktop.
Code snippet used in an IoC blog post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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