Refine is_empty methods.

This commit is contained in:
Stephen Chung 2022-08-24 21:58:08 +08:00
parent ae5e88928e
commit ca1b7f6a39
7 changed files with 101 additions and 35 deletions

View File

@ -22,6 +22,11 @@ New features
* For very special needs, the ability to register fallible type iterators is added.
Enhancements
------------
* `is_empty` method is added to arrays, BLOB's, object maps, strings and ranges.
Version 1.9.0
=============

View File

@ -785,6 +785,12 @@ op +(u8, u8) -> u8;
/// ```
op +=(Map, Map) -> ();
op +=(String, String) -> ();
op +=(String, char) -> ();
op +=(String, ()) -> ();
op +=(String, ?) -> ();
op +=(String, Blob) -> ();
@ -2368,6 +2374,21 @@ fn get int(x: float) -> float;
/// ```
fn get is_anonymous(fn_ptr: FnPtr) -> bool;
/// Return true if the array is empty.
fn get is_empty(array: Array) -> bool;
/// Return true if the BLOB is empty.
fn get is_empty(blob: Blob) -> bool;
/// Return true if the range contains no items.
fn get is_empty(range: ExclusiveRange) -> bool;
/// Return true if the range contains no items.
fn get is_empty(range: InclusiveRange) -> bool;
/// Return true if the string is empty.
fn get is_empty(string: String) -> bool;
/// Return true if the number is even.
fn get is_even(x: int) -> bool;
@ -2913,6 +2934,24 @@ fn int(x: float) -> float;
/// ```
fn is_anonymous(fn_ptr: FnPtr) -> bool;
/// Return true if the array is empty.
fn is_empty(array: Array) -> bool;
/// Return true if the BLOB is empty.
fn is_empty(blob: Blob) -> bool;
/// Return true if the map is empty.
fn is_empty(map: Map) -> bool;
/// Return true if the range contains no items.
fn is_empty(range: ExclusiveRange) -> bool;
/// Return true if the range contains no items.
fn is_empty(range: InclusiveRange) -> bool;
/// Return true if the string is empty.
fn is_empty(string: String) -> bool;
/// Return true if the number is even.
fn is_even(x: int) -> bool;
@ -3047,9 +3086,6 @@ fn keys(map: Map) -> Array;
/// Number of elements in the array.
fn len(array: Array) -> int;
/// Return true if the array is empty.
fn is_empty(array: Array) -> bool;
/// Return the length of the BLOB.
///
/// # Example
@ -3063,15 +3099,9 @@ fn is_empty(array: Array) -> bool;
/// ```
fn len(blob: Blob) -> int;
/// Return true if the blob is empty.
fn is_empty(blob: Blob) -> bool;
/// Return the number of properties in the object map.
fn len(map: Map) -> int;
/// Return true if the map is empty.
fn is_empty(map: Map) -> bool;
/// Return the length of the string, in number of characters.
///
/// # Example
@ -3083,9 +3113,6 @@ fn is_empty(map: Map) -> bool;
/// ```
fn len(string: String) -> int;
/// Return true if the string is empty.
fn is_empty(string: String) -> bool;
/// Return the natural log of the decimal number.
fn ln(x: Decimal) -> Decimal;
@ -5738,6 +5765,16 @@ fn tan(x: float) -> float;
fn tanh(x: float) -> float;
/// Create a timestamp containing the current system time.
///
/// # Example
///
/// ```rhai
/// let now = timestamp();
///
/// sleep(10.0); // sleep for 10 seconds
///
/// print(now.elapsed); // prints 10.???
/// ```
fn timestamp() -> Instant;
/// Convert the BLOB into an array of integers.

View File

