github.com/m4gshm/gollections@v0.0.10/collection/immutable/vector/api.go (about)

     1  // Package vector provides ordered immutable.Vector constructors and helpers
     2  package vector
     3  
     4  import (
     5  	"golang.org/x/exp/constraints"
     6  
     7  	breakStream "github.com/m4gshm/gollections/break/stream"
     8  	"github.com/m4gshm/gollections/collection"
     9  	"github.com/m4gshm/gollections/collection/immutable"
    10  	"github.com/m4gshm/gollections/stream"
    11  )
    12  
    13  // Of instantiates a vector with the specified elements
    14  func Of[T any](elements ...T) immutable.Vector[T] {
    15  	return immutable.NewVector(elements...)
    16  }
    17  
    18  // New instantiates a vector with the specified elements
    19  func New[T any](elements []T) immutable.Vector[T] {
    20  	return immutable.NewVector(elements...)
    21  }
    22  
    23  // From instantiates a vector with elements retrieved by the 'next' function.
    24  // The next returns an element with true or zero value with false if there are no more elements.
    25  func From[T any](next func() (T, bool)) immutable.Vector[T] {
    26  	return immutable.VectorFromLoop(next)
    27  }
    28  
    29  // Sort copy the specified vector with sorted elements
    30  func Sort[T any, F constraints.Ordered](v immutable.Vector[T], by func(T) F) immutable.Vector[T] {
    31  	return collection.Sort[immutable.Vector[T]](v, by)
    32  }
    33  
    34  // Convert returns a stream that applies the 'converter' function to the collection elements
    35  func Convert[From, To any](vector immutable.Vector[From], converter func(From) To) stream.Iter[To] {
    36  	return collection.Convert(vector, converter)
    37  }
    38  
    39  // Conv returns a breakable stream that applies the 'converter' function to the collection elements
    40  func Conv[From, To comparable](vector immutable.Vector[From], converter func(From) (To, error)) breakStream.Iter[To] {
    41  	return collection.Conv(vector, converter)
    42  }
    43  
    44  // Flat returns a stream that converts the collection elements into slices and then flattens them to one level
    45  func Flat[From any, To any](vector immutable.Vector[From], flattener func(From) []To) stream.Iter[To] {
    46  	return collection.Flat(vector, flattener)
    47  }
    48  
    49  // Flatt returns a breakable stream that converts the collection elements into slices and then flattens them to one level
    50  func Flatt[From, To comparable](vector immutable.Vector[From], flattener func(From) ([]To, error)) breakStream.Iter[To] {
    51  	return collection.Flatt(vector, flattener)
    52  }