mcnulty

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: Apache-2.0 Imports: 0 Imported by: 3

README

mcnulty

Go Report Card Documentation

mcnulty is a real downer. No matter what sort of type you give McNulty, ol' McNulty always returns a zero value that is appropriate for that type.

Why?!

Two reasons:

  1. As I work more and more with generic, I keep running into comparison issues with the standard blah == nil pattern. Because, you know, you might receive a non-nilable thingy.
  2. I never met a pun I didn't want to take to dinner.
  3. I like incredibly small modules that provide value.
  4. I can't count.

Installation

Go 1.18+ required, as mcnulty uses generics.

go get -u codeberg.org/ess/mcnulty

Usage

package main

import "mcnulty"

func main() {
  var x int

  // use your imagination and assume that we do something that manipulates x

  if x == mcnulty.Nil[int]() {
    panic("McNulty says no!")
  }
}

History

  • v1.0.0 - First (and likely only) release

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Nil

func Nil[T any]() T

Nil returns the zero value of the given type. For a pointer type, it returns nil. For a struct type, it returns a struct with all fields set to their zero value. For a slice type, it returns nil. For a map type, it returns nil. For a channel type, it returns nil. For a function type, it returns nil. For an interface type, it returns nil. For a string type, it returns "". For a numeric type, it returns 0. For a boolean type, it returns false. For a complex type, it returns 0i.

Types

This section is empty.

Jump to

Keyboard shortcuts

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