Documentation
¶
Overview ¶
Package seq extends iter.Seq API with convering, filtering, and reducing functionality.
Index ¶
- func Accum[T any, S ~seq[T]](first T, seq S, merge func(T, T) T) T
- func Accumm[T any, S ~seq[T]](first T, seq S, merge func(T, T) (T, error)) (accumulator T, err error)
- func Append[S ~seq[T], TS ~[]T, T any](seq S, out TS) TS
- func Contains[S ~seq[T], T comparable](seq S, example T) bool
- func First[S ~seq[T], T any](seq S, condition func(T) bool) (v T, ok bool)
- func Firstt[S ~seq[T], T any](seq S, condition func(T) (bool, error)) (v T, ok bool, err error)
- func ForEach[T any](seq Seq[T], consumer func(T))
- func Group[S ~seq[T], T any, K comparable, V any](seq S, keyExtractor func(T) K, valExtractor func(T) V) map[K][]V
- func HasAny[S ~seq[T], T any](seq S, filter func(T) bool) bool
- func Head[S ~seq[T], T any](seq S) (v T, ok bool)
- func Reduce[S ~seq[T], T any](seq S, merge func(T, T) T) T
- func ReduceOK[S ~seq[T], T any](seq S, merge func(T, T) T) (result T, ok bool)
- func Reducee[S ~seq[T], T any](seq S, merge func(T, T) (T, error)) (T, error)
- func ReduceeOK[S ~seq[T], T any](seq S, merge func(T, T) (T, error)) (result T, ok bool, err error)
- func Slice[S ~seq[T], T any](seq S) []T
- func SliceCap[S ~seq[T], T any](seq S, capacity int) (out []T)
- func Sum[S ~seq[T], T op.Summable](seq S) (out T)
- type Seq
- func Convert[S ~seq[From], From, To any](seq S, converter func(From) To) Seq[To]
- func ConvertNilSafe[S ~seq[*From], From, To any](seq S, converter func(*From) *To) Seq[*To]
- func ConvertOK[S ~seq[From], From, To any](seq S, converter func(from From) (To, bool)) Seq[To]
- func Filter[S ~seq[T], T any](seq S, filter func(T) bool) Seq[T]
- func Flat[S ~seq[From], STo ~[]To, From any, To any](seq S, flattener func(From) STo) Seq[To]
- func FlatSeq[S ~seq[From], STo ~seq[To], From any, To any](seq S, flattener func(From) STo) Seq[To]
- func NotNil[T any](seq Seq[*T]) Seq[*T]
- func Of[T any](elements ...T) Seq[T]
- func OfIndexed[T any](amount int, getAt func(int) T) Seq[T]
- func OfNext[T any](hasNext func() bool, pushNext func(*T)) Seq[T]
- func OfNextGet[T any](hasNext func() bool, getNext func() T) Seq[T]
- func OfSourceNext[S, T any](source S, hasNext func(S) bool, pushNext func(S, *T)) Seq[T]
- func OfSourceNextGet[S, T any](source S, hasNext func(S) bool, getNext func(S) T) Seq[T]
- func Range[T constraints.Integer | rune](from T, toExclusive T) Seq[T]
- func RangeClosed[T constraints.Integer | rune](from T, toInclusive T) Seq[T]
- func Series[T any](first T, next func(T) (T, bool)) Seq[T]
- func Skip[S ~seq[T], T any](n int, seq S) Seq[T]
- func SkipWhile[S ~seq[T], T any](seq S, filter func(T) bool) Seq[T]
- func Top[S ~seq[T], T any](n int, seq S) Seq[T]
- func Union[S ~seq[T], T any](seq ...S) Seq[T]
- func While[S ~seq[T], T any](seq S, filter func(T) bool) Seq[T]
- func (s Seq[T]) Accum(first T, merge func(T, T) T) T
- func (s Seq[T]) Accumm(first T, merge func(T, T) (T, error)) (T, error)
- func (s Seq[T]) Append(out []T) []T
- func (s Seq[T]) Conv(converter func(T) (T, error)) SeqE[T]
- func (s Seq[T]) Convert(converter func(t T) T) Seq[T]
- func (s Seq[T]) Filt(filter func(s T) (bool, error)) SeqE[T]
- func (s Seq[T]) Filter(filter func(s T) bool) Seq[T]
- func (s Seq[T]) First(predicate func(T) bool) (v T, ok bool)
- func (s Seq[T]) Firstt(predicate func(T) (bool, error)) (v T, ok bool, err error)
- func (s Seq[T]) ForEach(f func(T))
- func (s Seq[T]) HasAny(predicate func(T) bool) bool
- func (s Seq[T]) Head() (v T, ok bool)
- func (s Seq[T]) Reduce(merge func(a T, b T) T) T
- func (s Seq[T]) ReduceOK(merge func(T, T) T) (result T, ok bool)
- func (s Seq[T]) Reducee(merge func(T, T) (T, error)) (T, error)
- func (s Seq[T]) ReduceeOK(merge func(T, T) (T, error)) (result T, ok bool, err error)
- func (s Seq[T]) Skip(n int) Seq[T]
- func (s Seq[T]) SkipWhile(filter func(T) bool) Seq[T]
- func (s Seq[T]) Slice() []T
- func (s Seq[T]) Top(n int) Seq[T]
- func (s Seq[T]) Union(seqences ...seq[T]) Seq[T]
- func (s Seq[T]) While(filter func(T) bool) Seq[T]
- type Seq2
- func KeyValues[S ~seq[T], T, K, V any](seq S, keyExtractor func(T) K, valsExtractor func(T) []V) Seq2[K, V]
- func Of2[T any](elements ...T) Seq2[int, T]
- func ToKV[S ~seq[T], T, K, V any](seq S, keyExtractor func(T) K, valExtractor func(T) V) Seq2[K, V]
- func ToSeq2[S ~seq[T], T, K, V any](seq S, converter func(T) (K, V)) Seq2[K, V]
- func (s Seq2[K, V]) Conv(converter func(K, V) (K, V, error)) SeqE[c.KV[K, V]]
- func (s Seq2[K, V]) ConvKey(converter func(K) (K, error)) SeqE[c.KV[K, V]]
- func (s Seq2[K, V]) ConvValue(converter func(V) (V, error)) SeqE[c.KV[K, V]]
- func (s Seq2[K, V]) Convert(converter func(K, V) (K, V)) Seq2[K, V]
- func (s Seq2[K, V]) ConvertKey(converter func(K) K) Seq2[K, V]
- func (s Seq2[K, V]) ConvertValue(converter func(V) V) Seq2[K, V]
- func (s Seq2[K, V]) Filt(filter func(K, V) (bool, error)) SeqE[c.KV[K, V]]
- func (s Seq2[K, V]) Filter(filter func(K, V) bool) Seq2[K, V]
- func (s Seq2[K, V]) FilterKey(filter func(K) bool) Seq2[K, V]
- func (s Seq2[K, V]) FilterValue(filter func(V) bool) Seq2[K, V]
- func (s Seq2[K, V]) First(condition func(K, V) bool) (K, V, bool)
- func (s Seq2[K, V]) Firstt(condition func(K, V) (bool, error)) (K, V, bool, error)
- func (s Seq2[K, V]) HasAny(condition func(K, V) bool) bool
- func (s Seq2[K, V]) Head() (K, V, bool)
- func (s Seq2[K, V]) Keys() Seq[K]
- func (s Seq2[K, V]) TrackEach(consumer func(K, V))
- func (s Seq2[K, V]) Union(seqences ...seq2[K, V]) Seq2[K, V]
- func (s Seq2[K, V]) Values() Seq[V]
- type SeqE
- func Conv[S ~seq[From], From, To any](seq S, converter func(From) (To, error)) SeqE[To]
- func ConvOK[S ~seq[From], From, To any](seq S, converter func(from From) (To, bool, error)) SeqE[To]
- func Filt[S ~seq[T], T any](seq S, filter func(T) (bool, error)) SeqE[T]
- func Flatt[S ~seq[From], STo ~[]To, From any, To any](seq S, flattener func(From) (STo, error)) SeqE[To]
- func FlattSeq[S ~seq[From], STo ~seqE[To], From any, To any](seq S, flattener func(From) STo) SeqE[To]
- func (s SeqE[T]) Accum(first T, merge func(T, T) T) (T, error)
- func (s SeqE[T]) Accumm(first T, merge func(T, T) (T, error)) (T, error)
- func (s SeqE[T]) Append(out []T) ([]T, error)
- func (s SeqE[T]) Conv(converter func(T) (T, error)) SeqE[T]
- func (s SeqE[T]) Convert(converter func(t T) T) SeqE[T]
- func (s SeqE[T]) Filt(filter func(s T) (bool, error)) SeqE[T]
- func (s SeqE[T]) Filter(filter func(s T) bool) SeqE[T]
- func (s SeqE[T]) First(predicate func(T) bool) (T, bool, error)
- func (s SeqE[T]) Firstt(predicate func(T) (bool, error)) (T, bool, error)
- func (s SeqE[T]) ForEach(f func(T)) error
- func (s SeqE[T]) HasAny(predicate func(T) bool) (bool, error)
- func (s SeqE[T]) Head() (T, bool, error)
- func (s SeqE[T]) Reduce(merge func(a T, b T) T) (T, error)
- func (s SeqE[T]) ReduceOK(merge func(T, T) T) (result T, ok bool, err error)
- func (s SeqE[T]) Reducee(merge func(T, T) (T, error)) (T, error)
- func (s SeqE[T]) ReduceeOK(merge func(T, T) (T, error)) (result T, ok bool, err error)
- func (s SeqE[T]) Skip(n int) SeqE[T]
- func (s SeqE[T]) SkipWhile(filter func(T) bool) SeqE[T]
- func (s SeqE[T]) Slice() ([]T, error)
- func (s SeqE[T]) Top(n int) SeqE[T]
- func (s SeqE[T]) Union(seqences ...seqE[T]) SeqE[T]
- func (s SeqE[T]) While(filter func(T) bool) SeqE[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Accum ¶
func Accum[T any, S ~seq[T]](first T, seq S, merge func(T, T) T) T
Accum accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element of the 'seq' sequence.
func Accumm ¶
func Accumm[T any, S ~seq[T]](first T, seq S, merge func(T, T) (T, error)) (accumulator T, err error)
Accumm accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element of the 'seq' sequence.
func Append ¶
func Append[S ~seq[T], TS ~[]T, T any](seq S, out TS) TS
Append collects the elements of the 'seq' sequence into the specified 'out' slice.
func Contains ¶
func Contains[S ~seq[T], T comparable](seq S, example T) bool
Contains finds the first element that equal to the example and returns true.
func Group ¶ added in v0.0.15
func Group[S ~seq[T], T any, K comparable, V any](seq S, keyExtractor func(T) K, valExtractor func(T) V) map[K][]V
Group collects the seq elements into a new map. The keyExtractor converts an element to a key. The valExtractor converts an element to a value.
func Reduce ¶
func Reduce[S ~seq[T], T any](seq S, merge func(T, T) T) T
Reduce reduces the elements of the seq into one using the 'merge' function.
func ReduceOK ¶
ReduceOK reduces the elements of the seq into one using the 'merge' function. Returns ok==false if the seq returns ok=false at the first call (no more elements).
func ReduceeOK ¶
ReduceeOK reduces the elements of the seq into one using the 'merge' function. Returns ok==false if the seq returns ok=false at the first call (no more elements).
func Slice ¶
func Slice[S ~seq[T], T any](seq S) []T
Slice collects the elements of the 'seq' sequence into a new slice.
Types ¶
type Seq ¶ added in v0.0.15
type Seq[T any] seq[T]
Seq is an iterator-function that allows to iterate over elements of a sequence, such as slice.
func Convert ¶
Convert creates an iterator that applies the 'converter' function to each iterable element.
func ConvertNilSafe ¶ added in v0.0.17
ConvertNilSafe creates a seq that filters not nil elements, converts that ones, filters not nils after converting and returns them.
func ConvertOK ¶ added in v0.0.15
ConvertOK creates an iterator that applies the 'converter' function to each iterable element. The converter may returns a value or ok=false to exclude the value from the sequence.
func Filter ¶
Filter creates an iterator that iterates only those elements for which the 'filter' function returns true.
func Flat ¶
Flat is used to iterate over a two-dimensional sequence in single dimension form, like:
var arrays iter.Seq[[]int]
...
for e := range seq.Flat(arrays, as.Is) {
...
}
func FlatSeq ¶ added in v0.0.15
FlatSeq is used to iterate over a two-dimensional sequence in single dimension form, like:
var arrays iter.Seq[[]int]
...
for e := range s.FlatSeq(arrays, slices.Values) {
...
}
func OfIndexed ¶ added in v0.0.15
OfIndexed builds a Seq iterator by extracting elements from an indexed source. the len is length ot the source. the getAt retrieves an element by its index from the source.
func OfNext ¶ added in v0.0.15
OfNext builds an iterator by iterating elements of a source. The hasNext specifies a predicate that tests existing of a next element in the source. The pushNext copy the element to the next pointer.
func OfNextGet ¶ added in v0.0.15
OfNextGet builds an iterator by iterating elements of a source. The hasNext specifies a predicate that tests existing of a next element in the source. The getNext extracts the element.
func OfSourceNext ¶ added in v0.0.15
OfSourceNext builds an iterator by iterating elements of the source. The hasNext specifies a predicate that tests existing of a next element in the source. The pushNext copy the element to the next pointer.
func OfSourceNextGet ¶ added in v0.0.15
OfSourceNextGet builds an iterator by iterating elements of the source. The hasNext specifies a predicate that tests existing of a next element in the source. The getNext extracts the element.
func Range ¶ added in v0.0.15
func Range[T constraints.Integer | rune](from T, toExclusive T) Seq[T]
Range creates a sequence that generates integers in the range defined by from and to exclusive
func RangeClosed ¶ added in v0.0.15
func RangeClosed[T constraints.Integer | rune](from T, toInclusive T) Seq[T]
RangeClosed creates a sequence that generates integers in the range defined by from and to inclusive
func Series ¶ added in v0.0.15
Series makes a sequence by applying the 'next' function to the previous step generated value.
func SkipWhile ¶ added in v0.0.16
SkipWhile returns a sequence without first elements of the seq that dont'math the filter.
func (Seq[T]) Accum ¶ added in v0.0.17
func (s Seq[T]) Accum(first T, merge func(T, T) T) T
Accum accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element of the 'seq' sequence.
func (Seq[T]) Accumm ¶ added in v0.0.17
Accumm accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element of the 'seq' sequence.
func (Seq[T]) Append ¶ added in v0.0.17
func (s Seq[T]) Append(out []T) []T
Append collects the elements of the 'seq' sequence into the specified 'out' slice.
func (Seq[T]) Conv ¶ added in v0.0.17
Conv creates an errorable seq that applies the 'converter' function to the iterable elements.
func (Seq[T]) Convert ¶ added in v0.0.17
Convert creates an iterator that applies the 'converter' function to each iterable element.
func (Seq[T]) Filt ¶ added in v0.0.17
Filt creates an erroreable iterator that iterates only those elements for which the 'filter' function returns true.
func (Seq[T]) Filter ¶ added in v0.0.17
Filter creates an iterator that iterates only those elements for which the 'filter' function returns true.
func (Seq[T]) First ¶ added in v0.0.17
First returns the first element that satisfies the condition.
func (Seq[T]) Firstt ¶ added in v0.0.17
Firstt returns the first element that satisfies the condition.
func (Seq[T]) ForEach ¶ added in v0.0.17
func (s Seq[T]) ForEach(f func(T))
ForEach applies the 'consumer' function to the seq elements.
func (Seq[T]) HasAny ¶ added in v0.0.17
HasAny checks whether the seq contains an element that satisfies the condition.
func (Seq[T]) Reduce ¶ added in v0.0.17
func (s Seq[T]) Reduce(merge func(a T, b T) T) T
Reduce reduces the elements of the seq into one using the 'merge' function.
func (Seq[T]) ReduceOK ¶ added in v0.0.17
ReduceOK reduces the elements of the seq into one using the 'merge' function. Returns ok==false if the seq returns ok=false at the first call (no more elements).
func (Seq[T]) Reducee ¶ added in v0.0.17
Reducee reduces the elements of the seq into one using the 'merge' function.
func (Seq[T]) ReduceeOK ¶ added in v0.0.17
ReduceeOK reduces the elements of the seq into one using the 'merge' function. Returns ok==false if the seq returns ok=false at the first call (no more elements).
func (Seq[T]) SkipWhile ¶ added in v0.0.17
SkipWhile returns a sequence without first elements of the seq that dont'math the filter.
func (Seq[T]) Slice ¶ added in v0.0.17
func (s Seq[T]) Slice() []T
Slice collects the elements of the 'seq' sequence into a new slice.
type Seq2 ¶ added in v0.0.15
type Seq2[K, V any] seq2[K, V]
Seq2 is an iterator-function that allows to iterate over key/value pairs of a sequence, such as slice or map. It is used to iterate over slice index/value pairs or map key/value pairs.
func KeyValues ¶ added in v0.0.15
func KeyValues[S ~seq[T], T, K, V any](seq S, keyExtractor func(T) K, valsExtractor func(T) []V) Seq2[K, V]
KeyValues converts the seq iterator to a key/value pairs iterator by applying the key, values extractors to each iterable element.
func ToKV ¶ added in v0.0.17
ToKV converts the seq iterator to a key/value pairs iterator by applying the key, value extractors to each iterable element.
func ToSeq2 ¶
ToSeq2 converts an iterator of single elements to an iterator of key/value pairs by applying the 'converter' function to each iterable element.
func (Seq2[K, V]) Conv ¶ added in v0.0.17
Conv creates an errorable seq that applies the 'converter' function to the iterable key\value pairs.
func (Seq2[K, V]) ConvKey ¶ added in v0.0.17
ConvKey returns a seq that applies the 'converter' function to keys.
func (Seq2[K, V]) ConvValue ¶ added in v0.0.17
ConvValue returns a seq that applies the 'converter' function to values.
func (Seq2[K, V]) Convert ¶ added in v0.0.17
Convert creates an iterator that applies the 'converter' function to each iterable key\value pair.
func (Seq2[K, V]) ConvertKey ¶ added in v0.0.17
ConvertKey returns a seq that applies the 'converter' function to keys.
func (Seq2[K, V]) ConvertValue ¶ added in v0.0.17
ConvertValue returns a seq that applies the 'converter' function to values.
func (Seq2[K, V]) Filt ¶ added in v0.0.17
Filt creates an erroreable iterator that iterates only those key\value pairs for which the 'filter' function returns true.
func (Seq2[K, V]) Filter ¶ added in v0.0.17
Filter creates an iterator that iterates only those elements for which the 'filter' function returns true.
func (Seq2[K, V]) FilterKey ¶ added in v0.0.17
FilterKey returns a seq consisting of key/value pairs where the key satisfies the condition of the 'filter' function.
func (Seq2[K, V]) FilterValue ¶ added in v0.0.17
FilterValue returns a seq consisting of key/value pairs where the value satisfies the condition of the 'filter' function.
func (Seq2[K, V]) First ¶ added in v0.0.17
First returns the first key\value pair that satisfies the condition.
func (Seq2[K, V]) Firstt ¶ added in v0.0.17
Firstt returns the first key\value pair that satisfies the condition.
func (Seq2[K, V]) HasAny ¶ added in v0.0.17
HasAny checks whether the seq contains a key\value pair that satisfies the condition.
func (Seq2[K, V]) Keys ¶ added in v0.0.17
Keys converts a key/value pairs iterator to an iterator of just keys.
func (Seq2[K, V]) TrackEach ¶ added in v0.0.17
func (s Seq2[K, V]) TrackEach(consumer func(K, V))
TrackEach applies the 'consumer' function to the seq key\value pairs.
type SeqE ¶ added in v0.0.15
type SeqE[T any] seqE[T]
SeqE is a specific iterator form that allows to retrieve a value with an error as second parameter of the iterator. It is used as a result of applying functions like seq.Conv, which may throw an error during iteration. At each iteration step, it is necessary to check for the occurrence of an error.
for e, err := range seqence {
if err != nil {
break
}
...
}
func Conv ¶
Conv creates an errorable seq that applies the 'converter' function to the iterable elements. The error should be checked at every iteration step, like:
var integers iter.Seq[int]
...
for s, err := range seq.Conv(integers, strconv.Itoa) {
if err != nil {
break
}
...
}
func ConvOK ¶ added in v0.0.15
func ConvOK[S ~seq[From], From, To any](seq S, converter func(from From) (To, bool, error)) SeqE[To]
ConvOK creates a iterator that applies the 'converter' function to each iterable element. The converter may returns a value or ok=false to exclude the value from iteration. It may also return an error to abort the iteration.
func Filt ¶
Filt creates an erroreable iterator that iterates only those elements for which the 'filter' function returns true.
func Flatt ¶ added in v0.0.15
func Flatt[S ~seq[From], STo ~[]To, From any, To any](seq S, flattener func(From) (STo, error)) SeqE[To]
Flatt is used to iterate over a two-dimensional sequence in single dimension form, like:
var (
input iter.Seq[[]string]
flattener func([]string) ([]int, error)
out seq.SeqE[int]
)
flattener = convertEveryBy(strconv.Atoi)
out = seq.Flatt(input, flattener)
for i, err := range out {
if err != nil {
panic(err)
}
...
}
func FlattSeq ¶ added in v0.0.15
func FlattSeq[S ~seq[From], STo ~seqE[To], From any, To any](seq S, flattener func(From) STo) SeqE[To]
FlattSeq is used to iterate over a two-dimensional sequence in single dimension form, like:
var (
input iter.Seq[[]string]
flattener func([]string) seq.SeqE[int]
out seq.SeqE[int]
)
flattener = convertEveryBy(strconv.Atoi)
out = seq.Flatt(input, flattener)
for i, err := range out {
if err != nil {
panic(err)
}
...
}
func (SeqE[T]) Accum ¶ added in v0.0.17
Accum accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element of the 'seq' sequence.
func (SeqE[T]) Accumm ¶ added in v0.0.17
Accumm accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element of the 'seq' sequence.
func (SeqE[T]) Append ¶ added in v0.0.17
Append collects the elements of the 'seq' sequence into the specified 'out' slice.
func (SeqE[T]) Conv ¶ added in v0.0.17
Conv creates an errorable seq that applies the 'converter' function to the collection elements.
func (SeqE[T]) Convert ¶ added in v0.0.17
Convert creates an iterator that applies the 'converter' function to each iterable element.
func (SeqE[T]) Filt ¶ added in v0.0.17
Filt creates an erroreable iterator that iterates only those elements for which the 'filter' function returns true.
func (SeqE[T]) Filter ¶ added in v0.0.17
Filter creates an iterator that iterates only those elements for which the 'filter' function returns true.
func (SeqE[T]) First ¶ added in v0.0.17
First returns the first element that satisfies the condition.
func (SeqE[T]) Firstt ¶ added in v0.0.17
Firstt returns the first element that satisfies the condition.
func (SeqE[T]) ForEach ¶ added in v0.0.17
ForEach applies the 'consumer' function to the seq elements.
func (SeqE[T]) HasAny ¶ added in v0.0.17
HasAny checks whether the seq contains an element that satisfies the condition.
func (SeqE[T]) Reduce ¶ added in v0.0.17
Reduce reduces the elements of the seq into one using the 'merge' function.
func (SeqE[T]) ReduceOK ¶ added in v0.0.17
ReduceOK reduces the elements of the seq into one using the 'merge' function. Returns ok==false if the seq returns ok=false at the first call (no more elements).
func (SeqE[T]) Reducee ¶ added in v0.0.17
Reducee reduces the elements of the seq into one using the 'merge' function.
func (SeqE[T]) ReduceeOK ¶ added in v0.0.17
ReduceeOK reduces the elements of the seq into one using the 'merge' function. Returns ok==false if the seq returns ok=false at the first call (no more elements).
func (SeqE[T]) SkipWhile ¶ added in v0.0.17
SkipWhile returns a sequence without first elements of the seq that dont'math the filter.
func (SeqE[T]) Slice ¶ added in v0.0.17
Slice collects the elements of the 'seq' sequence into a new slice.