ToSliceContinuous implemented
This commit is contained in:
parent
9e62bab91e
commit
35264315fd
16
to.go
16
to.go
@ -9,6 +9,22 @@ func ToSlice[T any](ch <-chan T) []T {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToSliceContinuous returns a slice containing all values read from ch.
|
||||||
|
// The returned slice will be a pointer slice to a continuous block of memory.
|
||||||
|
// All values will be copied.
|
||||||
|
func ToSliceContinuous[T any](ch <-chan *T) []*T {
|
||||||
|
values := make([]T, 0, cap(ch))
|
||||||
|
pointers := make([]*T, 0, cap(ch))
|
||||||
|
EachSuccessive(ch, func(value *T) {
|
||||||
|
pointers = append(pointers, value)
|
||||||
|
|
||||||
|
if value != nil {
|
||||||
|
values = append(values, *value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return pointers
|
||||||
|
}
|
||||||
|
|
||||||
// ToSliceDeref returns a slice containing all values read from ch.
|
// ToSliceDeref returns a slice containing all values read from ch.
|
||||||
// The returned slice will be a dereferenced and continuous block of memory.
|
// The returned slice will be a dereferenced and continuous block of memory.
|
||||||
// Nil pointers are ignored.
|
// Nil pointers are ignored.
|
||||||
|
Loading…
Reference in New Issue
Block a user