interfacestries to help with that, they come at a heavy runtime-performance cost.
The template url consists of:
generics.pw/t/template-name[=type-name[,pkgname][,cmp]]/*pkg.type1[=import-path]/typeN[=import-path]
if pkg. is omitted when importing a custom type, the type will be imported as import . "yourtype".
import "generics.pw/t/set/int"git clone https://generics.pw/t/set/intgo get "generics.pw/t/set/int"curl -O -J -L https://generics.pw/t/set/int.go, you will have a file named set_int.go in the current directory.
If =type-name is omitted, the package name will be main if the file is downloaded directly or lowercase template-name if imported using git, and the type name will be capitalized Templatename
/ with :, this also works for local urls.| Shortcut | Expands To |
| g | generics.pw/t/ |
| gp | gopkg.in/ |
| gh | github.com/ |
| gc | code.google.com/p/ |
| gcg | code.google.com/p/go. |
| bb | bitbucket.org/ |
| lp | launchpad.net/ |
Example:
import "generics.pw/t/safemap=lmap/string/*tng.TCPListener=gh:OneOfOne:net-tng"
T = Type #1 , U and V = Type #3, knowing that, you can mix and match generic types together:
import "generics.pw/t/safemap/string/*Set=g:set:V/string" // = map[string]*Set where Set is an int Set.
=, <), you will have to define a Cmp function on your type, assuming the template requires comparision for your type (for example heap or sort):
// yourtype.go
func (t *Type) Cmp(o *Type) int {
switch {
case t > o: return 1
case t == o: return 0
}
return -1
}
// import code
import "generics.pw/t/heap=,cmp/*MyType=gh:you:YourType"
| Variable | Meaning |
P | package name |
N | package type name |
T | type 1 |
U | type 2 |
V | type 3 |
W | type 4 |
X | type 5 |
Y | type 6 |
Z | type 7 |