github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/loop/first/api.go (about)

     1  // Package first provides short aliases for loop functions for retrieving a first element
     2  package first
     3  
     4  import (
     5  	"github.com/m4gshm/gollections/loop"
     6  )
     7  
     8  // Of an alias of the loop.First
     9  func Of[T any](next func() (T, bool), predicate func(T) bool) (T, bool) {
    10  	return loop.First(next, predicate)
    11  }
    12  
    13  // Converted converts the first element that satisfies the condition of the 'predicate' function by the converter and returns it
    14  func Converted[From, To any](next func() (From, bool), filter func(From) bool, converter func(From) To) (out To, ok bool) {
    15  	if f, ok := loop.First(next, filter); ok {
    16  		return converter(f), true
    17  	}
    18  	return out, false
    19  }