Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support type matching #15

Open
FGRibreau opened this issue Mar 17, 2016 · 0 comments
Open

Support type matching #15

FGRibreau opened this issue Mar 17, 2016 · 0 comments

Comments

@FGRibreau
Copy link
Owner

before:

function replaceInstanceId(elem) {
 +    if (_.isPlainObject(elem)) {
+      return _.mapValues(elem, replaceInstanceId);
 +    } else if (_.isArray(elem)) {
 +      return _.map(elem, replaceInstanceId);
 +    } else if (_.isString(elem) && _.includes(elem, 'instance_id')) {
 +      return _.template(elem)({instance_id: conf.instance_id});
 +    }
 +
 +    return elem;
 +  }

after:

const replaceInstanceId = match({
 [when(Object)]:(elem) => _.mapValues(elem, replaceInstanceId),
 [when(Array)]:(elem) =>  _.map(elem, replaceInstanceId),
 [when.and(String, /instance_id/)]: (elem) =>  _.template(elem)({instance_id: conf.instance_id}),
 [when()]: _.identity
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant