Generics.pw: Go Generics Made Easy.


Why?

What is the solution?

How to use it?

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".

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

Advance Usage

Custom Types:
Any valid import URL can be used as long as you replace / with :, this also works for local urls.
Available (optional) shortcuts:
ShortcutExpands To
ggenerics.pw/t/
gpgopkg.in/
ghgithub.com/
gccode.google.com/p/
gcgcode.google.com/p/go.
bbbitbucket.org/
lplaunchpad.net/

Example:

import "generics.pw/t/safemap=lmap/string/*tng.TCPListener=gh:OneOfOne:net-tng"

Using other generic types as custom types:
Paramaters for custom types are 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.
Custom Compare Functions not available yet:
If your type doesn't support native compare operators (=, <), 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"
How to create a custom template to submit?
VariableMeaning
Ppackage name
Npackage type name
Ttype 1
Utype 2
Vtype 3
Wtype 4
Xtype 5
Ytype 6
Ztype 7

FAQ

Where's the source for available templates?
on github @ tmpl/
How to add / improve a current template?
Fork the project on github, add the type following the specs and send a pull request.
Is this project a fork of or based on gonerics.io?
Not at all, I've been working on this idea for quiet sometime, we're using completely different approaches to the problem.
Fork me on GitHub