@ -267,6 +267,12 @@ op +(u8, u8) -> u8;
/// ```
op +=(Map, Map) -> ();
op +=(String, String) -> ();
op +=(String, char) -> ();
op +=(String, ()) -> ();
op +=(String, ?) -> ();
op +=(String, Blob) -> ();
@ -1850,6 +1856,21 @@ fn get int(x: float) -> float;
/// ```
fn get is_anonymous(fn_ptr: FnPtr) -> bool;
/// Return true if the array is empty.
fn get is_empty(array: Array) -> bool;
/// Return true if the BLOB is empty.
fn get is_empty(blob: Blob) -> bool;
/// Return true if the range contains no items.
fn get is_empty(range: ExclusiveRange) -> bool;
/// Return true if the range contains no items.
fn get is_empty(range: InclusiveRange) -> bool;
/// Return true if the string is empty.
fn get is_empty(string: String) -> bool;
/// Return true if the number is even.
fn get is_even(x: int) -> bool;
@ -1973,9 +1994,6 @@ fn get is_zero(x: u8) -> bool;
/// Number of elements in the array.
fn get len(array: Array) -> int;
/// Return true if the array is empty.
fn get empty(array: Array) -> bool;
/// Return the length of the BLOB.
///
/// # Example
@ -2398,6 +2416,24 @@ fn int(x: float) -> float;
/// ```
fn is_anonymous(fn_ptr: FnPtr) -> bool;
/// Return true if the array is empty.
fn is_empty(array: Array) -> bool;
/// Return true if the BLOB is empty.
fn is_empty(blob: Blob) -> bool;
/// Return true if the map is empty.
fn is_empty(map: Map) -> bool;
/// Return true if the range contains no items.
fn is_empty(range: ExclusiveRange) -> bool;
/// Return true if the range contains no items.
fn is_empty(range: InclusiveRange) -> bool;
/// Return true if the string is empty.
fn is_empty(string: String) -> bool;
/// Return true if the number is even.
fn is_even(x: int) -> bool;
@ -2532,9 +2568,6 @@ fn keys(map: Map) -> Array;
/// Number of elements in the array.
fn len(array: Array) -> int;
/// Return true if the array is empty.
fn is_empty(array: Array) -> bool;
/// Return the length of the BLOB.
///
/// # Example
@ -2548,15 +2581,9 @@ fn is_empty(array: Array) -> bool;
/// ```
fn len(blob: Blob) -> int;
/// Return true if the blob is empty.
fn is_empty(blob: Blob) -> bool;
/// Return the number of properties in the object map.
fn len(map: Map) -> int;
/// Return true if the map is empty.
fn is_empty(map: Map) -> bool;
/// Return the length of the string, in number of characters.
///
/// # Example
@ -2568,9 +2595,6 @@ fn is_empty(map: Map) -> bool;
/// ```
fn len(string: String) -> int;
/// Return true if the string is empty.
fn is_empty(string: String) -> bool;
/// Return the natural log of the decimal number.
fn ln(x: Decimal) -> Decimal;

View File

@ -3,8 +3,8 @@
"general_kenobi": {
"functions": [
{
"baseHash": 2647973605745432570,
"fullHash": 14052888716942083368,
"baseHash": 14798413363692662073,
"fullHash": 2039416761244929762,
"namespace": "internal",
"access": "public",
"name": "hello_there",
@ -27,8 +27,8 @@
},
"functions": [
{
"baseHash": 6399059862174416123,
"fullHash": 15886705420394126404,
"baseHash": 17487674894006547092,
"fullHash": 13058993152904417424,
"namespace": "global",
"access": "public",
"name": "minus",

View File

@ -140,7 +140,7 @@ pub mod blob_functions {
pub fn len(blob: &mut Blob) -> INT {
blob.len() as INT
}
/// Return true if the blob is empty.
/// Return true if the BLOB is empty.
#[rhai_fn(name = "is_empty", get = "is_empty", pure)]
pub fn is_empty(blob: &mut Blob) -> bool {
blob.len() == 0

View File

@ -666,7 +666,7 @@ mod range_functions {
let _ = range;
true
}
/// Returns true if the range contains no items.
/// Return true if the range contains no items.
#[rhai_fn(get = "is_empty", name = "is_empty", pure)]
pub fn is_empty_exclusive(range: &mut ExclusiveRange) -> bool {
range.is_empty()
@ -693,7 +693,7 @@ mod range_functions {
let _ = range;
false
}
/// Returns true if the range contains no items.
/// Return true if the range contains no items.
#[rhai_fn(get = "is_empty", name = "is_empty", pure)]
pub fn is_empty_inclusive(range: &mut InclusiveRange) -> bool {
range.is_empty()

View File

@ -26,7 +26,7 @@ mod map_functions {
map.len() as INT
}
/// Return true if the map is empty.
#[rhai_fn(name = "is_empty", get = "is_empty", pure)]
#[rhai_fn(pure)]
pub fn is_empty(map: &mut Map) -> bool {
map.len() == 0
}