Skip to content

tpl/math: Add MaxInt64 function #13693

@jmooring

Description

@jmooring

Now that we have a break statement it would be handy (in some rare scenarios) if we could do:

{{ range }} <----------- do this forever until break
  {{ if $someBoolean }}
    {{ break }}
  {{ end }}
{{ end }}

But you can't do that... range requires an argument.

The text/template package in Go 1.22 and later supports range over int, so you can now do this:

{{ range 1000000000 }}  <----------- do this many times until break
  {{ if $someBoolean }}
    {{ break }}
  {{ end }}
{{ end }}

It would be cleaner if we could do this:

{{ range math.MaxInt64 }}  <----------- do this 9223372036854775807 times until break
  {{ if $someBoolean }}
    {{ break }}
  {{ end }}
{{ end }}

It's not infinite, but it's close enough for most cases that I can envision.

// MaxInt64 returns the maximum value for a signed 64-bit integer.
func (ns *Namespace) MaxInt64() int64 {
	return math.MaxInt64
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions