gitlab.com/evatix-go/core@v1.3.55/converters/StringToIntegersConditional.go (about)

     1  package converters
     2  
     3  import "strings"
     4  
     5  func StringToIntegersConditional(
     6  	stringInput,
     7  	separator string,
     8  	processor func(in string) (out int, isTake, isBreak bool),
     9  ) *[]int {
    10  	if stringInput == "" {
    11  		return &[]int{}
    12  	}
    13  
    14  	splits := strings.Split(stringInput, separator)
    15  	results := make([]int, 0, len(splits))
    16  
    17  	for _, v := range splits {
    18  		out, isTake, isBreak := processor(v)
    19  
    20  		if isTake {
    21  			results = append(results, out)
    22  		}
    23  
    24  		if isBreak {
    25  			break
    26  		}
    27  	}
    28  
    29  	return &results
    30  }