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

     1  // Package convert provides converation helpers for collection implementations
     2  package convert
     3  
     4  import (
     5  	"github.com/m4gshm/gollections/c"
     6  	"github.com/m4gshm/gollections/collection"
     7  	"github.com/m4gshm/gollections/op/check/not"
     8  	"github.com/m4gshm/gollections/stream"
     9  )
    10  
    11  // AndConvert - convert.AndConvert makes double converts From->Intermediate->To of the elements
    12  func AndConvert[From, To, Too any, I c.Iterable[From]](elements I, firsConverter func(From) To, secondConverter func(To) Too) stream.Iter[Too] {
    13  	return collection.Convert(collection.Convert(elements, firsConverter), secondConverter)
    14  }
    15  
    16  // AndFilter - convert.AndFilter converts only filtered elements and returns them
    17  func AndFilter[From, To any, I c.Iterable[From]](elements I, converter func(From) To, filter func(To) bool) stream.Iter[To] {
    18  	return collection.Filter(collection.Convert(elements, converter), filter)
    19  }
    20  
    21  // NotNil - convert.NotNil converts only not nil elements and returns them
    22  func NotNil[From, To any, I c.Iterable[*From]](elements I, converter func(*From) To) stream.Iter[To] {
    23  	return collection.FilterAndConvert(elements, not.Nil[From], converter)
    24  }