29 lines
396 B
Go
29 lines
396 B
Go
package entity
|
|
|
|
func IterWithErr[T any](t []T, err error) iterWithErr[T] {
|
|
return iterWithErr[T]{
|
|
items: t,
|
|
err: err,
|
|
}
|
|
}
|
|
|
|
type iterWithErr[T any] struct {
|
|
items []T
|
|
err error
|
|
}
|
|
|
|
func (iter iterWithErr[T]) Do(f func(T) error) error {
|
|
if iter.err != nil {
|
|
return iter.err
|
|
}
|
|
|
|
for _, item := range iter.items {
|
|
err := f(item)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|