MapError implemented
This commit is contained in:
		
							
								
								
									
										12
									
								
								map.go
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								map.go
									
									
									
									
									
								
							@ -7,3 +7,15 @@ func Map[I, O any](slice []I, mapper func(I) O) []O {
 | 
			
		||||
	}
 | 
			
		||||
	return ret
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func MapError[I, O any](slice []I, mapper func(I) (O, error)) ([]O, error) {
 | 
			
		||||
	ret := make([]O, 0, len(slice))
 | 
			
		||||
	for _, old := range slice {
 | 
			
		||||
		new, err := mapper(old)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		ret = append(ret, new)
 | 
			
		||||
	}
 | 
			
		||||
	return ret, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user