Conjunction and double
This example combines two threshold conditions and a checked transformation in one named function.
Stated source
Define filter-twice-and-double as a function.It accepts an integer sequence named input, an integer named threshold and another integer named other-threshold.Collect the input values in encounter order into a fresh sequence. Retain each value only when it is greater than the threshold and it is greater than the other-threshold. Replace each retained value with the doubled value of that value before appending it.Generated Go
go
package generated
import (
"errors"
"math"
)
func FilterTwiceAndDouble(p0 []int64, p1 int64, p2 int64) ([]int64, error) {
result := make([]int64, 0)
for _, value := range p0 {
if value > p1 && value > p2 {
if value > math.MaxInt64/2 || value < math.MinInt64/2 {
return nil, errors.New("integer overflow")
}
result = append(result, value+value)
}
}
return result, nil
}