github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/loop/conv/api.go (about) 1 // Package conv provides loop converation helpers 2 package conv 3 4 import ( 5 breakLoop "github.com/m4gshm/gollections/break/loop" 6 "github.com/m4gshm/gollections/loop" 7 ) 8 9 // FromIndexed - conv.FromIndexed retrieves elements from a indexed source and converts them 10 func FromIndexed[From, To any](len int, next func(int) From, converter func(from From) (To, error)) breakLoop.Loop[To] { 11 return loop.Conv(loop.OfIndexed(len, next), converter) 12 } 13 14 // AndReduce - convert.AndReduce converts elements and merge them into one 15 func AndReduce[From, To any](next func() (From, bool), converter func(From) (To, error), merge func(To, To) To) (To, error) { 16 return loop.ConvAndReduce(next, converter, merge) 17 }