mk

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: MIT Imports: 0 Imported by: 1

Documentation

Overview

Package mk provides type-inference wrappers around make().

Sometimes when calling make(T), T has already been declared elsewhere. For example, if initializing a map in a struct, you might wind up with a situation like

struct Example {
  Values map[string]any
}

func NewExample() *Example {
  return &Example{Values: make(map[string]any)}
}

Note how the type of the map is repeated. It is this exact situation that this package is for. Instead of repeating the type, you can use this package to eliminate the repetition:

func NewExample() *Example {
  var ex Example
  mk.Map(&ex.Values, 0)
  return &ex
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chan

func Chan[C ~chan E, E any](c *C, cap int)

Cap makes a channel of the given capacity and stores it in c.

func Map

func Map[M ~map[K]V, K comparable, V any](m *M, cap int)

Map makes a map of the given capacity and stores it in m.

func Slice

func Slice[S ~[]E, E any](s *S, len, cap int)

Slice makes a slice of the given length and capacity and stores it in s.

Types

This section is empty.

Jump to

Keyboard shortcuts

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