Skip to content

The uniqueslice package provides facilities for canonicalizing ("interning") slices of comparable values.

License

Notifications You must be signed in to change notification settings

Snawoot/uniqueslice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

uniqueslice

The uniqueslice package provides facilities for canonicalizing ("interning") slices of comparable values.

Documentation

GoDoc

Example

package main

import (
	"bufio"
	"fmt"
	"strings"

	"github.com/Snawoot/uniqueslice"
)

func main() {
	r := strings.NewReader(`123
1234
123`)
	scanner := bufio.NewScanner(r)
	var handles []uniqueslice.Handle[[]byte, byte]
	for scanner.Scan() {
		handles = append(handles, uniqueslice.Make(scanner.Bytes()))
	}
	if err := scanner.Err(); err != nil {
		panic(fmt.Errorf("scanner error: %v", err))
	}
	for i, h := range handles {
		fmt.Printf("handles[%d] = %v (%q)\n", i, h.Value(), h.Value())
	}
	if handles[0] != handles[2] {
		panic("handles[0] != handles[2]")
	}
	if handles[0] == handles[1] {
		panic("handles[0] == handles[1]")
	}
}

About

The uniqueslice package provides facilities for canonicalizing ("interning") slices of comparable values.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages