Last active
January 27, 2021 04:16
-
-
Save otwm/3a6358e53ca794cc2e57ade4af91d3bb to your computer and use it in GitHub Desktop.
ramda - argument null change
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
// infra code | |
const isEmptyOrNil = (value) => isEmpty(value) || isNil(value) | |
const nullChange = (defaultValue) => (value) => isEmptyOrNil(value)? defaultValue: value | |
// single null | |
const _somef = (value) => value | |
const somefWithDefault = (defaultValue) => pipe(nullChange(defaultValue), _somef) | |
const somef = somefWithDefault('myValue') | |
somef(null) | |
// many args | |
const _somef2 = (value, value2, value3) => value + value2 + value3 | |
const nullChangeMyValue = nullChange('myValue') | |
const somef2 = useWith(_somef2, [nullChangeMyValue, nullChangeMyValue, nullChangeMyValue]) | |
somef2(null, undefined, 1234) | |
// many args2 version2 | |
const nullChangeWith = (defaultValue) => nullChange(defaultValue) | |
const arrayNullChangeWith = (defaultValue) => (array) => array.map(nullChangeWith(defaultValue)) | |
const arg2Array = (...args) => args | |
const funcApplyDefaultValue = (defaultValue) => (func) => pipe( | |
arg2Array, arrayNullChangeWith(defaultValue), apply(func) | |
) | |
const v2somef2 = funcApplyDefaultValue(8)(_somef2) | |
v2somef2(1,2,null) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://tinyurl.com/yydhyjju