Move 'genRange' function to 'cmd'

master
Aadhavan Srinivasan 3 days ago
parent ee6bb3959c
commit c3c3829ac9

@ -2,6 +2,10 @@ package main
import "slices" import "slices"
type character interface {
int | rune
}
// Returns all elements in slice A that are NOT in slice B // Returns all elements in slice A that are NOT in slice B
func setDifference[T comparable](s1 []T, s2 []T) []T { func setDifference[T comparable](s1 []T, s2 []T) []T {
toReturn := make([]T, 0, len(s1)) toReturn := make([]T, 0, len(s1))
@ -12,3 +16,12 @@ func setDifference[T comparable](s1 []T, s2 []T) []T {
} }
return toReturn return toReturn
} }
// Generate numbers in a range - start (inclusive) to end (exclusive)
func genRange[T character](start, end T) []T {
toRet := make([]T, end-start)
for i := start; i < end; i++ {
toRet[i-start] = i
}
return toRet
}

@ -97,22 +97,15 @@ func Reduce[T any](slc []T, fn func(T, T) T) T {
return slc[0] return slc[0]
} }
// Generate numbers in a range - start (inclusive) to end (exclusive) // Generate numbers in a range - start to end (both inclusive)
func genRange[T character](start, end T) []T { func genRangeInclusive[T character](start, end T) []T {
toRet := make([]T, end-start) toRet := make([]T, end-start)
for i := start; i < end; i++ { for i := start; i <= end; i++ {
toRet[i-start] = i toRet[i-start] = i
} }
return toRet return toRet
} }
// Generate numbers in a range - start to end (both inclusive)
func genRangeInclusive[T character](start, end T) []T {
toRet := genRange(start, end)
toRet = append(toRet, end)
return toRet
}
// Returns a rune-slice containing all possible cases of the given rune, given the // Returns a rune-slice containing all possible cases of the given rune, given the
// 'caseInsensitive' boolean variable. // 'caseInsensitive' boolean variable.
// If this variable is false, the rune is returned as-is, without modifications. // If this variable is false, the rune is returned as-is, without modifications.

Loading…
Cancel
Save