diff --git a/ndc_lib/src/stdlib/hash_map.rs b/ndc_lib/src/stdlib/hash_map.rs index 9ecb1bb5..c7afbdf8 100644 --- a/ndc_lib/src/stdlib/hash_map.rs +++ b/ndc_lib/src/stdlib/hash_map.rs @@ -48,6 +48,11 @@ mod inner { map.insert(key, Value::unit()); } + /// Returns true if the map or set contains no elements. + pub fn is_empty(map: &HashMap) -> bool { + map.is_empty() + } + #[function(name = "&=")] pub fn intersect_assign(lhs: &mut MapRepr, rhs: &mut MapRepr) { let left_map: &mut HashMap = &mut lhs diff --git a/tests/programs/007_map_and_set/023_map_is_empty.ndct b/tests/programs/007_map_and_set/023_map_is_empty.ndct new file mode 100644 index 00000000..ee59f620 --- /dev/null +++ b/tests/programs/007_map_and_set/023_map_is_empty.ndct @@ -0,0 +1,6 @@ +--PROGRAM-- +assert_eq(%{}.is_empty(), true); +assert_eq(%{1,2,3}.is_empty(), false); +print("ok"); +--EXPECT-- +ok \ No newline at end of file