-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslice.go
More file actions
31 lines (24 loc) · 678 Bytes
/
Copy pathslice.go
File metadata and controls
31 lines (24 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package gofu
import "slices"
type Slice[T any] []T
func S[T any](data Slice[T]) Slice[T] {
return data
}
func (s Slice[T]) Mut() SliceMutator[T, Slice[T]] {
return mutableSlice[T](s)
}
// Copy returns an independent clone of the slice. [ Immutable ] [ time: O(n); space: O(n)]
func (s Slice[T]) Copy() Slice[T] {
return slices.Clone(s)
}
func (s Slice[T]) mapNoAlloc[R any](fn func(T) R, result Slice[R]) Slice[R] {
for i, v := range s {
result[i] = fn(v)
}
return result[:len(s)]
}
// Copy returns an independent clone. [ Immutable ] [ time: O(n); space: O(n)]
func (ps SliceParallel[T]) Copy() SliceParallel[T] {
ps.Slice = slices.Clone(ps.Slice)
return ps
}