generic

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package generic provides code generator that takes go sources of a generic-like go code and generates concrete implementation by substituting predefined type variables (T1,.., T5) to a given type names

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrBadTypeVar indicates that type var is unsupported
	ErrBadTypeVar = errors.New("Bad type variable")
)

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func BuiltInTypes

func BuiltInTypes() []string

BuiltInTypes return a slice with built-in generic type names

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator implements a generic code generator

func BuiltIn

func BuiltIn(typeName string) (*Generator, error)

BuiltIn return a generator object by a given built-in type name

func FromBytes

func FromBytes(src []byte) *Generator

FromBytes returns Generator from byte source

func FromFile

func FromFile(filename string) *Generator

FromFile returns Generator from a given file

func (*Generator) Generate

func (g *Generator) Generate(w io.Writer) error

Generate generates implementation based on generic code and writes it to the Writer

func (*Generator) WithPackageName

func (g *Generator) WithPackageName(name string) *Generator

WithPackageName sets the package name

func (*Generator) WithTypeMapping

func (g *Generator) WithTypeMapping(typeVars TypeMap) *Generator

WithTypeMapping sets type vars mapping to concrete types

type TypeMap

type TypeMap map[TypeVar]string

TypeMap maps type variable names to concrete type names

func TypeMapFromStrings

func TypeMapFromStrings(types ...string) TypeMap

TypeMapFromStrings returns TypeMap filled with given type var names

type TypeVar

type TypeVar string

TypeVar indicates generic type variable name

const (
	// T0 generic type name
	T0 TypeVar = "T0"
	// T1 generic type name
	T1 TypeVar = "T1"
	// T2 generic type name
	T2 TypeVar = "T2"
	// T3 generic type name
	T3 TypeVar = "T3"
	// T4 generic type name
	T4 TypeVar = "T4"
	// T5 generic type name
	T5 TypeVar = "T5"
)

Directories

Path Synopsis
Package converter provides a built-in implementation of generic routines for collection based conversion.
Package converter provides a built-in implementation of generic routines for collection based conversion.
Package hashmap provides a built-in implementation of a generic map
Package hashmap provides a built-in implementation of a generic map
Package iterator provides a built-in implementation of an ideomatic generic iterator
Package iterator provides a built-in implementation of an ideomatic generic iterator
Package list provides a built-in implementation of a generic list
Package list provides a built-in implementation of a generic list
Package set provides a built-in implementation of a generic set
Package set provides a built-in implementation of a generic set

Jump to

Keyboard shortcuts

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