tsyncmap

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 1 Imported by: 4

README

🗺️️ Generic sync.Map

Go package GitHub GitHub go.mod Go version

A wrap around sync.Map that uses generics.

package main

import "github.com/survivorbat/go-tsyncmap"

func main() {
	myMap := tsyncmap.Map[string, string]{}
	
	myMap.Store("a", "b")
	
	myMap.Load("a") // Returns "b"
}

⬇️ Installation

go get github.com/survivorbat/go-tsyncmap

📋 Usage

package main

import "github.com/survivorbat/go-tsyncmap"

func main() {
	myMap := tsyncmap.Map[string, string]{}

	myMap.Store("a", "b")

	myMap.Load("a") // Returns "b"
}

🔭 Plans

Not much.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map[K any, V any] struct {
	// sync.Map is exported for flexibility, so you can still
	// use it if required
	sync.Map
}

Map mimics sync.Map but with generics

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K)

Delete mimics sync.Map{}'s Delete

func (*Map[K, V]) Load

func (m *Map[K, V]) Load(key K) (V, bool)

Load mimics sync.Map{}'s Load

Example
myMap := Map[string, string]{}
myMap.Store("a", "b")

result, ok := myMap.Load("a")
fmt.Println(result, ok)

func (*Map[K, V]) LoadAndDelete

func (m *Map[K, V]) LoadAndDelete(key K) (V, bool)

LoadAndDelete mimics sync.Map{}'s LoadAndDelete

func (*Map[K, V]) LoadOrStore

func (m *Map[K, V]) LoadOrStore(key K, value V) (V, bool)

LoadOrStore mimics sync.Map{}'s LoadOrStore

func (*Map[K, V]) Range

func (m *Map[K, V]) Range(f func(key K, value V) bool)

Range mimics sync.Map{}'s Range

func (*Map[K, V]) Store

func (m *Map[K, V]) Store(key K, value V)

Store mimics sync.Map{}'s Store

Example
myMap := Map[string, string]{}
myMap.Store("a", "b")

result, ok := myMap.Load("a")
fmt.Println(result, ok)

Jump to

Keyboard shortcuts

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