Skip to content

Filter and double ​

filter-and-double combines stable filtering with checked doubling. Its generated Go returns both the result and a possible arithmetic error.

Stated source ​

Source mapGrammarVocabularyTypeName / reference
Define filter-and-double as a function.It accepts an integer sequence named input and an integer named threshold.Collect the input values in encounter order into a fresh sequence. Retain each value only when it is greater than the threshold. Replace each retained value with the doubled value of that value before appending it.

Generated Go ​

go
package generated

import (
	"errors"
	"math"
)

func FilterAndDouble(p0 []int64, p1 int64) ([]int64, error) {
	result := make([]int64, 0)
	for _, value := range p0 {
		if value > p1 {
			if value > math.MaxInt64/2 || value < math.MinInt64/2 {
				return nil, errors.New("integer overflow")
			}
			result = append(result, value+value)
		}
	}
	return result, nil
}

Download the Stated source · Download the generated Go

Stated compiles controlled English deterministically. It does not call an LLM at compile time.