markphelps / optional

Optional is a library of optional Go types
https://godoc.org/github.com/markphelps/optional
MIT License
209 stars 19 forks source link

Add string method to trim whitespace #27

Closed mjwenzke closed 1 year ago

mjwenzke commented 1 year ago

This PR adds a method to trim the whitespace from optional.String type. The built-in strings.Trim() function does not work for the optional.String types.

o := NewString("  This is a string.  ")
o.Trim()

After the Trim() function is called, the value of o is This is a string.. The outer whitespace has been trimmed.

markphelps commented 1 year ago

Thanks for the contribution @mjwenzke !

String is generated like all the other types in this package see: here, so unfortunately we cant just add a method to one type as it would be overwritten next time the generator runs.

Its prob better to just call strings.Trim after getting the value from the optional type