mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
datatypes: add a Set.array/0 method to help get all the elements from a set as an array (#24206)
This commit is contained in:
parent
8a39132b6e
commit
880a9873a4
2 changed files with 11 additions and 0 deletions
|
@ -128,3 +128,8 @@ pub fn (l Set[T]) subset(r Set[T]) bool {
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// array returns an array representation of the set
|
||||
pub fn (l Set[T]) array() []T {
|
||||
return l.elements.keys()
|
||||
}
|
||||
|
|
|
@ -131,3 +131,9 @@ fn test_subset() {
|
|||
subset.add_all(['b', 'c'])
|
||||
assert set.subset(subset)
|
||||
}
|
||||
|
||||
fn test_array() {
|
||||
mut set := Set[string]{}
|
||||
set.add_all(['a', 'b', 'c'])
|
||||
assert set.array().len == 3
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue