gitlab.com/evatix-go/core@v1.3.55/conditional/executeErrorFunctions.go (about)

     1  package conditional
     2  
     3  import (
     4  	"strconv"
     5  
     6  	"gitlab.com/evatix-go/core/constants"
     7  	"gitlab.com/evatix-go/core/errcore"
     8  )
     9  
    10  func executeErrorFunctions(functions []func() error) error {
    11  	if len(functions) == 0 {
    12  		return nil
    13  	}
    14  
    15  	var sliceErr []string
    16  	for index, currentFunction := range functions {
    17  		if currentFunction == nil {
    18  			continue
    19  		}
    20  
    21  		err := currentFunction()
    22  
    23  		if err != nil {
    24  			sliceErr = append(sliceErr, err.Error()+"- index of - "+strconv.Itoa(index))
    25  		}
    26  	}
    27  
    28  	return errcore.SliceToError(sliceErr)
    29  }
    30  
    31  func executeAnyFunctions(
    32  	functions []func() (
    33  		result interface{},
    34  		isTake,
    35  		isBreak bool,
    36  	),
    37  ) []interface{} {
    38  	if len(functions) == 0 {
    39  		return nil
    40  	}
    41  
    42  	results := make(
    43  		[]interface{},
    44  		constants.Zero,
    45  		len(functions))
    46  	for _, curFunc := range functions {
    47  		if curFunc == nil {
    48  			continue
    49  		}
    50  
    51  		result, isTake, isBreak := curFunc()
    52  
    53  		if isTake {
    54  			results = append(results, result)
    55  		}
    56  
    57  		if isBreak {
    58  			return results
    59  		}
    60  	}
    61  
    62  	return results
    63  }