Documentation
¶
Overview ¶
Package ks ("kitchen sink") implements assorted helpful things that don't fit anywhere else.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterError ¶ added in v2.8.0
FilterError returns err, unless errors.Is(err, i) returns true for any i in ignore, in which case it returns nil.
For example,
// Create a symlink but ignore an error if the file exists. err := FilterError(os.Symlink(oldname, newname), fs.ErrExist)
func MustMap ¶ added in v2.7.0
func MustMap[K comparable, V any](m map[K]V) map[K]V
MustMap is used to construct a map if it is nil, or return the input unchanged (i.e. the identity function) if it is not nil. This is useful for conditionally initialising a map that may or may not be its zero value.
func Reserve
deprecated
added in
v2.6.0
Reserve grows a slice to fit at least size extra elements. Like the builtin append, it may return an updated slice.
Deprecated: use golang.org/x/exp/slices.Grow.
func WrapBlock ¶ added in v2.0.1
WrapBlock word-wraps a whitespace-delimited string to a given number of columns. The column length is given in runes (Unicode code points), not bytes.
This is a simple implementation without any configuration options, designed for circumstances such as quickly wrapping a single error message for display.
Save for bug fixes, the output of this function for any given input is frozen and will not be changed in future. This means you can reliably test against the return value of this function without your tests being brittle.
Caveat: Single words longer than the column length will be truncated.
Caveat: all whitespace, including existing new lines, is collapsed. An input consisting of multiple paragraphs will be wrapped into a single word-wrapped paragraph.
Caveat: assumes all runes in the input string represent a glyph of length one. Whether this is true or not depends on how the display and font treats different runes. For example, some runes where [Unicode.IsGraphic] returns false might still be displayed as a special escaped character. Some letters might be displayed wider than usual, even in a monospaced font.
Types ¶
This section is empty.