ericcornelissen/wordrow

Update code base to use Go's built-in map type instead of WordMap

Closed this issue · 0 comments

Implementation update

  • wordrow version: v0.4.0-beta

Description

Update the implementation to use Golang's built-in map type instead of the custom WordMap type to store replacements in memory. A simple map[string]string, where from is the key and to is the value, provides almost the same guarentees as a WordMap with the exception that it doesn't prevent storing empty strings (neither as key or as value).

There are two other potential issues that may result from making this switch:

  • map[string]string cannot be used to store multiple mappings for one from value. In practice this is not a problem as after any instance of from has been replaced, the later mappings defined for from are no longer relevant (unless another mapping in between inserts new instances of the from value. However, this behaviour is currently neither a feature nor a bug and is in my opinion not desired as it makes the behaviour difficult to understand and unpredictable when using multiple mapping files). It is important to note that the described change would result in a change of behaviour. With the current implementation the first definition of a from value takes effect, with a map[string]string the value would be overridden and the last definition of a from value takes effect.
  • There is no built-in way to "invert" a map[string]string whereas the WordMap struct does. Of course, a simple for-loop can be used to invert a map.