Initial commit of modash
This was taken from github.com/lmika/gopkgs/fp
This commit is contained in:
commit
a20530ddfd
20 changed files with 425 additions and 0 deletions
13
moslice/foreach.go
Normal file
13
moslice/foreach.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package moslice
|
||||
|
||||
// ForEachWithError runs the passed in function for each element of T. If an error
|
||||
// is encountered, the error is returned immediately and any subsequence elements
|
||||
// will not be processed.
|
||||
func ForEachWithError[T any](ts []T, fn func(t T) error) error {
|
||||
for _, t := range ts {
|
||||
if err := fn(t); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue