Updated map and reduce function names so that they aren't exported

master
Aadhavan Srinivasan 3 days ago
parent f6d56b74e1
commit 24a5045ebe

@ -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, // 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 // and them to the state's _content_. As mentioned above, if the exception has exceptions, then we can match
// those. // those.
nodeExceptChars := slices.Concat(Map(node.except, func(node postfixNode) []rune { nodeExceptChars := slices.Concat(funcMap(node.except, func(node postfixNode) []rune {
nodeContents := node.contents nodeContents := node.contents
if caseInsensitive { if caseInsensitive {
nodeContents = slices.Concat(Map(nodeContents, func(r rune) []rune { nodeContents = slices.Concat(funcMap(nodeContents, func(r rune) []rune {
return allCases(r, caseInsensitive) return allCases(r, caseInsensitive)
})...) })...)
} }
@ -844,7 +844,7 @@ func thompson(re []postfixNode) (Reg, error) {
} else { } else {
charsToAdd := node.contents charsToAdd := node.contents
if caseInsensitive { if caseInsensitive {
charsToAdd = slices.Concat(Map(charsToAdd, func(r rune) []rune { charsToAdd = slices.Concat(funcMap(charsToAdd, func(r rune) []rune {
return allCases(r, caseInsensitive) return allCases(r, caseInsensitive)
})...) })...)
} }
@ -857,7 +857,7 @@ func thompson(re []postfixNode) (Reg, error) {
// convert back to stateContents. // convert back to stateContents.
runesToAdd := c.contents runesToAdd := c.contents
if caseInsensitive { if caseInsensitive {
runesToAdd = slices.Concat(Map(runesToAdd, func(r rune) []rune { runesToAdd = slices.Concat(funcMap(runesToAdd, func(r rune) []rune {
return allCases(r, caseInsensitive) 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 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 // 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() s := newState()
nodeContents := node.contents nodeContents := node.contents
if caseInsensitive { if caseInsensitive {
nodeContents = slices.Concat(Map(nodeContents, func(r rune) []rune { nodeContents = slices.Concat(funcMap(nodeContents, func(r rune) []rune {
return allCases(r, caseInsensitive) return allCases(r, caseInsensitive)
})...) })...)
} }
s.content = rune2Contents(nodeContents) s.content = rune2Contents(nodeContents)
if len(node.except) > 0 { if len(node.except) > 0 {
s.allChars = true 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 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 // Map function - convert a slice of T to a slice of V, based on a function
// that maps a T to a V // 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)) toReturn := make([]V, len(slc))
for i, val := range slc { for i, val := range slc {
toReturn[i] = fn(val) 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, // Reduce function - reduces a slice of a type into a value of the type,
// based on the given function. // 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 { if len(slc) == 0 {
panic("Reduce on empty slice.") panic("Reduce on empty slice.")
} }

Loading…
Cancel
Save