mirror of
https://github.com/vlang/v.git
synced 2025-08-03 09:47:15 -04: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
@ -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…
x
Reference in New Issue
Block a user