8e596d5979
1. moved scan/symbol.go to new package sym and adapted all files that reference Symbol type and its values. 2. new type interval defined by begin, end and step values. 3. replaced operator-range.go with operator-interval.go. 4. replaced range operator begin:end with begin..end..step. 5. new implementation of sub-collection extraction based on new interval literal.
69 lines
1.1 KiB
Go
69 lines
1.1 KiB
Go
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
// All rights reserved.
|
|
|
|
// interval.go
|
|
package interval
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.portale-stac.it/go-pkg/expr/kern"
|
|
)
|
|
|
|
const TypeName = "interval"
|
|
|
|
type IntervalType struct {
|
|
begin, end, step int64
|
|
}
|
|
|
|
func NewInterval(begin, end, step int64) *IntervalType {
|
|
return &IntervalType{
|
|
begin: begin,
|
|
end: end,
|
|
step: step,
|
|
}
|
|
}
|
|
|
|
func (p *IntervalType) Begin() int64 {
|
|
return p.begin
|
|
}
|
|
|
|
func (p *IntervalType) End() int64 {
|
|
return p.end
|
|
}
|
|
|
|
func (p *IntervalType) Step() int64 {
|
|
return p.step
|
|
}
|
|
|
|
func IsInterval(v any) (ok bool) {
|
|
_, ok = v.(*IntervalType)
|
|
return ok
|
|
}
|
|
|
|
func (p *IntervalType) TypeName() string {
|
|
return TypeName
|
|
}
|
|
|
|
func (p *IntervalType) ToString(opt kern.FmtOpt) string {
|
|
return fmt.Sprintf("%d..%d..%d", p.begin, p.end, p.step)
|
|
}
|
|
|
|
func (p *IntervalType) String() string {
|
|
return p.ToString(0)
|
|
}
|
|
|
|
func (p *IntervalType) ToIntTriple() (b, e, s int) {
|
|
b = int(p.begin)
|
|
e = int(p.end)
|
|
s = int(p.step)
|
|
return
|
|
}
|
|
|
|
// func (b *bool) EqualTo(other kern.Equaler) (equal bool) {
|
|
// if otherBool, ok := other.(*bool); ok {
|
|
// equal = b == otherBool
|
|
// }
|
|
// return
|
|
// }
|