z

package module
v0.0.0-...-4cab1b3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2023 License: Apache-2.0 Imports: 1 Imported by: 45

README

z

z exposes a curated set of utility functions.

Goals

Its primary goals are two-fold:

  1. Make the best commonly used utilities discoverable; "Ugh! What's the import for that helper again?"
  2. Reduce hand strain; "I can finally stop writing func must(...) everywhere!"

Why call it 'z'?

First off, it's a much better name than 'y'.

Besides that, the choice in name is supported by a few rules-of-thumb:

  • A smaller package name is more ergonomic (z.Pointer("foo") vs. utils.Pointer("foo"))
  • The last letter of the alphabet is probably definitely less likely to be shadowed by dependents
  • It's memorable (and fun to say out loud while typing!)

Adding to this Module

This module has two distinct classes of utilities, each with their own purpose and threshold for acceptance.

A) External

External utilities are curated components of external packages that are re-exported by z to make them more easily discoverable.

The bar for accepting PRs adding external utilities should be low, since the source is not maintained in z.

B) Local

Local utilities are home baked, and should consist of the most often reimplemented helpers.

The bar for accepting PRs adding local utilities should be high, since the source is maintained in z.

Documentation

Overview

Package z exposes a curated set of utility functions.

Its primary goals are two-fold:

  1. Make the best commonly used utilities discoverable
  2. Reduce hand strain; "I can finally stop writing `func must(...)` everywhere!"

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToMap

func AddToMap[K comparable, V any](m map[K]V, k K, v V) map[K]V

AddToMap will add the key value pair to the map, ensuring that the map is not nil.

func ConcatMaps

func ConcatMaps[K comparable, V any](ms ...map[K]V) map[K]V

ConcatMaps will iteratively add all the key/value pairs from each map, overwriting existing keys. That is, if every map in ms has the same key, then the value of that key in the resulting map will be the value of the key in the last map in ms. If no maps are provided, then a nil map is returned. If at least one map is provided (nil or not), then a non-nil map is returned.

func Dereference

func Dereference[T any](p *T) (v T)

Dereference returns the dereferenced value of p. If p is nil, the zero value of T is returned instead. This function is intended to be used to dereference native types (e.g. *int, *string, etc.); for structs, use of Dereference may decrease readability and obscure intent, so prefer a conditional (e.g. `if p != nil { ... }`) instead.

func Must

func Must(errs ...error)

Must panics IFF any error in errs is non-nil.

func MustBe

func MustBe[T any](t T, err error) T

MustBe panics IFF err is non-nil, otherwise it returns t.

func Pointer

func Pointer[T any](v T) *T

Pointer returns a pointer to v.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL