Updated map and reduce function names so that they aren't exported
This commit is contained in:
@@ -831,10 +831,10 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
// For each postfixNode in node.except, extract the contents of the postfixNode. Concatenate them all,
|
||||
// and them to the state's _content_. As mentioned above, if the exception has exceptions, then we can match
|
||||
// those.
|
||||
nodeExceptChars := slices.Concat(Map(node.except, func(node postfixNode) []rune {
|
||||
nodeExceptChars := slices.Concat(funcMap(node.except, func(node postfixNode) []rune {
|
||||
nodeContents := node.contents
|
||||
if caseInsensitive {
|
||||
nodeContents = slices.Concat(Map(nodeContents, func(r rune) []rune {
|
||||
nodeContents = slices.Concat(funcMap(nodeContents, func(r rune) []rune {
|
||||
return allCases(r, caseInsensitive)
|
||||
})...)
|
||||
}
|
||||
@@ -844,7 +844,7 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
} else {
|
||||
charsToAdd := node.contents
|
||||
if caseInsensitive {
|
||||
charsToAdd = slices.Concat(Map(charsToAdd, func(r rune) []rune {
|
||||
charsToAdd = slices.Concat(funcMap(charsToAdd, func(r rune) []rune {
|
||||
return allCases(r, caseInsensitive)
|
||||
})...)
|
||||
}
|
||||
@@ -857,7 +857,7 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
// convert back to stateContents.
|
||||
runesToAdd := c.contents
|
||||
if caseInsensitive {
|
||||
runesToAdd = slices.Concat(Map(runesToAdd, func(r rune) []rune {
|
||||
runesToAdd = slices.Concat(funcMap(runesToAdd, func(r rune) []rune {
|
||||
return allCases(r, caseInsensitive)
|
||||
})...)
|
||||
}
|
||||
@@ -971,18 +971,18 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
}
|
||||
if c.nodetype == CHARCLASS { // A Character class consists of all the nodes in it, alternated
|
||||
// Map the list of nodes to a list of states, each state containing the contents of a specific node
|
||||
states := Map(c.nodeContents, func(node postfixNode) *State {
|
||||
states := funcMap(c.nodeContents, func(node postfixNode) *State {
|
||||
s := newState()
|
||||
nodeContents := node.contents
|
||||
if caseInsensitive {
|
||||
nodeContents = slices.Concat(Map(nodeContents, func(r rune) []rune {
|
||||
nodeContents = slices.Concat(funcMap(nodeContents, func(r rune) []rune {
|
||||
return allCases(r, caseInsensitive)
|
||||
})...)
|
||||
}
|
||||
s.content = rune2Contents(nodeContents)
|
||||
if len(node.except) > 0 {
|
||||
s.allChars = true
|
||||
s.except = slices.Concat(Map(node.except, func(n postfixNode) []rune {
|
||||
s.except = slices.Concat(funcMap(node.except, func(n postfixNode) []rune {
|
||||
return n.contents
|
||||
})...)
|
||||
}
|
||||
|
@@ -74,7 +74,7 @@ func allEqual[T comparable](items ...T) bool {
|
||||
|
||||
// Map function - convert a slice of T to a slice of V, based on a function
|
||||
// that maps a T to a V
|
||||
func Map[T, V any](slc []T, fn func(T) V) []V {
|
||||
func funcMap[T, V any](slc []T, fn func(T) V) []V {
|
||||
toReturn := make([]V, len(slc))
|
||||
for i, val := range slc {
|
||||
toReturn[i] = fn(val)
|
||||
@@ -84,7 +84,7 @@ func Map[T, V any](slc []T, fn func(T) V) []V {
|
||||
|
||||
// Reduce function - reduces a slice of a type into a value of the type,
|
||||
// based on the given function.
|
||||
func Reduce[T any](slc []T, fn func(T, T) T) T {
|
||||
func funcReduce[T any](slc []T, fn func(T, T) T) T {
|
||||
if len(slc) == 0 {
|
||||
panic("Reduce on empty slice.")
|
||||
}
|
||||
|
Reference in New Issue
Block a user