Initial commit of modash

This was taken from github.com/lmika/gopkgs/fp
This commit is contained in:
Leon Mika 2025-01-27 13:19:52 +11:00
commit a20530ddfd
20 changed files with 425 additions and 0 deletions

13
moslice/foreach.go Normal file
View 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
}