You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe:
When working with KCL, I often need to check if a value is "nullish" (either None or Undefined). Currently, this requires using constructs like value in [None, Undefined] or value is None or value is Undefined. While functional, these approaches can be verbose and may lead to inconsistencies across different codebases.
Describe the feature you'd like:
I propose adding a new built-in function is_nullable(value) to KCL. This function would return True if the value is None or Undefined, and False otherwise. For example:
ifis_nullable(some_value):
print("Value is None or Undefined")
else:
print("Value is not None and not Undefined")
This would provide a concise, readable, and standardized way to perform this common check.
Describe alternatives you've considered:
Continue using value in [None, Undefined]
Use value is None or value is Undefined
While these alternatives work, they lack the clarity and potential for optimization that a dedicated built-in function could provide.
Teachability, Documentation, Adoption, Migration Strategy:
The is_nullable function would be straightforward to teach and document. It follows a naming convention similar to other programming languages and its purpose is self-explanatory.
Adoption scenarios:
Simplifying null checks in conditional statements:
ifnotis_nullable(config.timeout):
# Use the timeout value
'is_nullish' might actually be a better name than 'is_nullable'. It more accurately describes the function's purpose of checking for both None and Undefined.
Feature Request
Is your feature request related to a problem? Please describe:
When working with KCL, I often need to check if a value is "nullish" (either
None
orUndefined
). Currently, this requires using constructs likevalue in [None, Undefined]
orvalue is None or value is Undefined
. While functional, these approaches can be verbose and may lead to inconsistencies across different codebases.Describe the feature you'd like:
I propose adding a new built-in function
is_nullable(value)
to KCL. This function would returnTrue
if the value isNone
orUndefined
, andFalse
otherwise. For example:This would provide a concise, readable, and standardized way to perform this common check.
Describe alternatives you've considered:
value in [None, Undefined]
value is None or value is Undefined
While these alternatives work, they lack the clarity and potential for optimization that a dedicated built-in function could provide.
Teachability, Documentation, Adoption, Migration Strategy:
The
is_nullable
function would be straightforward to teach and document. It follows a naming convention similar to other programming languages and its purpose is self-explanatory.Adoption scenarios:
Simplifying null checks in conditional statements:
Cleaning up default value assignments:
Validating function inputs:
Migration would be straightforward as the function doesn't break existing code. Developers could gradually adopt it in new code or during refactoring.
The text was updated successfully, but these errors were encountered: