mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2026-01-05 23:23:16 -06:00
fix nil panic in AddToList()
This commit is contained in:
parent
002bd86a39
commit
af1be28c2b
2 changed files with 34 additions and 6 deletions
|
|
@ -42,6 +42,18 @@ func ToSet[T comparable](in []T) Set[T] {
|
|||
return set
|
||||
}
|
||||
|
||||
// ToSetFunc creates a Set[T] from input slice, keys provided by func.
|
||||
func ToSetFunc[S any, T comparable](in []S, key func(S) T) Set[T] {
|
||||
if key == nil {
|
||||
panic("nil func")
|
||||
}
|
||||
set := make(Set[T], len(in))
|
||||
for _, v := range in {
|
||||
set[key(v)] = struct{}{}
|
||||
}
|
||||
return set
|
||||
}
|
||||
|
||||
// FromSet extracts the values from set to slice.
|
||||
func FromSet[T comparable](in Set[T]) []T {
|
||||
out := make([]T, len(in))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue