You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Trim returns a slice with all leading and trailing elements of s contained in v removed.funcTrim[S~[]E, Ecomparable](sS, v...E) S// TrimLeft returns a slice with all leading elements of s contained in v removed.funcTrimLeft[S~[]E, Ecomparable](sS, v...E) S// TrimRight returns a slice with all trailing elements of s contained in v removed.funcTrimRight[S~[]E, Ecomparable](sS, v...E) S// TrimFunc returns a slice with all leading and trailing elements of s that satisfy f removed.funcTrimFunc[S~[]E, Eany](sS, ffunc(E) bool) bool// TrimLeftFunc returns a slice with all leading elements of s that satisfy f removed.funcTrimLeftFunc[S~[]E, Eany](sS, ffunc(E) bool) bool// TrimRightFunc returns a slice with all trailing elements of s that satisfy f removed.funcTrimRightFunc[S~[]E, Eany](sS, ffunc(E) bool) bool
These functions match similar functions found in the "bytes" and "strings" packages:
Trim
TrimLeft
TrimRight
TrimFunc
TrimLeftFunc
TrimRightFunc
The text was updated successfully, but these errors were encountered:
While in general we want slices to follow bytes and strings, I think we've learned over the years that the use of "left" and "right" is parochial and confusing. We should use "begin" and "end" or something similar.
Changing the words "Left" and "Right" sounds fine to me, but I do have a preference for consistency with the "strings" and "bytes" package. Presumably we would introduce functions with the updated names there too?
the *Func variants feel really close to a theoretical Filter
It's actually more like DropWhile because it stops filtering after the first false return and then just returns the rest, even if it passes the filter.
I like slices.DeleteFunc because it takes the convoluted idiom for filtering a slice in place and makes it much simpler. If these return new slices, I'm not sure they meet the bar for simplifying complicated code you could just write some other way.
Proposal Details
I propose the addition of:
These functions match similar functions found in the "bytes" and "strings" packages:
Trim
TrimLeft
TrimRight
TrimFunc
TrimLeftFunc
TrimRightFunc
The text was updated successfully, but these errors were encountered: