Last active
July 31, 2019 02:52
-
-
Save horiuchie/e717775c1645c9df6a53e40b45654258 to your computer and use it in GitHub Desktop.
mustBeArray
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
/* | |
e.g. | |
mustBeArray([123, 456, 789]) => [123, 456, 789] | |
mustBeArray(123) => [123] | |
*/ | |
const mustBeArray = R.unless(R.is(Array), R.of); | |
// array type expected | |
function doSomething (numbers) { | |
// ... | |
console.log(numbers); | |
// ... | |
} | |
doSomething(mustBeArray(123)); | |
// => [123] | |
doSomething(mustBeArray([123, 456])); | |
// => [123, 456] | |
function saveUsers (users) { | |
// ... | |
console.log(users); | |
// ... | |
} | |
Promise.resolve({ name: 'haru', age: 1 }).then(mustBeArray).then(saveUsers); | |
// => [{ name: 'haru', age: 1 }] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment