ソースを参照

[add] 1.18版本更新

bvbej 2 年 前
コミット
1361ea90e1
99 ファイル変更103 行追加9171 行削除
  1. 0 25
      pkg/aes/aes_test.go
  2. 1 1
      pkg/android_binary/table.go
  3. 1 1
      pkg/android_binary/xml.go
  4. 13 9
      pkg/apollo/config.go
  5. 0 142
      pkg/apollo/config_test.go
  6. 0 23
      pkg/captcha/captcha_test.go
  7. 2 2
      pkg/color/string_darwin.go
  8. 2 2
      pkg/color/string_linux.go
  9. 2 2
      pkg/color/string_windows.go
  10. 0 32
      pkg/ddm/type_test.go
  11. 0 13
      pkg/duration_fmt/fmt_test.go
  12. 4 4
      pkg/errors/err.go
  13. 0 34
      pkg/errors/err_test.go
  14. 0 18
      pkg/hash/hash_hashids_test.go
  15. 1 1
      pkg/httpclient/option.go
  16. 4 4
      pkg/logger/logger.go
  17. 0 35
      pkg/logger/logger_test.go
  18. 0 23
      pkg/mail/mail_test.go
  19. 0 14
      pkg/md5/md5_test.go
  20. 1 1
      pkg/p/print.go
  21. 4 4
      pkg/proxy/out.go
  22. 10 10
      pkg/proxy/pool.go
  23. 1 1
      pkg/proxy/tcp.go
  24. 0 25
      pkg/proxy/tcp_test.go
  25. 0 77
      pkg/rsa/rsa_test.go
  26. 0 45
      pkg/signature/signature_test.go
  27. 0 19
      pkg/time_parse/time_parse_test.go
  28. 1 1
      pkg/token/token_jwt.go
  29. 0 54
      pkg/token/token_test.go
  30. 3 3
      pkg/trace/debug.go
  31. 9 9
      pkg/trace/grpc.go
  32. 12 12
      pkg/trace/trace.go
  33. 0 157
      pkg/urltable/urltable_test.go
  34. 10 10
      pkg/utils/map.go
  35. 3 3
      pkg/validator/validator.go
  36. 2 2
      pkg/websocket/codec/codec.go
  37. 2 2
      pkg/websocket/codec/json/json.go
  38. 5 5
      pkg/websocket/codec/meta.go
  39. 2 2
      pkg/websocket/codec/protobuf/protobuf.go
  40. 1 1
      pkg/websocket/peer/connect/connection.go
  41. 1 1
      pkg/websocket/peer/connection.go
  42. 1 1
      pkg/websocket/peer/session_manager.go
  43. 2 2
      pkg/websocket/service/component.go
  44. 1 1
      pkg/websocket/service/service_manager.go
  45. 2 2
      pkg/websocket/service/session_callback.go
  46. 0 158
      tool/help/aggregate.go
  47. 0 119
      tool/help/aggregate_test.go
  48. 0 93
      tool/help/benchmark_test.go
  49. 0 200
      tool/help/compare.go
  50. 0 65
      tool/help/compare_test.go
  51. 0 74
      tool/help/concat.go
  52. 0 31
      tool/help/concat_test.go
  53. 0 70
      tool/help/convert.go
  54. 0 57
      tool/help/convert_test.go
  55. 0 33
      tool/help/defaultifempty.go
  56. 0 25
      tool/help/defaultifempty_test.go
  57. 0 98
      tool/help/distinct.go
  58. 0 61
      tool/help/distinct_test.go
  59. 0 6
      tool/help/doc.go
  60. 0 2627
      tool/help/example_test.go
  61. 0 79
      tool/help/except.go
  62. 0 31
      tool/help/except_test.go
  63. 0 193
      tool/help/from.go
  64. 0 107
      tool/help/from_test.go
  65. 0 36
      tool/help/general_test.go
  66. 0 138
      tool/help/genericfunc.go
  67. 0 130
      tool/help/genericfunc_test.go
  68. 0 81
      tool/help/groupby.go
  69. 0 59
      tool/help/groupby_test.go
  70. 0 107
      tool/help/groupjoin.go
  71. 0 58
      tool/help/groupjoin_test.go
  72. 0 40
      tool/help/index.go
  73. 0 53
      tool/help/index_test.go
  74. 0 87
      tool/help/intersect.go
  75. 0 33
      tool/help/intersect_test.go
  76. 0 105
      tool/help/join.go
  77. 0 60
      tool/help/join_test.go
  78. 0 313
      tool/help/orderby.go
  79. 0 158
      tool/help/orderby_test.go
  80. 0 674
      tool/help/result.go
  81. 0 622
      tool/help/result_test.go
  82. 0 30
      tool/help/reverse.go
  83. 0 18
      tool/help/reverse_test.go
  84. 0 109
      tool/help/select.go
  85. 0 60
      tool/help/select_test.go
  86. 0 265
      tool/help/selectmany.go
  87. 0 154
      tool/help/selectmany_test.go
  88. 0 83
      tool/help/setup_test.go
  89. 0 134
      tool/help/skip.go
  90. 0 87
      tool/help/skip_test.go
  91. 0 129
      tool/help/take.go
  92. 0 80
      tool/help/take_test.go
  93. 0 40
      tool/help/union.go
  94. 0 13
      tool/help/union_test.go
  95. 0 90
      tool/help/where.go
  96. 0 60
      tool/help/where_test.go
  97. 0 55
      tool/help/zip.go
  98. 0 26
      tool/help/zip_test.go
  99. 0 22
      tool/signature_request/request_test.go

+ 0 - 25
pkg/aes/aes_test.go

@@ -1,25 +0,0 @@
-package aes
-
-import "testing"
-
-const (
-	key = "IgkibX71IEf382PT"
-	iv  = "IgkibX71IEf382PT"
-)
-
-func TestEncrypt(t *testing.T) {
-	t.Log(New(key, iv).Encrypt("123456"))
-}
-
-func TestDecrypt(t *testing.T) {
-	t.Log(New(key, iv).Decrypt("GO-ri84zevE-z1biJwfQPw=="))
-}
-
-func BenchmarkEncryptAndDecrypt(b *testing.B) {
-	b.ResetTimer()
-	aes := New(key, iv)
-	for i := 0; i < b.N; i++ {
-		encryptString, _ := aes.Encrypt("123456")
-		aes.Decrypt(encryptString)
-	}
-}

+ 1 - 1
pkg/android_binary/table.go

@@ -269,7 +269,7 @@ func (p *TablePackage) findEntry(typeIndex, entryIndex int, config *ResTableConf
 }
 
 // GetResource returns a resource referenced by id.
-func (f *TableFile) GetResource(id ResID, config *ResTableConfig) (interface{}, error) {
+func (f *TableFile) GetResource(id ResID, config *ResTableConfig) (any, error) {
 	p := f.findPackage(id.Package())
 	if p == nil {
 		return nil, fmt.Errorf("androidbinary: package 0x%02X not found", id.Package())

+ 1 - 1
pkg/android_binary/xml.go

@@ -86,7 +86,7 @@ func (f *XMLFile) Reader() *bytes.Reader {
 
 // Decode decodes XML file and stores the result in the value pointed to by v.
 // To resolve the resource references, Decode also stores default TableFile and ResTableConfig in the value pointed to by v.
-func (f *XMLFile) Decode(v interface{}, table *TableFile, config *ResTableConfig) error {
+func (f *XMLFile) Decode(v any, table *TableFile, config *ResTableConfig) error {
 	decoder := xml.NewDecoder(f.Reader())
 	if err := decoder.Decode(v); err != nil {
 		return err

+ 13 - 9
pkg/apollo/config.go

@@ -1,22 +1,22 @@
 package apollo
 
 import (
-	"fmt"
 	"git.bvbej.com/bvbej/base-golang/pkg/env"
 	"github.com/apolloconfig/agollo/v4"
 	"github.com/apolloconfig/agollo/v4/component/log"
 	apolloConfig "github.com/apolloconfig/agollo/v4/env/config"
 	"github.com/apolloconfig/agollo/v4/storage"
+	"github.com/pkg/errors"
 	"github.com/spf13/viper"
 )
 
 type clientConfig struct {
 	client agollo.Client
 	ac     *apolloConfig.AppConfig
-	conf   interface{}
+	conf   any
 }
 
-func GetApolloConfig(appId, secret string, config interface{}) {
+func GetApolloConfig(appId, secret string, config any) error {
 	var err error
 	namespace := env.Active().Value() + ".yaml"
 
@@ -37,24 +37,28 @@ func GetApolloConfig(appId, secret string, config interface{}) {
 		return c.ac, nil
 	})
 	if err != nil {
-		panic(fmt.Sprintf("get config error:[%s]", err))
+		return errors.Errorf("get config error:[%s]", err)
 	}
 	c.client.AddChangeListener(c)
 
 	err = c.serialization()
 	if err != nil {
-		panic(fmt.Sprintf("unmarshal config error:[%s]", err))
+		return errors.Errorf("unmarshal config error:[%s]", err)
 	}
+
+	return nil
 }
 
 func (c *clientConfig) serialization() error {
-	viper.SetConfigType("yaml")
-	c.client.GetConfigCache(c.ac.NamespaceName).Range(func(key, value interface{}) bool {
-		viper.Set(key.(string), value)
+	parser := viper.New()
+
+	parser.SetConfigType("yaml")
+	c.client.GetConfigCache(c.ac.NamespaceName).Range(func(key, value any) bool {
+		parser.Set(key.(string), value)
 		return true
 	})
 
-	return viper.Unmarshal(c.conf)
+	return parser.Unmarshal(c.conf)
 }
 
 func (c *clientConfig) OnChange(*storage.ChangeEvent) {

+ 0 - 142
pkg/apollo/config_test.go

@@ -1,142 +0,0 @@
-package apollo
-
-import (
-	"fmt"
-	"git.bvbej.com/bvbej/base-golang/pkg/time_parse"
-	"sync"
-	"testing"
-	"time"
-)
-
-var config = new(Config)
-
-type Config struct {
-	Server struct {
-		ListenAddr   string `yaml:"listenAddr"`
-		AppAddr      string `yaml:"appAddr"`
-		AuthAddr     string `yaml:"authAddr"`
-		RtmpBaseAddr string `yaml:"rtmpBaseAddr"`
-		ProductID    string `yaml:"productID"`
-	} `yaml:"server"`
-
-	EncryptKeys struct {
-		AesKey string `yaml:"aesKey"`
-		AesIv  string `yaml:"aesIv"`
-	} `yaml:"encryptKeys"`
-
-	MySQL struct {
-		Read struct {
-			Addr string `yaml:"addr"`
-			User string `yaml:"user"`
-			Pass string `yaml:"pass"`
-			Name string `yaml:"name"`
-		} `yaml:"read"`
-		Write struct {
-			Addr string `yaml:"addr"`
-			User string `yaml:"user"`
-			Pass string `yaml:"pass"`
-			Name string `yaml:"name"`
-		} `yaml:"write"`
-		Base struct {
-			MaxOpenConn     int           `yaml:"maxOpenConn"`     //最大连接数
-			MaxIdleConn     int           `yaml:"maxIdleConn"`     //最大空闲连接数
-			ConnMaxLifeTime time.Duration `yaml:"connMaxLifeTime"` //最大连接超时(分钟)
-		} `yaml:"base"`
-	} `yaml:"mysql"`
-
-	Redis struct {
-		Addr        string `yaml:"addr"`
-		Pass        string `yaml:"pass"`
-		Db          int    `yaml:"db"`
-		MaxRetries  int    `yaml:"maxRetries"`  // 最大重试次数
-		PoolSize    int    `yaml:"poolSize"`    // Redis连接池大小
-		MinIdleConn int    `yaml:"minIdleConn"` // 最小空闲连接数
-	} `yaml:"redis"`
-
-	URLToken struct {
-		Secret         string        `yaml:"secret"`
-		ExpireDuration time.Duration `yaml:"expireDuration"` //毫秒
-	} `yaml:"urlToken"`
-
-	HashIds struct {
-		Secret string `yaml:"secret"`
-		Length int    `yaml:"length"`
-	} `yaml:"hashids"`
-
-	DingTalkAlert struct {
-		Service struct {
-			AccessToken string `yaml:"accessToken"`
-			Secret      string `yaml:"secret"`
-		} `yaml:"service"`
-		Alarm struct {
-			AccessToken string `yaml:"accessToken"`
-			Secret      string `yaml:"secret"`
-		} `yaml:"alarm"`
-	} `yaml:"dingTalkAlert"`
-
-	IPProxy struct {
-		Addr      string `yaml:"addr"`
-		BasicAuth struct {
-			Username string `yaml:"username"`
-			Password string `yaml:"password"`
-		} `yaml:"basicAuth"`
-		CheckAddr string `yaml:"checkAddr"`
-		CheckAuth struct {
-			Username string `yaml:"username"`
-			Password string `yaml:"password"`
-		} `yaml:"checkAuth"`
-	} `yaml:"ipProxy"`
-
-	APP struct {
-		IOS struct {
-			Version     string `yaml:"version"`
-			IsForce     bool   `yaml:"isForce"`
-			DownloadUrl string `yaml:"downloadUrl"`
-			Log         string `yaml:"log"`
-		} `yaml:"ios"`
-		Android struct {
-			Version     string `yaml:"version"`
-			IsForce     bool   `yaml:"isForce"`
-			DownloadUrl string `yaml:"downloadUrl"`
-			Log         string `yaml:"log"`
-			Size        uint64 `yaml:"size"`
-		} `yaml:"android"`
-	} `yaml:"app"`
-
-	Mail struct {
-		Host string `yaml:"host"`
-		Port int    `yaml:"port"`
-		User string `yaml:"user"`
-		Pass string `yaml:"pass"`
-		To   string `yaml:"to"`
-	} `yaml:"mail"`
-
-	Alipay struct {
-		NotifyURL string `yaml:"notifyURL"`
-		QuitURL   string `yaml:"quitURL"`
-		returnURL string `yaml:"returnURL"`
-		Debug     bool   `yaml:"debug"`
-	} `yaml:"alipay"`
-
-	QiNiu struct {
-		MoguCloud struct {
-			AccessKey   string `yaml:"accessKey"`
-			SecretKey   string `yaml:"secretKey"`
-			SecurityKey string `yaml:"securityKey"`
-			Bucket      string `yaml:"bucket"`
-			Domain      string `yaml:"domain"`
-		} `yaml:"moguCloud"`
-	} `yaml:"qiNiu"`
-}
-
-func TestGetApolloConfig(t *testing.T) {
-	var wait sync.WaitGroup
-	wait.Add(1)
-	GetApolloConfig("**", "**", config)
-	go func() {
-		for range time.NewTicker(time.Second).C {
-			fmt.Println(config.APP.IOS.Log, time.Now().Format(time_parse.CSTLayout))
-		}
-	}()
-	wait.Wait()
-}

+ 0 - 23
pkg/captcha/captcha_test.go

@@ -1,23 +0,0 @@
-package captcha
-
-import (
-	"git.bvbej.com/bvbej/base-golang/pkg/cache"
-	"testing"
-	"time"
-)
-
-func TestNewCaptcha(t *testing.T) {
-	repo, err := cache.New("127.0.0.1:6379", "", 0, 5, 100, 10)
-	if err != nil {
-		t.Error(err)
-		return
-	}
-	newStore := NewStore(repo, 5*time.Minute)
-	newCaptcha := NewCaptcha(newStore, 80, 180, 5)
-	generate, s, err := newCaptcha.Generate()
-	if err != nil {
-		t.Error(err)
-		return
-	}
-	t.Log(generate, s)
-}

+ 2 - 2
pkg/color/string_darwin.go

@@ -27,7 +27,7 @@ func Red(msg string) string {
 }
 
 // Redf ...
-func Redf(msg string, arg interface{}) string {
+func Redf(msg string, arg any) string {
 	return fmt.Sprintf("\x1b[31m%s\x1b[0m %+v\n", msg, arg)
 }
 
@@ -42,6 +42,6 @@ func Green(msg string) string {
 }
 
 // Greenf ...
-func Greenf(msg string, arg interface{}) string {
+func Greenf(msg string, arg any) string {
 	return fmt.Sprintf("\x1b[32m%s\x1b[0m %+v\n", msg, arg)
 }

+ 2 - 2
pkg/color/string_linux.go

@@ -27,7 +27,7 @@ func Red(msg string) string {
 }
 
 // Redf ...
-func Redf(msg string, arg interface{}) string {
+func Redf(msg string, arg any) string {
 	return fmt.Sprintf("\x1b[31m%s\x1b[0m %+v\n", msg, arg)
 }
 
@@ -42,6 +42,6 @@ func Green(msg string) string {
 }
 
 // Greenf ...
-func Greenf(msg string, arg interface{}) string {
+func Greenf(msg string, arg any) string {
 	return fmt.Sprintf("\x1b[32m%s\x1b[0m %+v\n", msg, arg)
 }

+ 2 - 2
pkg/color/string_windows.go

@@ -27,7 +27,7 @@ func Red(msg string) string {
 }
 
 // Redf ...
-func Redf(msg string, arg interface{}) string {
+func Redf(msg string, arg any) string {
 	return fmt.Sprintf("%s %+v\n", msg, arg)
 }
 
@@ -42,6 +42,6 @@ func Green(msg string) string {
 }
 
 // Greenf ...
-func Greenf(msg string, arg interface{}) string {
+func Greenf(msg string, arg any) string {
 	return fmt.Sprintf("%s %+v\n", msg, arg)
 }

+ 0 - 32
pkg/ddm/type_test.go

@@ -1,32 +0,0 @@
-package ddm
-
-import (
-	"encoding/json"
-	"testing"
-)
-
-type message struct {
-	Name      IDName   `json:"name"`
-	Mobile    Mobile   `json:"mobile"`
-	IDCard    IDCard   `json:"id_card"`
-	PassWord  PassWord `json:"password"`
-	Email     Email    `json:"email"`
-	BankCard1 BankCard `json:"bank_card_1"`
-	BankCard2 BankCard `json:"bank_card_2"`
-	BankCard3 BankCard `json:"bank_card_3"`
-}
-
-func TestMarshalJSON(t *testing.T) {
-	msg := new(message)
-	msg.Name = IDName("李鸿章")
-	msg.Mobile = Mobile("13288887986")
-	msg.IDCard = IDCard("125252525252525252")
-	msg.PassWord = PassWord("123456")
-	msg.Email = Email("xinliangnote@163.com")
-	msg.BankCard1 = BankCard("6545654565456545")
-	msg.BankCard2 = BankCard("65485269874569852")
-	msg.BankCard3 = BankCard("6548526987456985298")
-
-	marshal, _ := json.Marshal(msg)
-	t.Log(string(marshal))
-}

+ 0 - 13
pkg/duration_fmt/fmt_test.go

@@ -1,13 +0,0 @@
-package duration_fmt
-
-import (
-	"testing"
-	"time"
-)
-
-func TestFmt(t *testing.T) {
-	timeduration := time.Now().Sub(time.Now().Add(time.Hour*301*3 + time.Minute + time.Second*3 + time.Microsecond*988))
-	duration := Parse(timeduration).LimitFirstN(3).TrimSpace()
-	t.Log(duration)
-
-}

+ 4 - 4
pkg/errors/err.go

@@ -20,8 +20,8 @@ type Error interface {
 	t()
 }
 
-var _ (Error) = (*item)(nil)
-var _ (fmt.Formatter) = (*item)(nil)
+var _ Error = (*item)(nil)
+var _ fmt.Formatter = (*item)(nil)
 
 type item struct {
 	msg   string
@@ -50,7 +50,7 @@ func New(msg string) Error {
 }
 
 // Errorf create a new error
-func Errorf(format string, args ...interface{}) Error {
+func Errorf(format string, args ...any) Error {
 	return &item{msg: fmt.Sprintf(format, args...), stack: callers()}
 }
 
@@ -70,7 +70,7 @@ func Wrap(err error, msg string) Error {
 }
 
 // Wrapf with some extra message into err
-func Wrapf(err error, format string, args ...interface{}) Error {
+func Wrapf(err error, format string, args ...any) Error {
 	if err == nil {
 		return nil
 	}

+ 0 - 34
pkg/errors/err_test.go

@@ -1,34 +0,0 @@
-package errors
-
-import (
-	"errors"
-	"testing"
-
-	"go.uber.org/zap"
-)
-
-func TestErr(t *testing.T) {
-	logger, _ := zap.NewProduction()
-
-	logger.Info("errorf", zap.Error(Errorf("%s %d", "127.0.0.1", 80)))
-
-	err := New("a dummy err")
-	logger.Info("new", zap.Error(err))
-
-	err = Wrap(err, "ping timeout err")
-	logger.Info("wrap", zap.Error(err))
-
-	err = Wrapf(err, "ip: %s port: %d", "localhost", 80)
-	logger.Info("wrapf", zap.Error(err))
-
-	err = WithStack(err)
-	logger.Info("withstack", zap.Error(err))
-
-	logger.Info("wrap std", zap.Error(Wrap(errors.New("std err"), "some err occurs")))
-
-	logger.Info("wrapf std", zap.Error(Wrapf(errors.New("std err"), "ip: %s port: %d", "localhost", 80)))
-
-	logger.Info("withstack std", zap.Error(WithStack(errors.New("std err"))))
-
-	t.Logf("%+v", New("a dummy error"))
-}

+ 0 - 18
pkg/hash/hash_hashids_test.go

@@ -1,18 +0,0 @@
-package hash
-
-import "testing"
-
-const secret = "i1ydX9RtHyuJTrw7frcu"
-const length = 12
-
-func TestHashidsEncode(t *testing.T) {
-	str, _ := New(secret, length).HashidsEncode([]int{99})
-	t.Log(str)
-
-	//GyV5pJqXvwAR
-}
-
-func TestHashidsDecode(t *testing.T) {
-	ids, _ := New(secret, length).HashidsDecode("GyV5pJqXvwAR")
-	t.Log(ids)
-}

+ 1 - 1
pkg/httpclient/option.go

@@ -11,7 +11,7 @@ import (
 
 var (
 	cache = &sync.Pool{
-		New: func() interface{} {
+		New: func() any {
 			return &option{
 				header:    make(map[string][]string),
 				basicAuth: new(basicAuth),

+ 4 - 4
pkg/logger/logger.go

@@ -201,27 +201,27 @@ var _ Meta = (*meta)(nil)
 // Meta key-value
 type Meta interface {
 	Key() string
-	Value() interface{}
+	Value() any
 	meta()
 }
 
 type meta struct {
 	key   string
-	value interface{}
+	value any
 }
 
 func (m *meta) Key() string {
 	return m.key
 }
 
-func (m *meta) Value() interface{} {
+func (m *meta) Value() any {
 	return m.value
 }
 
 func (m *meta) meta() {}
 
 // NewMeta create meat
-func NewMeta(key string, value interface{}) Meta {
+func NewMeta(key string, value any) Meta {
 	return &meta{key: key, value: value}
 }
 

+ 0 - 35
pkg/logger/logger_test.go

@@ -1,35 +0,0 @@
-package logger
-
-import (
-	"testing"
-
-	"github.com/pkg/errors"
-)
-
-func TestJSONLogger(t *testing.T) {
-	logger, err := NewJSONLogger(
-		WithField("defined_key", "defined_value"),
-	)
-	if err != nil {
-		t.Fatal(err)
-	}
-	defer logger.Sync()
-
-	err = errors.New("pkg error")
-	logger.Error("err occurs", WrapMeta(nil, NewMeta("para1", "value1"), NewMeta("para2", "value2"))...)
-	logger.Error("err occurs", WrapMeta(err, NewMeta("para1", "value1"), NewMeta("para2", "value2"))...)
-
-}
-
-func BenchmarkJsonLogger(b *testing.B) {
-	b.ResetTimer()
-	logger, err := NewJSONLogger(
-		WithField("defined_key", "defined_value"),
-	)
-	if err != nil {
-		b.Fatal(err)
-	}
-
-	defer logger.Sync()
-
-}

+ 0 - 23
pkg/mail/mail_test.go

@@ -1,23 +0,0 @@
-package mail
-
-import (
-	"testing"
-)
-
-func TestSend(t *testing.T) {
-	options := &Options{
-		MailHost: "smtp.163.com",
-		MailPort: 465,
-		MailUser: "xxx@163.com",
-		MailPass: "", //密码或授权码
-		MailTo:   "",
-		Subject:  "subject",
-		Body:     "body",
-	}
-	err := Send(options)
-	if err != nil {
-		t.Error("Mail Send error", err)
-		return
-	}
-	t.Log("success")
-}

+ 0 - 14
pkg/md5/md5_test.go

@@ -1,14 +0,0 @@
-package md5
-
-import "testing"
-
-func TestEncrypt(t *testing.T) {
-	t.Log(New().Encrypt("123456"))
-}
-
-func BenchmarkEncrypt(b *testing.B) {
-	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		New().Encrypt("123456")
-	}
-}

+ 1 - 1
pkg/p/print.go

@@ -20,7 +20,7 @@ func newOption() *option {
 	return &option{}
 }
 
-func Println(key string, value interface{}, options ...Option) {
+func Println(key string, value any, options ...Option) {
 	ts := time.Now()
 	opt := newOption()
 	defer func() {

+ 4 - 4
pkg/proxy/out.go

@@ -21,8 +21,8 @@ func NewOutPool(dur int, address string, timeout int, InitialCap int, MaxCap int
 	}
 	var err error
 	op.Pool, err = NewConnPool(poolConfig{
-		IsActive: func(conn interface{}) bool { return true },
-		Release: func(conn interface{}) {
+		IsActive: func(conn any) bool { return true },
+		Release: func(conn any) {
 			if conn != nil {
 				conn.(net.Conn).SetDeadline(time.Now().Add(time.Millisecond))
 				conn.(net.Conn).Close()
@@ -30,7 +30,7 @@ func NewOutPool(dur int, address string, timeout int, InitialCap int, MaxCap int
 		},
 		InitialCap: InitialCap,
 		MaxCap:     MaxCap,
-		Factory: func() (conn interface{}, err error) {
+		Factory: func() (conn any, err error) {
 			conn, err = op.getConn()
 			return
 		},
@@ -48,7 +48,7 @@ func NewOutPool(dur int, address string, timeout int, InitialCap int, MaxCap int
 	return
 }
 
-func (op *OutPool) getConn() (conn interface{}, err error) {
+func (op *OutPool) getConn() (conn any, err error) {
 	conn, err = ConnectHost(op.address, op.timeout)
 	return
 }

+ 10 - 10
pkg/proxy/pool.go

@@ -9,22 +9,22 @@ import (
 type ConnPool interface {
 	initAutoFill(async bool) (err error)
 
-	Get() (conn interface{}, err error)
-	Put(conn interface{})
+	Get() (conn any, err error)
+	Put(conn any)
 	ReleaseAll()
 	Len() (length int)
 }
 
 type netPool struct {
-	connects chan interface{}
+	connects chan any
 	lock     *sync.Mutex
 	config   poolConfig
 }
 
 type poolConfig struct {
-	Factory    func() (interface{}, error)
-	IsActive   func(interface{}) bool
-	Release    func(interface{})
+	Factory    func() (any, error)
+	IsActive   func(any) bool
+	Release    func(any)
 	InitialCap int
 	MaxCap     int
 }
@@ -32,7 +32,7 @@ type poolConfig struct {
 func NewConnPool(poolConfig poolConfig) (pool ConnPool, err error) {
 	p := netPool{
 		config:   poolConfig,
-		connects: make(chan interface{}, poolConfig.MaxCap),
+		connects: make(chan any, poolConfig.MaxCap),
 		lock:     &sync.Mutex{},
 	}
 
@@ -94,7 +94,7 @@ func (p *netPool) initAutoFill(async bool) (err error) {
 
 }
 
-func (p *netPool) Get() (conn interface{}, err error) {
+func (p *netPool) Get() (conn any, err error) {
 	// defer func() {
 	// 	log.Printf("pool len : %d", p.Len())
 	// }()
@@ -118,7 +118,7 @@ func (p *netPool) Get() (conn interface{}, err error) {
 	return
 }
 
-func (p *netPool) Put(conn interface{}) {
+func (p *netPool) Put(conn any) {
 	if conn == nil {
 		return
 	}
@@ -141,7 +141,7 @@ func (p *netPool) ReleaseAll() {
 	for c := range p.connects {
 		p.config.Release(c)
 	}
-	p.connects = make(chan interface{}, p.config.InitialCap)
+	p.connects = make(chan any, p.config.InitialCap)
 
 }
 

+ 1 - 1
pkg/proxy/tcp.go

@@ -85,7 +85,7 @@ func (s *tcp) callback(inConn net.Conn) {
 
 func (s *tcp) outToTCP(inConn *net.Conn) (err error) {
 	var outConn net.Conn
-	var _outConn interface{}
+	var _outConn any
 	_outConn, err = s.outPool.Pool.Get()
 	if err == nil {
 		outConn = _outConn.(net.Conn)

+ 0 - 25
pkg/proxy/tcp_test.go

@@ -1,25 +0,0 @@
-package proxy
-
-import (
-	"sync"
-	"testing"
-)
-
-func TestProxy(t *testing.T) {
-	var wait sync.WaitGroup
-	wait.Add(1)
-	run := Run("test", TCPArgs{
-		Local:               ":8100",
-		Parent:              "10.0.1.174:5555",
-		Timeout:             1500,
-		PoolSize:            5,
-		CheckParentInterval: 30,
-		OutCallback: func() bool {
-			return true
-		},
-	})
-	if run == nil {
-		wait.Done()
-	}
-	wait.Wait()
-}

+ 0 - 77
pkg/rsa/rsa_test.go

@@ -1,77 +0,0 @@
-package rsa
-
-import (
-	"testing"
-)
-
-const (
-	publicKey = `-----BEGIN PUBLIC KEY-----
-MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1O3p0JN0/RrP7eY3f81i
-zPf16FS0WMNGCJkd+y5c6yBzUvN0IEeoxiIWIBhoMKH0pzlzBg0rfttojSodOgNo
-m/UCAzAYEgdIsNee5LSN/7e0T2/QvsIAHINuA8gI8fGoGiSA2TEzpUo6aVXwhZT3
-4GGRdrSJ+m4iVk/Kt95tavBNk+NDVSeb5xAjxBchT5BjAMMlE0ffGZb0MMjjO5+e
-9Tn8f99M2VMqpzXHXZzv1ABmqufzS20iWcSvnjhWcJ9hiKwO8Z30GgJyACmml+HM
-xLYEFN9h2MWYgxLm9Z0rLMrWwMM+E2rCs8tsxAD5sO9RZMJPl1C0FIsMR53ngqbz
-owIDAQAB
------END PUBLIC KEY-----`
-
-	privateKey = `-----BEGIN RSA PRIVATE KEY-----
-MIIEpgIBAAKCAQEA1O3p0JN0/RrP7eY3f81izPf16FS0WMNGCJkd+y5c6yBzUvN0
-IEeoxiIWIBhoMKH0pzlzBg0rfttojSodOgNom/UCAzAYEgdIsNee5LSN/7e0T2/Q
-vsIAHINuA8gI8fGoGiSA2TEzpUo6aVXwhZT34GGRdrSJ+m4iVk/Kt95tavBNk+ND
-VSeb5xAjxBchT5BjAMMlE0ffGZb0MMjjO5+e9Tn8f99M2VMqpzXHXZzv1ABmqufz
-S20iWcSvnjhWcJ9hiKwO8Z30GgJyACmml+HMxLYEFN9h2MWYgxLm9Z0rLMrWwMM+
-E2rCs8tsxAD5sO9RZMJPl1C0FIsMR53ngqbzowIDAQABAoIBAQCO1RE1ItUlO6kj
-Un0ENAgEqojAUqGvsT33Yo7kAZO+/cOeb0UEqk0iq5bf7L9ncBynWDg6ZPc6X3/g
-wdFdKxAvHck9zjM3VL+EMP+bNyrR0K8ZYk5Kx+Q/PEK+Mp8dfRdgggAUsZaNWB+a
-rVVspiMo1wo28KBl5x8NevTnJkOLqXAyB7UyLWqnOL1fb988lZvZPR7ZUYroVIZa
-pyXtZcafIJeKyQ3bvWI5+eFqOe61Z4Bx1+TpfZ3fKfSDW0vhxzNqaimOa8jSXtMJ
-jMeOctL4nZ0TPo/jS3I+XlaH4ZQlFLuUWGscpxwfEeBN23I8HRLkZXJsw66yvRN3
-s4bUKPXRAoGBAP/3oSZAECvfsYYzs76tnrAmR/0GxCqgguxDlWn5DowQzdWFOdHC
-ZbTo/hUVoMSQnO1EKCFlnBS+wg/3TuIzUO0ewC1aeT7qHbOMDl0zKbNpS2Z9/j+U
-zro+qz7XmkWolMCfmDrCrw9CtCxcMSII+ajbI8SAgFVMz9XnDt+xW9E9AoGBANT0
-4F6kCUJTEyqf2+v84tjQ2wGIF6XtZPU9JR806zeMyahQ9F6z3hY8BYb0tIy5b3uJ
-VlJ9TG1qg/t59TWxIq43mYSUJHe0aJi3ilooObQtHlhPu8nwmmX47sX0PyG2hMoD
-kBVxTpTDmBaDz7O9uBnlMXJN5qEygctaixpEbmZfAoGBAMBA9kEMjRjnAyeRXcgy
-D6aumhNqKZz6wltCx864yjxZwsBFOJBcOpgPCAg+HmqFU9jCAIJVF05dmNT1I8Ky
-WG5BUoa+FaMzpOtenstRylh/Far9pyGKW1t4BpdEyRLY9CFZvbUk1OfZagqHlD/E
-DgDN16eX/MwUzWYUDg/l3tjhAoGBAKGip/ZNjVWRFpggs9z/mfK1O7WC5Wgksp9N
-ZLK2CN6l9p3RrFmBLk00C4HulGfHi+15RVLhFbRqx3iFje/N3iPbwaMWikNtZIKd
-tN5Pb9To9gJTqpZRD+/cLOeFRrHBBjMK1z7fPKS/fN2B+JFVq7nD827t3+J0In4F
-4FT0odMDAoGBAJk3ELB/FHY8xzZ4jF1wG/a1CK681Xm6SuU5KIELDSAUNoou6OPG
-mS8gU20MMPAeV2z7khyDcSxlHsUyL73eLeaakbQov9NMW7cc99XX4wnP4W7FRpmr
-QbHmKuHIRFHCFv+XX8c0aK2mDZMUlzJdy4FgD/YCEZ7kZMZKyvZW/ZuV
------END RSA PRIVATE KEY-----`
-)
-
-func TestEncrypt(t *testing.T) {
-	str, err := NewPublic(publicKey).Encrypt("123456")
-	if err != nil {
-		t.Error("rsa public encrypt error", err)
-		return
-	}
-
-	t.Log(str)
-}
-
-func TestDecrypt(t *testing.T) {
-	decryptStr := "KTKXckjkCLI6Vk_y_XROnY-a6nJpllruL-CX-v_2AFxfghA2tZ2nkQyS6d1-IIYMlgwm4ivwlzy-phLtaN9BB03htA5D9rwjA_JwYtqAG4iwuvgaDl2SiZ_H2ACv-aV1kNRgnyjh14hs0JiSt5VHEiJ3D2xYzOCKwtEzoo0WczJ-MYb3u_-bfcnm9YtvgtG5-y3Jy7WYr-IwXdBKqPO0E-jzrtY7m3Q1yC4znHdzjNpxCj0I6YRx4CZ362b706qNX7sl3E5KTJeSmYrsurB-SxQT1CaqGzVt7mshx1v2qGnv5NBNXpj7ZPKWGJbgaCUxcuxd1Mg0o81HnfbsGuSlFQ=="
-
-	str, err := NewPrivate(privateKey).Decrypt(decryptStr)
-	if err != nil {
-		t.Error("rsa private decrypt error", err)
-		return
-	}
-
-	t.Log(str)
-}
-
-func BenchmarkEncryptAndDecrypt(b *testing.B) {
-	b.ResetTimer()
-	rsaPublic := NewPublic(publicKey)
-	rsaPrivate := NewPrivate(privateKey)
-	for i := 0; i < b.N; i++ {
-		encryptString, _ := rsaPublic.Encrypt("123456")
-		rsaPrivate.Decrypt(encryptString)
-	}
-}

+ 0 - 45
pkg/signature/signature_test.go

@@ -1,45 +0,0 @@
-package signature
-
-import (
-	"net/url"
-	"testing"
-	"time"
-)
-
-const (
-	key    = "blog"
-	secret = "i1ydX9RtHyuJTrw7frcu"
-	ttl    = time.Minute * 10
-)
-
-func TestSignature_Generate(t *testing.T) {
-	path := "/echo"
-	method := "POST"
-
-	params := url.Values{}
-	params.Add("a", "a1")
-	params.Add("d", "d1")
-	params.Add("c", "c1 c2")
-
-	authorization, date, err := New(key, secret, ttl).Generate(path, method, params)
-	t.Log("authorization:", authorization)
-	t.Log("date:", date)
-	t.Log("err:", err)
-}
-
-func TestSignature_Verify(t *testing.T) {
-
-	authorization := "blog y7a326f3aWvIxdeNIgRo0P7FSDnCNSsN8gJi/4y+cZo="
-	date := "2021-04-06 16:15:26"
-
-	path := "/echo"
-	method := "post"
-	params := url.Values{}
-	params.Add("a", "a1")
-	params.Add("d", "d1")
-	params.Add("c", "c1 c2*")
-
-	ok, err := New(key, secret, ttl).Verify(authorization, date, path, method, params)
-	t.Log(ok)
-	t.Log(err)
-}

+ 0 - 19
pkg/time_parse/time_parse_test.go

@@ -1,19 +0,0 @@
-package time_parse
-
-import "testing"
-
-func TestRFC3339ToCSTLayout(t *testing.T) {
-	t.Log(RFC3339ToCSTLayout("2020-11-08T08:18:46+08:00"))
-}
-
-func TestCSTLayoutString(t *testing.T) {
-	t.Log(CSTLayoutString())
-}
-
-func TestCSTLayoutStringToUnix(t *testing.T) {
-	t.Log(CSTLayoutStringToUnix("2020-01-24 21:11:11"))
-}
-
-func TestGMTLayoutString(t *testing.T) {
-	t.Log(GMTLayoutString())
-}

+ 1 - 1
pkg/token/token_jwt.go

@@ -29,7 +29,7 @@ func (t *token) JwtSign(userId uint64, platform string, expireDuration time.Dura
 }
 
 func (t *token) JwtParse(tokenString string) (*claims, error) {
-	tokenClaims, err := jwt.ParseWithClaims(tokenString, &claims{}, func(token *jwt.Token) (interface{}, error) {
+	tokenClaims, err := jwt.ParseWithClaims(tokenString, &claims{}, func(token *jwt.Token) (any, error) {
 		return []byte(t.secret), nil
 	})
 

+ 0 - 54
pkg/token/token_test.go

@@ -1,54 +0,0 @@
-package token
-
-import (
-	"net/url"
-	"testing"
-	"time"
-)
-
-const secret = "i1ydX9RtHyuJTrw7frcu"
-
-func TestJwtSign(t *testing.T) {
-	tokenString, err := New(secret).JwtSign(123456789, "xinliangnote", 24*time.Hour)
-	if err != nil {
-		t.Error("sign error", err)
-		return
-	}
-	t.Log(tokenString)
-}
-
-func TestJwtParse(t *testing.T) {
-	tokenString := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjEyMzQ1Njc4OSwidXNlcm5hbWUiOiJ4aW5saWFuZyIsImV4cCI6MTYwOTQ2NzcwNCwiaWF0IjoxNjA5MzgxMzA0LCJpc3MiOiJnby1naW4tYXBpIiwibmJmIjoxNjA5MzgxMzA0fQ.hccv8F713WpKcwiSldBrFLZz_2SZzOTPedPi-8ps7M4"
-	user, err := New(secret).JwtParse(tokenString)
-	if err != nil {
-		t.Error("parse error", err)
-		return
-	}
-	t.Log(user)
-}
-
-func TestUrlSign(t *testing.T) {
-
-	urlPath := "/echo"
-	method := "post"
-	params := url.Values{}
-	params.Add("a", "a1")
-	params.Add("d", "d1")
-	params.Add("c", "c1")
-
-	tokenString, err := New(secret).UrlSign(urlPath, method, params)
-	if err != nil {
-		t.Error("sign error", err)
-		return
-	}
-	t.Log(tokenString)
-}
-
-func BenchmarkJwtSignAndParse(b *testing.B) {
-	b.ResetTimer()
-	token := New(secret)
-	for i := 0; i < b.N; i++ {
-		tokenString, _ := token.JwtSign(123456789, "xinliangnote", 24*time.Hour)
-		token.JwtParse(tokenString)
-	}
-}

+ 3 - 3
pkg/trace/debug.go

@@ -1,7 +1,7 @@
 package trace
 
 type Debug struct {
-	Key         string      `json:"key"`          // 标示
-	Value       interface{} `json:"value"`        // 值
-	CostSeconds float64     `json:"cost_seconds"` // 执行时间(单位秒)
+	Key         string  `json:"key"`          // 标示
+	Value       any     `json:"value"`        // 值
+	CostSeconds float64 `json:"cost_seconds"` // 执行时间(单位秒)
 }

+ 9 - 9
pkg/trace/grpc.go

@@ -5,13 +5,13 @@ import (
 )
 
 type Grpc struct {
-	Timestamp   string                 `json:"timestamp"`             // 时间,格式:2006-01-02 15:04:05
-	Addr        string                 `json:"addr"`                  // 地址
-	Method      string                 `json:"method"`                // 操作方法
-	Meta        metadata.MD            `json:"meta"`                  // Mate
-	Request     map[string]interface{} `json:"request"`               // 请求信息
-	Response    map[string]interface{} `json:"response"`              // 返回信息
-	CostSeconds float64                `json:"cost_seconds"`          // 执行时间(单位秒)
-	Code        string                 `json:"err_code,omitempty"`    // 错误码
-	Message     string                 `json:"err_message,omitempty"` // 错误信息
+	Timestamp   string         `json:"timestamp"`             // 时间,格式:2006-01-02 15:04:05
+	Addr        string         `json:"addr"`                  // 地址
+	Method      string         `json:"method"`                // 操作方法
+	Meta        metadata.MD    `json:"meta"`                  // Mate
+	Request     map[string]any `json:"request"`               // 请求信息
+	Response    map[string]any `json:"response"`              // 返回信息
+	CostSeconds float64        `json:"cost_seconds"`          // 执行时间(单位秒)
+	Code        string         `json:"err_code,omitempty"`    // 错误码
+	Message     string         `json:"err_message,omitempty"` // 错误信息
 }

+ 12 - 12
pkg/trace/trace.go

@@ -39,22 +39,22 @@ type Trace struct {
 
 // Request 请求信息
 type Request struct {
-	TTL        string      `json:"ttl"`         // 请求超时时间
-	Method     string      `json:"method"`      // 请求方式
-	DecodedURL string      `json:"decoded_url"` // 请求地址
-	Header     interface{} `json:"header"`      // 请求 Header 信息
-	Body       interface{} `json:"body"`        // 请求 Body 信息
+	TTL        string `json:"ttl"`         // 请求超时时间
+	Method     string `json:"method"`      // 请求方式
+	DecodedURL string `json:"decoded_url"` // 请求地址
+	Header     any    `json:"header"`      // 请求 Header 信息
+	Body       any    `json:"body"`        // 请求 Body 信息
 }
 
 // Response 响应信息
 type Response struct {
-	Header          interface{} `json:"header"`                      // Header 信息
-	Body            interface{} `json:"body"`                        // Body 信息
-	BusinessCode    int         `json:"business_code,omitempty"`     // 业务码
-	BusinessCodeMsg string      `json:"business_code_msg,omitempty"` // 提示信息
-	HttpCode        int         `json:"http_code"`                   // HTTP 状态码
-	HttpCodeMsg     string      `json:"http_code_msg"`               // HTTP 状态码信息
-	CostSeconds     float64     `json:"cost_seconds"`                // 执行时间(单位秒)
+	Header          any     `json:"header"`                      // Header 信息
+	Body            any     `json:"body"`                        // Body 信息
+	BusinessCode    int     `json:"business_code,omitempty"`     // 业务码
+	BusinessCodeMsg string  `json:"business_code_msg,omitempty"` // 提示信息
+	HttpCode        int     `json:"http_code"`                   // HTTP 状态码
+	HttpCodeMsg     string  `json:"http_code_msg"`               // HTTP 状态码信息
+	CostSeconds     float64 `json:"cost_seconds"`                // 执行时间(单位秒)
 }
 
 func New(id string) *Trace {

+ 0 - 157
pkg/urltable/urltable_test.go

@@ -1,157 +0,0 @@
-package urltable
-
-import (
-	"strings"
-	"testing"
-)
-
-func TestFormat(t *testing.T) {
-	pattern, err := Format(" view  / a / b / c   ")
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if pattern != "VIEW/a/b/c" {
-		t.Fatal("format failed")
-	}
-}
-
-func TestParse(t *testing.T) {
-	for i, pattern := range []string{
-		"get/ a / b / c   ",
-		"get/ a / b / * / **  ",
-		"get/ a / b / * / c / **  ",
-		"get/ a / b / * / * / c/ **  ",
-		"get/ a / b / * / * / c/   ",
-	} {
-		paths, err := parse(pattern)
-		if err != nil {
-			t.Fatal(pattern, "should be legal; err: ", err.Error())
-		}
-		t.Log(i, strings.Join(paths, delimiter))
-	}
-
-	for _, pattern := range []string{
-		"   ",
-		" /  ",
-		" x /  ",
-		"get/  ",
-		"get/ * ",
-		"get/ ** ",
-		"get/ ** / * ",
-		"get/ ** / ** ",
-		"get/ a / **  / * ",
-		"get/ a /   / * ",
-		"get/ a /   / ** ",
-		"get/ a /   /  ",
-		"get/ a /  * /   / ",
-		"get/ a /  * / **  / ",
-	} {
-		if _, err := parse(pattern); err == nil {
-			t.Fatal(pattern, "should be illegal")
-		}
-	}
-}
-
-func TestAppend(t *testing.T) {
-	table := NewTable()
-
-	if err := table.Append("get/a/b"); err != nil {
-		t.Fatal("shouldn't be err")
-	}
-
-	if err := table.Append("get/a/b/*"); err != nil {
-		t.Fatal("shouldn't be err")
-	}
-	if err := table.Append("get/a/b/*/**"); err != nil {
-		t.Fatal("shouldn't be err")
-	}
-
-	if err := table.Append("get/a/b/c/*"); err != nil {
-		t.Fatal("shouldn't be err")
-	}
-	if err := table.Append("get/a/b/c/*/**"); err != nil {
-		t.Fatal("shouldn't be err")
-	}
-
-	t.Log(table.Size())
-	if err := table.Append("get/a/b/c/*"); err != nil {
-		t.Fatal("shouldn't be err")
-	}
-	t.Log(table.Size())
-
-	if err := table.Append("get/a/b/**"); err == nil {
-		t.Fatal("should be err")
-	}
-	if err := table.Append("get/a/b/*/*"); err == nil {
-		t.Fatal("should be err")
-	}
-	if err := table.Append("get/a/b/*/c"); err == nil {
-		t.Fatal("should be err")
-	}
-}
-
-func TestMapping(t *testing.T) {
-	table := NewTable()
-
-	if err := table.Append("get/a/b"); err != nil {
-		t.Fatal("shouldn't be err")
-	}
-
-	if err := table.Append("get/a/b/*"); err != nil {
-		t.Fatal("shouldn't be err")
-	}
-	if err := table.Append("get/a/b/*/**"); err != nil {
-		t.Fatal("shouldn't be err")
-	}
-
-	if err := table.Append("get/a/b/c/*"); err != nil {
-		t.Fatal("shouldn't be err")
-	}
-	if err := table.Append("get/a/b/c/*/**"); err != nil {
-		t.Fatal("shouldn't be err")
-	}
-
-	if pattern, _ := table.Mapping("get/a/b"); pattern == "" {
-		t.Fatal("should contains")
-	} else {
-		t.Log("get/a/b", ">>", pattern)
-	}
-	if pattern, _ := table.Mapping("get/a/b/"); pattern == "" {
-		t.Fatal("should contains")
-	} else {
-		t.Log("get/a/b/", ">>", pattern)
-	}
-	if pattern, _ := table.Mapping("get/a/b/x"); pattern == "" {
-		t.Fatal("should contains")
-	} else {
-		t.Log("get/a/b/x", ">>", pattern)
-	}
-	if pattern, _ := table.Mapping("get/a/b/x/y/z"); pattern == "" {
-		t.Fatal("should contains")
-	} else {
-		t.Log("get/a/b/x/y/z", ">>", pattern)
-	}
-
-	if pattern, _ := table.Mapping("get/a/b/c/"); pattern == "" {
-		t.Fatal("should contains")
-	} else {
-		t.Log("get/a/b/c/", ">>", pattern)
-	}
-	if pattern, _ := table.Mapping("get/a/b/c/d/e/f"); pattern == "" {
-		t.Fatal("should contains")
-	} else {
-		t.Log("get/a/b/c/d/e/f", ">>", pattern)
-	}
-
-	if pattern, _ := table.Mapping("get/a/"); pattern != "" {
-		t.Fatal("shouldn't contains")
-	} else {
-		t.Log("get/a/", ">>", pattern)
-	}
-	if pattern, _ := table.Mapping("get/a/c"); pattern != "" {
-		t.Fatal("shouldn't contains")
-	} else {
-		t.Log("get/a/c", ">>", pattern)
-	}
-}

+ 10 - 10
pkg/utils/map.go

@@ -12,11 +12,11 @@ var _ ConcurrentMap = (*concurrentMap)(nil)
 
 type ConcurrentMap interface {
 	i()
-	Store(key, value interface{})
-	Delete(key interface{})
-	Range(f func(key, value interface{}) bool)
-	Load(key interface{}) (value interface{}, ok bool)
-	LoadOrStore(key, value interface{}) (actual interface{}, loaded bool)
+	Store(key, value any)
+	Delete(key any)
+	Range(f func(key, value any) bool)
+	Load(key any) (value any, ok bool)
+	LoadOrStore(key, value any) (actual any, loaded bool)
 }
 
 type concurrentMap struct {
@@ -46,7 +46,7 @@ func NewConcurrentMap(keyType, valueType reflect.Type) (ConcurrentMap, error) {
 
 func (cMap *concurrentMap) i() {}
 
-func (cMap *concurrentMap) Delete(key interface{}) {
+func (cMap *concurrentMap) Delete(key any) {
 	if reflect.TypeOf(key) != cMap.keyType {
 		return
 	}
@@ -58,14 +58,14 @@ func (cMap *concurrentMap) Len() int64 {
 	return cMap.counter
 }
 
-func (cMap *concurrentMap) Load(key interface{}) (value interface{}, ok bool) {
+func (cMap *concurrentMap) Load(key any) (value any, ok bool) {
 	if reflect.TypeOf(key) != cMap.keyType {
 		return
 	}
 	return cMap.m.Load(key)
 }
 
-func (cMap *concurrentMap) LoadOrStore(key, value interface{}) (actual interface{}, loaded bool) {
+func (cMap *concurrentMap) LoadOrStore(key, value any) (actual any, loaded bool) {
 	if reflect.TypeOf(key) != cMap.keyType {
 		panic(fmt.Errorf("wrong key type: %v", reflect.TypeOf(key)))
 	}
@@ -76,11 +76,11 @@ func (cMap *concurrentMap) LoadOrStore(key, value interface{}) (actual interface
 	return
 }
 
-func (cMap *concurrentMap) Range(f func(key, value interface{}) bool) {
+func (cMap *concurrentMap) Range(f func(key, value any) bool) {
 	cMap.m.Range(f)
 }
 
-func (cMap *concurrentMap) Store(key, value interface{}) {
+func (cMap *concurrentMap) Store(key, value any) {
 	if reflect.TypeOf(key) != cMap.keyType {
 		panic(fmt.Errorf("wrong key type: %v", reflect.TypeOf(key)))
 	}

+ 3 - 3
pkg/validator/validator.go

@@ -15,7 +15,7 @@ type DefaultValidator struct {
 
 var _ binding.StructValidator = &DefaultValidator{}
 
-func (v *DefaultValidator) ValidateStruct(obj interface{}) error {
+func (v *DefaultValidator) ValidateStruct(obj any) error {
 	if kindOfData(obj) == reflect.Struct {
 
 		v.lazyinit()
@@ -27,7 +27,7 @@ func (v *DefaultValidator) ValidateStruct(obj interface{}) error {
 	return nil
 }
 
-func (v *DefaultValidator) Engine() interface{} {
+func (v *DefaultValidator) Engine() any {
 	v.lazyinit()
 	return v.validate
 }
@@ -43,7 +43,7 @@ func (v *DefaultValidator) lazyinit() {
 	})
 }
 
-func kindOfData(data interface{}) reflect.Kind {
+func kindOfData(data any) reflect.Kind {
 	value := reflect.ValueOf(data)
 	valueType := value.Kind()
 

+ 2 - 2
pkg/websocket/codec/codec.go

@@ -1,9 +1,9 @@
 package codec
 
 type Codec interface {
-	Marshal(router string, dataPtr interface{}, err error) ([]byte, error)
+	Marshal(router string, dataPtr any, err error) ([]byte, error)
 	Unmarshal([]byte) (int, *MsgPack, error)
-	ToString(interface{}) string
+	ToString(any) string
 }
 
 var codecsList = make(map[string]Codec)

+ 2 - 2
pkg/websocket/codec/json/json.go

@@ -22,7 +22,7 @@ type jsonAck struct {
 	Error  string `json:"error,omitempty"`
 }
 
-func (*jsonCodec) Marshal(router string, dataPtr interface{}, retErr error) ([]byte, error) {
+func (*jsonCodec) Marshal(router string, dataPtr any, retErr error) ([]byte, error) {
 
 	if router == "" {
 		return nil, fmt.Errorf("marshal: router is empty")
@@ -83,7 +83,7 @@ func (*jsonCodec) Unmarshal(msg []byte) (int, *codec.MsgPack, error) {
 	return l, msgPack, nil
 }
 
-func (*jsonCodec) ToString(data interface{}) string {
+func (*jsonCodec) ToString(data any) string {
 	ab, err := json.Marshal(data)
 	if err != nil {
 		return fmt.Sprintf("invalid type %T", data)

+ 5 - 5
pkg/websocket/codec/meta.go

@@ -7,15 +7,15 @@ import (
 )
 
 type MsgPack struct {
-	Router  interface{}
-	DataPtr interface{}
+	Router  any
+	DataPtr any
 	Err     error
 }
 
-var modelMap = make(map[interface{}]reflect.Type)
+var modelMap = make(map[any]reflect.Type)
 var modelMapLock sync.RWMutex
 
-func RegisterMessage(router interface{}, datePtr interface{}) {
+func RegisterMessage(router any, datePtr any) {
 	modelMapLock.Lock()
 	defer modelMapLock.Unlock()
 	if _, ok := modelMap[router]; ok {
@@ -33,7 +33,7 @@ func RegisterMessage(router interface{}, datePtr interface{}) {
 	}
 }
 
-func GetMessage(router interface{}) interface{} {
+func GetMessage(router any) any {
 	modelMapLock.RLock()
 	defer modelMapLock.RUnlock()
 	if ptr, ok := modelMap[router]; ok {

+ 2 - 2
pkg/websocket/codec/protobuf/protobuf.go

@@ -11,7 +11,7 @@ import (
 
 type protobufCodec struct{}
 
-func (*protobufCodec) Marshal(router string, dataPtr interface{}, retErr error) ([]byte, error) {
+func (*protobufCodec) Marshal(router string, dataPtr any, retErr error) ([]byte, error) {
 	if router == "" {
 		return nil, fmt.Errorf("marshal: empty router")
 	}
@@ -71,7 +71,7 @@ func (*protobufCodec) Unmarshal(msg []byte) (int, *codec.MsgPack, error) {
 	return l, msgPack, nil
 }
 
-func (*protobufCodec) ToString(data interface{}) string {
+func (*protobufCodec) ToString(data any) string {
 	pbMsg, ok := data.(proto.Message)
 	if !ok {
 		return fmt.Sprintf("invalid type %T", data)

+ 1 - 1
pkg/websocket/peer/connect/connection.go

@@ -33,7 +33,7 @@ func (ws *wsConnection) Peer() *peer.SessionManager {
 	return ws.p
 }
 
-func (ws *wsConnection) Raw() interface{} {
+func (ws *wsConnection) Raw() any {
 	if ws.conn == nil {
 		return nil
 	}

+ 1 - 1
pkg/websocket/peer/connection.go

@@ -1,7 +1,7 @@
 package peer
 
 type Connection interface {
-	Raw() interface{}
+	Raw() any
 	Peer() *SessionManager
 	Send(msg []byte) error
 	Close()

+ 1 - 1
pkg/websocket/peer/session_manager.go

@@ -92,7 +92,7 @@ func (mgr *SessionManager) GetSession(id int64) *Session {
 }
 
 func (mgr *SessionManager) VisitSession(callback func(*Session) bool) {
-	mgr.sessionList.Range(func(key, value interface{}) bool {
+	mgr.sessionList.Range(func(key, value any) bool {
 		return callback(value.(*Session))
 	})
 }

+ 2 - 2
pkg/websocket/service/component.go

@@ -9,7 +9,7 @@ import (
 type Component interface {
 	Init()
 	OnSessionClose(*peer.Session) bool
-	OnRequestFinished(*peer.Session, string, interface{}, string, time.Duration)
+	OnRequestFinished(*peer.Session, string, any, string, time.Duration)
 }
 
 type ComponentBase struct{}
@@ -22,6 +22,6 @@ func (c *ComponentBase) OnSessionClose(session *peer.Session) bool {
 	return false
 }
 
-func (c *ComponentBase) OnRequestFinished(session *peer.Session, router string, req interface{}, errMsg string, delta time.Duration) {
+func (c *ComponentBase) OnRequestFinished(session *peer.Session, router string, req any, errMsg string, delta time.Duration) {
 
 }

+ 1 - 1
pkg/websocket/service/service_manager.go

@@ -47,7 +47,7 @@ func SetCodec(name string) error {
 	return nil
 }
 
-func Send(session *peer.Session, router string, data interface{}) error {
+func Send(session *peer.Session, router string, data any) error {
 	rb, err := routerCodec.Marshal(router, data, nil)
 	if err != nil {
 		return fmt.Errorf("service: %v", err)

+ 2 - 2
pkg/websocket/service/session_callback.go

@@ -25,7 +25,7 @@ func (cb *callBackEntity) OnClosed(session *peer.Session) {
 }
 
 //调用注册的函数
-func callHandlerFunc(foo reflect.Method, args []reflect.Value) (retValue interface{}, retErr error) {
+func callHandlerFunc(foo reflect.Method, args []reflect.Value) (retValue any, retErr error) {
 	defer func() {
 		if err := recover(); err != nil {
 			fmt.Println(fmt.Sprintf("callHandlerFunc: %v", err))
@@ -68,7 +68,7 @@ func (cb *callBackEntity) OnReceive(session *peer.Session, msg []byte) error {
 	t1 := time.Now()
 
 	var args = []reflect.Value{h.Receiver, reflect.ValueOf(session), reflect.ValueOf(msgPack.DataPtr)}
-	var res interface{}
+	var res any
 	var rb []byte
 	res, err = callHandlerFunc(h.Method, args)
 	if res != nil && !reflect.ValueOf(res).IsNil() {

+ 0 - 158
tool/help/aggregate.go

@@ -1,158 +0,0 @@
-package help
-
-// Aggregate applies an accumulator function over a sequence.
-//
-// Aggregate method makes it simple to perform a calculation over a sequence of
-// values. This method works by calling f() one time for each element in source
-// except the first one. Each time f() is called, Aggregate passes both the
-// element from the sequence and an aggregated value (as the first argument to
-// f()). The first element of source is used as the initial aggregate value. The
-// result of f() replaces the previous aggregated value.
-//
-// Aggregate returns the final result of f().
-func (q Query) Aggregate(f func(interface{}, interface{}) interface{}) interface{} {
-	next := q.Iterate()
-
-	result, any := next()
-	if !any {
-		return nil
-	}
-
-	for current, ok := next(); ok; current, ok = next() {
-		result = f(result, current)
-	}
-
-	return result
-}
-
-// AggregateT is the typed version of Aggregate.
-//
-//   - f is of type: func(TSource, TSource) TSource
-//
-// NOTE: Aggregate has better performance than AggregateT.
-func (q Query) AggregateT(f interface{}) interface{} {
-	fGenericFunc, err := newGenericFunc(
-		"AggregateT", "f", f,
-		simpleParamValidator(newElemTypeSlice(new(genericType), new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	fFunc := func(result interface{}, current interface{}) interface{} {
-		return fGenericFunc.Call(result, current)
-	}
-
-	return q.Aggregate(fFunc)
-}
-
-// AggregateWithSeed applies an accumulator function over a sequence. The
-// specified seed value is used as the initial accumulator value.
-//
-// Aggregate method makes it simple to perform a calculation over a sequence of
-// values. This method works by calling f() one time for each element in source
-// except the first one. Each time f() is called, Aggregate passes both the
-// element from the sequence and an aggregated value (as the first argument to
-// f()). The value of the seed parameter is used as the initial aggregate value.
-// The result of f() replaces the previous aggregated value.
-//
-// Aggregate returns the final result of f().
-func (q Query) AggregateWithSeed(seed interface{},
-	f func(interface{}, interface{}) interface{}) interface{} {
-
-	next := q.Iterate()
-	result := seed
-
-	for current, ok := next(); ok; current, ok = next() {
-		result = f(result, current)
-	}
-
-	return result
-}
-
-// AggregateWithSeedT is the typed version of AggregateWithSeed.
-//
-//   - f is of type "func(TAccumulate, TSource) TAccumulate"
-//
-// NOTE: AggregateWithSeed has better performance than
-// AggregateWithSeedT.
-func (q Query) AggregateWithSeedT(seed interface{},
-	f interface{}) interface{} {
-	fGenericFunc, err := newGenericFunc(
-		"AggregateWithSeed", "f", f,
-		simpleParamValidator(newElemTypeSlice(new(genericType), new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	fFunc := func(result interface{}, current interface{}) interface{} {
-		return fGenericFunc.Call(result, current)
-	}
-
-	return q.AggregateWithSeed(seed, fFunc)
-}
-
-// AggregateWithSeedBy applies an accumulator function over a sequence. The
-// specified seed value is used as the initial accumulator value, and the
-// specified function is used to select the result value.
-//
-// Aggregate method makes it simple to perform a calculation over a sequence of
-// values. This method works by calling f() one time for each element in source.
-// Each time func is called, Aggregate passes both the element from the sequence
-// and an aggregated value (as the first argument to func). The value of the
-// seed parameter is used as the initial aggregate value. The result of func
-// replaces the previous aggregated value.
-//
-// The final result of func is passed to resultSelector to obtain the final
-// result of Aggregate.
-func (q Query) AggregateWithSeedBy(seed interface{},
-	f func(interface{}, interface{}) interface{},
-	resultSelector func(interface{}) interface{}) interface{} {
-
-	next := q.Iterate()
-	result := seed
-
-	for current, ok := next(); ok; current, ok = next() {
-		result = f(result, current)
-	}
-
-	return resultSelector(result)
-}
-
-// AggregateWithSeedByT is the typed version of AggregateWithSeedBy.
-//
-//   - f is of type "func(TAccumulate, TSource) TAccumulate"
-//   - resultSelectorFn is of type "func(TAccumulate) TResult"
-//
-// NOTE: AggregateWithSeedBy has better performance than
-// AggregateWithSeedByT.
-func (q Query) AggregateWithSeedByT(seed interface{},
-	f interface{},
-	resultSelectorFn interface{}) interface{} {
-	fGenericFunc, err := newGenericFunc(
-		"AggregateWithSeedByT", "f", f,
-		simpleParamValidator(newElemTypeSlice(new(genericType), new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	fFunc := func(result interface{}, current interface{}) interface{} {
-		return fGenericFunc.Call(result, current)
-	}
-
-	resultSelectorGenericFunc, err := newGenericFunc(
-		"AggregateWithSeedByT", "resultSelectorFn", resultSelectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	resultSelectorFunc := func(result interface{}) interface{} {
-		return resultSelectorGenericFunc.Call(result)
-	}
-
-	return q.AggregateWithSeedBy(seed, fFunc, resultSelectorFunc)
-}

+ 0 - 119
tool/help/aggregate_test.go

@@ -1,119 +0,0 @@
-package help
-
-import "testing"
-import "strings"
-
-func TestAggregate(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  interface{}
-	}{
-		{[]string{"apple", "mango", "orange", "passionfruit", "grape"}, "passionfruit"},
-		{[]string{}, nil},
-	}
-
-	for _, test := range tests {
-		r := From(test.input).Aggregate(func(r interface{}, i interface{}) interface{} {
-			if len(r.(string)) > len(i.(string)) {
-				return r
-			}
-			return i
-		})
-
-		if r != test.want {
-			t.Errorf("From(%v).Aggregate()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestAggregateT_PanicWhenFunctionIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "AggregateT: parameter [f] has a invalid function signature. Expected: 'func(T,T)T', actual: 'func(int,string,string)string'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).AggregateT(func(x int, r string, i string) string {
-			if len(r) > len(i) {
-				return r
-			}
-			return i
-		})
-	})
-}
-
-func TestAggregateWithSeed(t *testing.T) {
-	input := []string{"apple", "mango", "orange", "banana", "grape"}
-	want := "passionfruit"
-
-	r := From(input).AggregateWithSeed(want,
-		func(r interface{}, i interface{}) interface{} {
-			if len(r.(string)) > len(i.(string)) {
-				return r
-			}
-			return i
-		})
-
-	if r != want {
-		t.Errorf("From(%v).AggregateWithSeed()=%v expected %v", input, r, want)
-	}
-}
-
-func TestAggregateWithSeedT_PanicWhenFunctionIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "AggregateWithSeed: parameter [f] has a invalid function signature. Expected: 'func(T,T)T', actual: 'func(int,string,string)string'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).AggregateWithSeedT(3, func(x int, r string, i string) string {
-			if len(r) > len(i) {
-				return r
-			}
-			return i
-		})
-	})
-}
-
-func TestAggregateWithSeedBy(t *testing.T) {
-	input := []string{"apple", "mango", "orange", "passionfruit", "grape"}
-	want := "PASSIONFRUIT"
-
-	r := From(input).AggregateWithSeedBy("banana",
-		func(r interface{}, i interface{}) interface{} {
-			if len(r.(string)) > len(i.(string)) {
-				return r
-			}
-			return i
-		},
-		func(r interface{}) interface{} {
-			return strings.ToUpper(r.(string))
-		},
-	)
-
-	if r != want {
-		t.Errorf("From(%v).AggregateWithSeed()=%v expected %v", input, r, want)
-	}
-}
-
-func TestAggregateWithSeedByT_PanicWhenFunctionIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "AggregateWithSeedByT: parameter [f] has a invalid function signature. Expected: 'func(T,T)T', actual: 'func(int,string,string)string'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).AggregateWithSeedByT(3,
-			func(x int, r string, i string) string {
-				if len(r) > len(i) {
-					return r
-				}
-				return i
-			},
-			func(r string) string {
-				return r
-			},
-		)
-	})
-}
-
-func TestAggregateWithSeedByT_PanicWhenResultSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "AggregateWithSeedByT: parameter [resultSelectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(string,int)string'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).AggregateWithSeedByT(3,
-			func(x int, r int) int {
-				if x > r {
-					return x
-				}
-				return r
-			},
-			func(r string, t int) string {
-				return r
-			},
-		)
-	})
-}

+ 0 - 93
tool/help/benchmark_test.go

@@ -1,93 +0,0 @@
-package help
-
-import "testing"
-
-const (
-	size = 1000000
-)
-
-func BenchmarkSelectWhereFirst(b *testing.B) {
-	for n := 0; n < b.N; n++ {
-		Range(1, size).Select(func(i interface{}) interface{} {
-			return -i.(int)
-		}).Where(func(i interface{}) bool {
-			return i.(int) > -1000
-		}).First()
-	}
-}
-
-func BenchmarkSelectWhereFirst_generics(b *testing.B) {
-	for n := 0; n < b.N; n++ {
-		Range(1, size).SelectT(func(i int) int {
-			return -i
-		}).WhereT(func(i int) bool {
-			return i > -1000
-		}).First()
-	}
-}
-
-func BenchmarkSum(b *testing.B) {
-	for n := 0; n < b.N; n++ {
-		Range(1, size).Where(func(i interface{}) bool {
-			return i.(int)%2 == 0
-		}).SumInts()
-	}
-}
-
-func BenchmarkSum_generics(b *testing.B) {
-	for n := 0; n < b.N; n++ {
-		Range(1, size).WhereT(func(i int) bool {
-			return i%2 == 0
-		}).SumInts()
-	}
-}
-
-func BenchmarkZipSkipTake(b *testing.B) {
-	for n := 0; n < b.N; n++ {
-		Range(1, size).Zip(Range(1, size).Select(func(i interface{}) interface{} {
-			return i.(int) * 2
-		}), func(i, j interface{}) interface{} {
-			return i.(int) + j.(int)
-		}).Skip(2).Take(5)
-	}
-}
-
-func BenchmarkZipSkipTake_generics(b *testing.B) {
-	for n := 0; n < b.N; n++ {
-		Range(1, size).ZipT(Range(1, size).SelectT(func(i int) int {
-			return i * 2
-		}), func(i, j int) int {
-			return i + j
-		}).Skip(2).Take(5)
-	}
-}
-
-func BenchmarkFromChannel(b *testing.B) {
-	for n := 0; n < b.N; n++ {
-		ch := make(chan interface{})
-		go func() {
-			for i := 0; i < size; i++ {
-				ch <- i
-			}
-
-			close(ch)
-		}()
-
-		FromChannel(ch).All(func(i interface{}) bool { return true })
-	}
-}
-
-func BenchmarkFromChannelT(b *testing.B) {
-	for n := 0; n < b.N; n++ {
-		ch := make(chan interface{})
-		go func() {
-			for i := 0; i < size; i++ {
-				ch <- i
-			}
-
-			close(ch)
-		}()
-
-		FromChannelT(ch).All(func(i interface{}) bool { return true })
-	}
-}

+ 0 - 200
tool/help/compare.go

@@ -1,200 +0,0 @@
-package help
-
-type comparer func(interface{}, interface{}) int
-
-// Comparable is an interface that has to be implemented by a custom collection
-// elements in order to work with linq.
-//
-// Example:
-// 	func (f foo) CompareTo(c Comparable) int {
-// 		a, b := f.f1, c.(foo).f1
-//
-// 		if a < b {
-// 			return -1
-// 		} else if a > b {
-// 			return 1
-// 		}
-//
-// 		return 0
-// 	}
-type Comparable interface {
-	CompareTo(Comparable) int
-}
-
-func getComparer(data interface{}) comparer {
-	switch data.(type) {
-	case int:
-		return func(x, y interface{}) int {
-			a, b := x.(int), y.(int)
-			switch {
-			case a > b:
-				return 1
-			case b > a:
-				return -1
-			default:
-				return 0
-			}
-		}
-	case int8:
-		return func(x, y interface{}) int {
-			a, b := x.(int8), y.(int8)
-			switch {
-			case a > b:
-				return 1
-			case b > a:
-				return -1
-			default:
-				return 0
-			}
-		}
-	case int16:
-		return func(x, y interface{}) int {
-			a, b := x.(int16), y.(int16)
-			switch {
-			case a > b:
-				return 1
-			case b > a:
-				return -1
-			default:
-				return 0
-			}
-		}
-	case int32:
-		return func(x, y interface{}) int {
-			a, b := x.(int32), y.(int32)
-			switch {
-			case a > b:
-				return 1
-			case b > a:
-				return -1
-			default:
-				return 0
-			}
-		}
-	case int64:
-		return func(x, y interface{}) int {
-			a, b := x.(int64), y.(int64)
-			switch {
-			case a > b:
-				return 1
-			case b > a:
-				return -1
-			default:
-				return 0
-			}
-		}
-	case uint:
-		return func(x, y interface{}) int {
-			a, b := x.(uint), y.(uint)
-			switch {
-			case a > b:
-				return 1
-			case b > a:
-				return -1
-			default:
-				return 0
-			}
-		}
-	case uint8:
-		return func(x, y interface{}) int {
-			a, b := x.(uint8), y.(uint8)
-			switch {
-			case a > b:
-				return 1
-			case b > a:
-				return -1
-			default:
-				return 0
-			}
-		}
-	case uint16:
-		return func(x, y interface{}) int {
-			a, b := x.(uint16), y.(uint16)
-			switch {
-			case a > b:
-				return 1
-			case b > a:
-				return -1
-			default:
-				return 0
-			}
-		}
-	case uint32:
-		return func(x, y interface{}) int {
-			a, b := x.(uint32), y.(uint32)
-			switch {
-			case a > b:
-				return 1
-			case b > a:
-				return -1
-			default:
-				return 0
-			}
-		}
-	case uint64:
-		return func(x, y interface{}) int {
-			a, b := x.(uint64), y.(uint64)
-			switch {
-			case a > b:
-				return 1
-			case b > a:
-				return -1
-			default:
-				return 0
-			}
-		}
-	case float32:
-		return func(x, y interface{}) int {
-			a, b := x.(float32), y.(float32)
-			switch {
-			case a > b:
-				return 1
-			case b > a:
-				return -1
-			default:
-				return 0
-			}
-		}
-	case float64:
-		return func(x, y interface{}) int {
-			a, b := x.(float64), y.(float64)
-			switch {
-			case a > b:
-				return 1
-			case b > a:
-				return -1
-			default:
-				return 0
-			}
-		}
-	case string:
-		return func(x, y interface{}) int {
-			a, b := x.(string), y.(string)
-			switch {
-			case a > b:
-				return 1
-			case b > a:
-				return -1
-			default:
-				return 0
-			}
-		}
-	case bool:
-		return func(x, y interface{}) int {
-			a, b := x.(bool), y.(bool)
-			switch {
-			case a == b:
-				return 0
-			case a:
-				return 1
-			default:
-				return -1
-			}
-		}
-	default:
-		return func(x, y interface{}) int {
-			a, b := x.(Comparable), y.(Comparable)
-			return a.CompareTo(b)
-		}
-	}
-}

+ 0 - 65
tool/help/compare_test.go

@@ -1,65 +0,0 @@
-package help
-
-import "testing"
-
-func TestGetComparer(t *testing.T) {
-	tests := []struct {
-		x    interface{}
-		y    interface{}
-		want int
-	}{
-		{100, 500, -1},
-		{-100, -500, 1},
-		{256, 256, 0},
-		{int8(100), int8(-100), 1},
-		{int8(-100), int8(100), -1},
-		{int8(100), int8(100), 0},
-		{int16(100), int16(-100), 1},
-		{int16(-100), int16(100), -1},
-		{int16(100), int16(100), 0},
-		{int32(100), int32(-100), 1},
-		{int32(-100), int32(100), -1},
-		{int32(100), int32(100), 0},
-		{int64(100), int64(-100), 1},
-		{int64(-100), int64(100), -1},
-		{int64(100), int64(100), 0},
-		{uint(100), uint(0), 1},
-		{uint(0), uint(100), -1},
-		{uint(100), uint(100), 0},
-		{uint8(100), uint8(0), 1},
-		{uint8(0), uint8(100), -1},
-		{uint8(100), uint8(100), 0},
-		{uint16(100), uint16(0), 1},
-		{uint16(0), uint16(100), -1},
-		{uint16(100), uint16(100), 0},
-		{uint32(100), uint32(0), 1},
-		{uint32(0), uint32(100), -1},
-		{uint32(100), uint32(100), 0},
-		{uint64(100), uint64(0), 1},
-		{uint64(0), uint64(100), -1},
-		{uint64(100), uint64(100), 0},
-		{float32(5.), float32(1.), 1},
-		{float32(1.), float32(5.), -1},
-		{float32(0), float32(0), 0},
-		{float64(5.), float64(1.), 1},
-		{float64(1.), float64(5.), -1},
-		{float64(0), float64(0), 0},
-		{true, true, 0},
-		{false, false, 0},
-		{true, false, 1},
-		{false, true, -1},
-		{"foo", "foo", 0},
-		{"foo", "bar", 1},
-		{"bar", "foo", -1},
-		{"FOO", "bar", -1},
-		{foo{f1: 1}, foo{f1: 5}, -1},
-		{foo{f1: 5}, foo{f1: 1}, 1},
-		{foo{f1: 1}, foo{f1: 1}, 0},
-	}
-
-	for _, test := range tests {
-		if r := getComparer(test.x)(test.x, test.y); r != test.want {
-			t.Errorf("getComparer(%v)(%v,%v)=%v expected %v", test.x, test.x, test.y, r, test.want)
-		}
-	}
-}

+ 0 - 74
tool/help/concat.go

@@ -1,74 +0,0 @@
-package help
-
-// Append inserts an item to the end of a collection, so it becomes the last
-// item.
-func (q Query) Append(item interface{}) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			appended := false
-
-			return func() (interface{}, bool) {
-				i, ok := next()
-				if ok {
-					return i, ok
-				}
-
-				if !appended {
-					appended = true
-					return item, true
-				}
-
-				return nil, false
-			}
-		},
-	}
-}
-
-// Concat concatenates two collections.
-//
-// The Concat method differs from the Union method because the Concat method
-// returns all the original elements in the input sequences. The Union method
-// returns only unique elements.
-func (q Query) Concat(q2 Query) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			next2 := q2.Iterate()
-			use1 := true
-
-			return func() (item interface{}, ok bool) {
-				if use1 {
-					item, ok = next()
-					if ok {
-						return
-					}
-
-					use1 = false
-				}
-
-				return next2()
-			}
-		},
-	}
-}
-
-// Prepend inserts an item to the beginning of a collection, so it becomes the
-// first item.
-func (q Query) Prepend(item interface{}) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			prepended := false
-
-			return func() (interface{}, bool) {
-				if prepended {
-					return next()
-				}
-
-				prepended = true
-				return item, true
-			}
-		},
-	}
-}

+ 0 - 31
tool/help/concat_test.go

@@ -1,31 +0,0 @@
-package help
-
-import "testing"
-
-func TestAppend(t *testing.T) {
-	input := []int{1, 2, 3, 4}
-	want := []interface{}{1, 2, 3, 4, 5}
-
-	if q := From(input).Append(5); !validateQuery(q, want) {
-		t.Errorf("From(%v).Append()=%v expected %v", input, toSlice(q), want)
-	}
-}
-
-func TestConcat(t *testing.T) {
-	input1 := []int{1, 2, 3}
-	input2 := []int{4, 5}
-	want := []interface{}{1, 2, 3, 4, 5}
-
-	if q := From(input1).Concat(From(input2)); !validateQuery(q, want) {
-		t.Errorf("From(%v).Concat(%v)=%v expected %v", input1, input2, toSlice(q), want)
-	}
-}
-
-func TestPrepend(t *testing.T) {
-	input := []int{1, 2, 3, 4}
-	want := []interface{}{0, 1, 2, 3, 4}
-
-	if q := From(input).Prepend(0); !validateQuery(q, want) {
-		t.Errorf("From(%v).Prepend()=%v expected %v", input, toSlice(q), want)
-	}
-}

+ 0 - 70
tool/help/convert.go

@@ -1,70 +0,0 @@
-package help
-
-type intConverter func(interface{}) int64
-
-func getIntConverter(data interface{}) intConverter {
-	switch data.(type) {
-	case int:
-		return func(i interface{}) int64 {
-			return int64(i.(int))
-		}
-	case int8:
-		return func(i interface{}) int64 {
-			return int64(i.(int8))
-		}
-	case int16:
-		return func(i interface{}) int64 {
-			return int64(i.(int16))
-		}
-	case int32:
-		return func(i interface{}) int64 {
-			return int64(i.(int32))
-		}
-	}
-
-	return func(i interface{}) int64 {
-		return i.(int64)
-	}
-}
-
-type uintConverter func(interface{}) uint64
-
-func getUIntConverter(data interface{}) uintConverter {
-	switch data.(type) {
-	case uint:
-		return func(i interface{}) uint64 {
-			return uint64(i.(uint))
-		}
-	case uint8:
-		return func(i interface{}) uint64 {
-			return uint64(i.(uint8))
-		}
-	case uint16:
-		return func(i interface{}) uint64 {
-			return uint64(i.(uint16))
-		}
-	case uint32:
-		return func(i interface{}) uint64 {
-			return uint64(i.(uint32))
-		}
-	}
-
-	return func(i interface{}) uint64 {
-		return i.(uint64)
-	}
-}
-
-type floatConverter func(interface{}) float64
-
-func getFloatConverter(data interface{}) floatConverter {
-	switch data.(type) {
-	case float32:
-		return func(i interface{}) float64 {
-			return float64(i.(float32))
-		}
-	}
-
-	return func(i interface{}) float64 {
-		return i.(float64)
-	}
-}

+ 0 - 57
tool/help/convert_test.go

@@ -1,57 +0,0 @@
-package help
-
-import "testing"
-
-func TestIntConverter(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  int64
-	}{
-		{2, 2},
-		{int8(-1), -1},
-		{int16(0), 0},
-		{int32(10), 10},
-		{int64(5), 5},
-	}
-
-	for _, test := range tests {
-		if conv := getIntConverter(test.input); conv(test.input) != test.want {
-			t.Errorf("IntConverter for %v failed", test.input)
-		}
-	}
-}
-
-func TestUIntConverter(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  uint64
-	}{
-		{uint(2), 2},
-		{uint8(1), 1},
-		{uint16(0), 0},
-		{uint32(10), 10},
-		{uint64(5), 5},
-	}
-
-	for _, test := range tests {
-		if conv := getUIntConverter(test.input); conv(test.input) != test.want {
-			t.Errorf("UIntConverter for %v failed", test.input)
-		}
-	}
-}
-
-func TestFloatConverter(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  float64
-	}{
-		{float32(-1), -1},
-		{float64(0), 0},
-	}
-
-	for _, test := range tests {
-		if conv := getFloatConverter(test.input); conv(test.input) != test.want {
-			t.Errorf("FloatConverter for %v failed", test.input)
-		}
-	}
-}

+ 0 - 33
tool/help/defaultifempty.go

@@ -1,33 +0,0 @@
-package help
-
-// DefaultIfEmpty returns the elements of the specified sequence
-// if the sequence is empty.
-func (q Query) DefaultIfEmpty(defaultValue interface{}) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			state := 1
-
-			return func() (item interface{}, ok bool) {
-				switch state {
-				case 1:
-					item, ok = next()
-					if ok {
-						state = 2
-					} else {
-						item = defaultValue
-						ok = true
-						state = -1
-					}
-					return
-				case 2:
-					for item, ok = next(); ok; item, ok = next() {
-						return
-					}
-					return
-				}
-				return
-			}
-		},
-	}
-}

+ 0 - 25
tool/help/defaultifempty_test.go

@@ -1,25 +0,0 @@
-package help
-
-import (
-	"testing"
-)
-
-func TestDefaultIfEmpty(t *testing.T) {
-	defaultValue := 0
-	tests := []struct {
-		input []interface{}
-		want  []interface{}
-	}{
-		{[]interface{}{}, []interface{}{defaultValue}},
-		{[]interface{}{1, 2, 3, 4, 5}, []interface{}{1, 2, 3, 4, 5}},
-	}
-
-	for _, test := range tests {
-		q := From(test.input).DefaultIfEmpty(defaultValue)
-
-		if !validateQuery(q, test.want) {
-			t.Errorf("From(%v).DefaultIfEmpty(%v)=%v expected %v", test.input, defaultValue, toSlice(q), test.want)
-		}
-	}
-
-}

+ 0 - 98
tool/help/distinct.go

@@ -1,98 +0,0 @@
-package help
-
-// Distinct method returns distinct elements from a collection. The result is an
-// unordered collection that contains no duplicate values.
-func (q Query) Distinct() Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			set := make(map[interface{}]bool)
-
-			return func() (item interface{}, ok bool) {
-				for item, ok = next(); ok; item, ok = next() {
-					if _, has := set[item]; !has {
-						set[item] = true
-						return
-					}
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// Distinct method returns distinct elements from a collection. The result is an
-// ordered collection that contains no duplicate values.
-//
-// NOTE: Distinct method on OrderedQuery type has better performance than
-// Distinct method on Query type.
-func (oq OrderedQuery) Distinct() OrderedQuery {
-	return OrderedQuery{
-		orders: oq.orders,
-		Query: Query{
-			Iterate: func() Iterator {
-				next := oq.Iterate()
-				var prev interface{}
-
-				return func() (item interface{}, ok bool) {
-					for item, ok = next(); ok; item, ok = next() {
-						if item != prev {
-							prev = item
-							return
-						}
-					}
-
-					return
-				}
-			},
-		},
-	}
-}
-
-// DistinctBy method returns distinct elements from a collection. This method
-// executes selector function for each element to determine a value to compare.
-// The result is an unordered collection that contains no duplicate values.
-func (q Query) DistinctBy(selector func(interface{}) interface{}) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			set := make(map[interface{}]bool)
-
-			return func() (item interface{}, ok bool) {
-				for item, ok = next(); ok; item, ok = next() {
-					s := selector(item)
-					if _, has := set[s]; !has {
-						set[s] = true
-						return
-					}
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// DistinctByT is the typed version of DistinctBy.
-//
-//   - selectorFn is of type "func(TSource) TSource".
-//
-// NOTE: DistinctBy has better performance than DistinctByT.
-func (q Query) DistinctByT(selectorFn interface{}) Query {
-	selectorFunc, ok := selectorFn.(func(interface{}) interface{})
-	if !ok {
-		selectorGenericFunc, err := newGenericFunc(
-			"DistinctByT", "selectorFn", selectorFn,
-			simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-		)
-		if err != nil {
-			panic(err)
-		}
-
-		selectorFunc = func(item interface{}) interface{} {
-			return selectorGenericFunc.Call(item)
-		}
-	}
-	return q.DistinctBy(selectorFunc)
-}

+ 0 - 61
tool/help/distinct_test.go

@@ -1,61 +0,0 @@
-package help
-
-import "testing"
-
-func TestDistinct(t *testing.T) {
-	tests := []struct {
-		input  interface{}
-		output []interface{}
-	}{
-		{[]int{1, 2, 2, 3, 1}, []interface{}{1, 2, 3}},
-		{[9]int{1, 1, 1, 2, 1, 2, 3, 4, 2}, []interface{}{1, 2, 3, 4}},
-		{"sstr", []interface{}{'s', 't', 'r'}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).Distinct(); !validateQuery(q, test.output) {
-			t.Errorf("From(%v).Distinct()=%v expected %v", test.input, toSlice(q), test.output)
-		}
-	}
-}
-
-func TestDistinctForOrderedQuery(t *testing.T) {
-	tests := []struct {
-		input  interface{}
-		output []interface{}
-	}{
-		{[]int{1, 2, 2, 3, 1}, []interface{}{1, 2, 3}},
-		{[9]int{1, 1, 1, 2, 1, 2, 3, 4, 2}, []interface{}{1, 2, 3, 4}},
-		{"sstr", []interface{}{'r', 's', 't'}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).OrderBy(func(i interface{}) interface{} {
-			return i
-		}).Distinct(); !validateQuery(q.Query, test.output) {
-			t.Errorf("From(%v).Distinct()=%v expected %v", test.input, toSlice(q.Query), test.output)
-		}
-	}
-}
-
-func TestDistinctBy(t *testing.T) {
-	type user struct {
-		id   int
-		name string
-	}
-
-	users := []user{{1, "Foo"}, {2, "Bar"}, {3, "Foo"}}
-	want := []interface{}{user{1, "Foo"}, user{2, "Bar"}}
-
-	if q := From(users).DistinctBy(func(u interface{}) interface{} {
-		return u.(user).name
-	}); !validateQuery(q, want) {
-		t.Errorf("From(%v).DistinctBy()=%v expected %v", users, toSlice(q), want)
-	}
-}
-
-func TestDistinctByT_PanicWhenSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "DistinctByT: parameter [selectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(string,string)bool'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).DistinctByT(func(indice, item string) bool { return item == "2" })
-	})
-}

+ 0 - 6
tool/help/doc.go

@@ -1,6 +0,0 @@
-// package help provides methods for querying and manipulating slices, arrays,
-// maps, strings, channels and collections.
-//
-// Authors: Alexander Kalankhodzhaev (kalan), Ahmet Alp Balkan, Cleiton Marques
-// Souza.
-package help

+ 0 - 2627
tool/help/example_test.go

@@ -1,2627 +0,0 @@
-package help
-
-import (
-	"fmt"
-	"strings"
-	"time"
-)
-
-func ExampleKeyValue() {
-	m := make(map[int]bool)
-	m[10] = true
-
-	fmt.Println(From(m).Results())
-	// Output:
-	// [{10 true}]
-}
-
-func ExampleKeyValue_second() {
-	input := []KeyValue{
-		{10, true},
-	}
-
-	m := make(map[int]bool)
-	From(input).
-		ToMap(&m)
-
-	fmt.Println(m)
-	// Output:
-	// map[10:true]
-}
-
-// The following code example demonstrates how
-// to use Range to generate a slice of values.
-func ExampleRange() {
-	// Generate a slice of integers from 1 to 10
-	// and then select their squares.
-	var squares []int
-	Range(1, 10).
-		SelectT(
-			func(x int) int { return x * x },
-		).
-		ToSlice(&squares)
-
-	for _, num := range squares {
-		fmt.Println(num)
-	}
-	//Output:
-	//1
-	//4
-	//9
-	//16
-	//25
-	//36
-	//49
-	//64
-	//81
-	//100
-}
-
-// The following code example demonstrates how to use Repeat
-// to generate a slice of a repeated value.
-func ExampleRepeat() {
-	var slice []string
-	Repeat("I like programming.", 5).
-		ToSlice(&slice)
-
-	for _, str := range slice {
-		fmt.Println(str)
-	}
-	//Output:
-	//I like programming.
-	//I like programming.
-	//I like programming.
-	//I like programming.
-	//I like programming.
-
-}
-
-func ExampleQuery() {
-	query := From([]int{1, 2, 3, 4, 5}).Where(func(i interface{}) bool {
-		return i.(int) <= 3
-	})
-
-	next := query.Iterate()
-	for item, ok := next(); ok; item, ok = next() {
-		fmt.Println(item)
-	}
-	// Output:
-	// 1
-	// 2
-	// 3
-}
-
-// The following code example demonstrates how to use Aggregate function
-func ExampleQuery_Aggregate() {
-	fruits := []string{"apple", "mango", "orange", "passionfruit", "grape"}
-
-	// Determine which string in the slice is the longest.
-	longestName := From(fruits).
-		Aggregate(
-			func(r interface{}, i interface{}) interface{} {
-				if len(r.(string)) > len(i.(string)) {
-					return r
-				}
-				return i
-			},
-		)
-
-	fmt.Println(longestName)
-	// Output:
-	// passionfruit
-}
-
-// The following code example demonstrates how to use AggregateWithSeed function
-func ExampleQuery_AggregateWithSeed() {
-	ints := []int{4, 8, 8, 3, 9, 0, 7, 8, 2}
-
-	// Count the even numbers in the array, using a seed value of 0.
-	numEven := From(ints).
-		AggregateWithSeed(0,
-			func(total, next interface{}) interface{} {
-				if next.(int)%2 == 0 {
-					return total.(int) + 1
-				}
-				return total
-			},
-		)
-
-	fmt.Printf("The number of even integers is: %d", numEven)
-	// Output:
-	// The number of even integers is: 6
-}
-
-// The following code example demonstrates how to use AggregateWithSeedBy function
-func ExampleQuery_AggregateWithSeedBy() {
-	input := []string{"apple", "mango", "orange", "passionfruit", "grape"}
-
-	// Determine whether any string in the array is longer than "banana".
-	longestName := From(input).
-		AggregateWithSeedBy("banana",
-			func(longest interface{}, next interface{}) interface{} {
-				if len(longest.(string)) > len(next.(string)) {
-					return longest
-				}
-				return next
-
-			},
-			// Return the final result
-			func(result interface{}) interface{} {
-				return fmt.Sprintf("The fruit with the longest name is %s.", result)
-			},
-		)
-
-	fmt.Println(longestName)
-	// Output:
-	// The fruit with the longest name is passionfruit.
-}
-
-// The following code example demonstrates how to
-// use Distinct to return distinct elements from a slice of integers.
-func ExampleOrderedQuery_Distinct() {
-	ages := []int{21, 46, 46, 55, 17, 21, 55, 55}
-
-	var distinctAges []int
-	From(ages).
-		OrderBy(
-			func(item interface{}) interface{} { return item },
-		).
-		Distinct().
-		ToSlice(&distinctAges)
-
-	fmt.Println(distinctAges)
-	// Output:
-	// [17 21 46 55]
-}
-
-// The following code example demonstrates how to
-// use DistinctBy to return distinct elements from a ordered slice of elements.
-func ExampleOrderedQuery_DistinctBy() {
-	type Product struct {
-		Name string
-		Code int
-	}
-
-	products := []Product{
-		{Name: "orange", Code: 4},
-		{Name: "apple", Code: 9},
-		{Name: "lemon", Code: 12},
-		{Name: "apple", Code: 9},
-	}
-
-	//Order and exclude duplicates.
-	var noduplicates []Product
-	From(products).
-		OrderBy(
-			func(item interface{}) interface{} { return item.(Product).Name },
-		).
-		DistinctBy(
-			func(item interface{}) interface{} { return item.(Product).Code },
-		).
-		ToSlice(&noduplicates)
-
-	for _, product := range noduplicates {
-		fmt.Printf("%s %d\n", product.Name, product.Code)
-	}
-	// Output:
-	// apple 9
-	// lemon 12
-	// orange 4
-}
-
-// The following code example demonstrates how to use ThenBy to perform
-// a secondary ordering of the elements in a slice.
-func ExampleOrderedQuery_ThenBy() {
-	fruits := []string{"grape", "passionfruit", "banana", "mango", "orange", "raspberry", "apple", "blueberry"}
-
-	// Sort the strings first by their length and then
-	//alphabetically by passing the identity selector function.
-	var query []string
-	From(fruits).
-		OrderBy(
-			func(fruit interface{}) interface{} { return len(fruit.(string)) },
-		).
-		ThenBy(
-			func(fruit interface{}) interface{} { return fruit },
-		).
-		ToSlice(&query)
-
-	for _, fruit := range query {
-		fmt.Println(fruit)
-	}
-	// Output:
-	// apple
-	// grape
-	// mango
-	// banana
-	// orange
-	// blueberry
-	// raspberry
-	// passionfruit
-}
-
-// The following code example demonstrates how to use All to determine
-// whether all the elements in a slice satisfy a condition.
-// Variable allStartWithB is true if all the pet names start with "B"
-// or if the pets array is empty.
-func ExampleQuery_All() {
-
-	type Pet struct {
-		Name string
-		Age  int
-	}
-
-	pets := []Pet{
-		{Name: "Barley", Age: 10},
-		{Name: "Boots", Age: 4},
-		{Name: "Whiskers", Age: 6},
-	}
-
-	// Determine whether all pet names
-	// in the array start with 'B'.
-	allStartWithB := From(pets).
-		All(
-			func(pet interface{}) bool { return strings.HasPrefix(pet.(Pet).Name, "B") },
-		)
-
-	fmt.Printf("All pet names start with 'B'? %t", allStartWithB)
-	// Output:
-	//
-	//  All pet names start with 'B'? false
-}
-
-// The following code example demonstrates how to use Any to determine
-// whether a slice contains any elements.
-func ExampleQuery_Any() {
-
-	numbers := []int{1, 2}
-	hasElements := From(numbers).Any()
-
-	fmt.Printf("Are there any element in the list? %t", hasElements)
-	// Output:
-	// Are there any element in the list? true
-}
-
-// The following code example demonstrates how to use AnyWith
-// to determine whether any element in a slice satisfies a condition.
-func ExampleQuery_AnyWith() {
-
-	type Pet struct {
-		Name       string
-		Age        int
-		Vaccinated bool
-	}
-
-	pets := []Pet{
-		{Name: "Barley", Age: 8, Vaccinated: true},
-		{Name: "Boots", Age: 4, Vaccinated: false},
-		{Name: "Whiskers", Age: 1, Vaccinated: false},
-	}
-
-	// Determine whether any pets over age 1 are also unvaccinated.
-	unvaccinated := From(pets).
-		AnyWith(
-			func(p interface{}) bool {
-				return p.(Pet).Age > 1 && p.(Pet).Vaccinated == false
-			},
-		)
-
-	fmt.Printf("Are there any unvaccinated animals over age one? %t", unvaccinated)
-	// Output:
-	//
-	// Are there any unvaccinated animals over age one? true
-}
-
-// The following code example demonstrates how to use Append
-// to include an elements in the last position of a slice.
-func ExampleQuery_Append() {
-	input := []int{1, 2, 3, 4}
-
-	q := From(input).Append(5)
-
-	last := q.Last()
-
-	fmt.Println(last)
-	// Output:
-	// 5
-}
-
-//The following code example demonstrates how to use Average
-//to calculate the average of a slice of values.
-func ExampleQuery_Average() {
-	grades := []int{78, 92, 100, 37, 81}
-	average := From(grades).Average()
-
-	fmt.Println(average)
-	// Output:
-	// 77.6
-}
-
-// The following code example demonstrates how to use Count
-// to count the elements in an array.
-func ExampleQuery_Count() {
-	fruits := []string{"apple", "banana", "mango", "orange", "passionfruit", "grape"}
-	numberOfFruits := From(fruits).Count()
-
-	fmt.Println(numberOfFruits)
-	// Output:
-	// 6
-}
-
-// The following code example demonstrates how to use Contains
-// to determine whether a slice contains a specific element.
-func ExampleQuery_Contains() {
-	slice := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
-
-	has5 := From(slice).Contains(5)
-
-	fmt.Printf("Does the slice contains 5? %t", has5)
-	// Output:
-	// Does the slice contains 5? true
-}
-
-//The following code example demonstrates how to use CountWith
-//to count the even numbers in an array.
-func ExampleQuery_CountWith() {
-	slice := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
-
-	evenCount := From(slice).
-		CountWith(
-			func(item interface{}) bool { return item.(int)%2 == 0 },
-		)
-
-	fmt.Println(evenCount)
-	// Output:
-	// 6
-}
-
-// The following example demonstrates how to use the DefaultIfEmpty
-// method on the results of a group join to perform a left outer join.
-//
-// The first step in producing a left outer join of two collections is to perform
-// an inner join by using a group join. In this example, the list of Person objects
-// is inner-joined to the list of Pet objects based on a Person object that matches Pet.Owner.
-//
-// The second step is to include each element of the first (left) collection in the
-// result set even if that element has no matches in the right collection.
-// This is accomplished by calling DefaultIfEmpty on each sequence of matching
-// elements from the group join.
-// In this example, DefaultIfEmpty is called on each sequence of matching Pet elements.
-// The method returns a collection that contains a single, default value if the sequence
-// of matching Pet elements is empty for any Person element, thereby ensuring that each
-// Person element is represented in the result collection.
-func ExampleQuery_DefaultIfEmpty() {
-	type Person struct {
-		FirstName string
-		LastName  string
-	}
-
-	type Pet struct {
-		Name  string
-		Owner Person
-	}
-
-	magnus := Person{FirstName: "Magnus", LastName: "Hedlund"}
-	terry := Person{FirstName: "Terry", LastName: "Adams"}
-	charlotte := Person{FirstName: "Charlotte", LastName: "Weiss"}
-	arlene := Person{FirstName: "Arlene", LastName: "Huff"}
-
-	barley := Pet{Name: "Barley", Owner: terry}
-	boots := Pet{Name: "Boots", Owner: terry}
-	whiskers := Pet{Name: "Whiskers", Owner: charlotte}
-	bluemoon := Pet{Name: "Blue Moon", Owner: terry}
-	daisy := Pet{Name: "Daisy", Owner: magnus}
-
-	// Create two lists.
-	people := []Person{magnus, terry, charlotte, arlene}
-	pets := []Pet{barley, boots, whiskers, bluemoon, daisy}
-
-	results := []string{}
-	From(people).
-		GroupJoinT(
-			From(pets),
-			func(person Person) Person { return person },
-			func(pet Pet) Person { return pet.Owner },
-			func(person Person, pets []Pet) Group { return Group{Key: person, Group: From(pets).Results()} },
-		).
-		SelectManyByT(
-			func(g Group) Query { return From(g.Group).DefaultIfEmpty(Pet{}) },
-			func(pet Pet, group Group) string {
-				return fmt.Sprintf("%s: %s", group.Key.(Person).FirstName, pet.Name)
-			},
-		).
-		ToSlice(&results)
-
-	for _, s := range results {
-		fmt.Println(s)
-	}
-	// Output:
-	// Magnus: Daisy
-	// Terry: Barley
-	// Terry: Boots
-	// Terry: Blue Moon
-	// Charlotte: Whiskers
-	// Arlene:
-
-}
-
-//The following code example demonstrates how to use Distinct
-//to return distinct elements from a slice of integers.
-func ExampleQuery_Distinct() {
-	ages := []int{21, 46, 46, 55, 17, 21, 55, 55}
-
-	var distinctAges []int
-	From(ages).
-		Distinct().
-		ToSlice(&distinctAges)
-
-	fmt.Println(distinctAges)
-	// Output:
-	// [21 46 55 17]
-}
-
-// The following code example demonstrates how to
-// use DistinctBy to return distinct elements from a ordered slice of elements.
-func ExampleQuery_DistinctBy() {
-	type Product struct {
-		Name string
-		Code int
-	}
-
-	products := []Product{
-		{Name: "orange", Code: 4},
-		{Name: "apple", Code: 9},
-		{Name: "lemon", Code: 12},
-		{Name: "apple", Code: 9},
-	}
-
-	//Order and exclude duplicates.
-	var noduplicates []Product
-	From(products).
-		DistinctBy(
-			func(item interface{}) interface{} { return item.(Product).Code },
-		).
-		ToSlice(&noduplicates)
-
-	for _, product := range noduplicates {
-		fmt.Printf("%s %d\n", product.Name, product.Code)
-	}
-	// Output:
-	// orange 4
-	// apple 9
-	// lemon 12
-
-}
-
-// The following code example demonstrates how to use the Except
-// method to compare two slices of numbers and return elements
-// that appear only in the first slice.
-func ExampleQuery_Except() {
-	numbers1 := []float32{2.0, 2.1, 2.2, 2.3, 2.4, 2.5}
-	numbers2 := []float32{2.2}
-
-	var onlyInFirstSet []float32
-	From(numbers1).
-		Except(From(numbers2)).
-		ToSlice(&onlyInFirstSet)
-
-	for _, number := range onlyInFirstSet {
-		fmt.Println(number)
-	}
-	// Output:
-	//2
-	//2.1
-	//2.3
-	//2.4
-	//2.5
-
-}
-
-// The following code example demonstrates how to use the Except
-// method to compare two slices of numbers and return elements
-// that appear only in the first slice.
-func ExampleQuery_ExceptBy() {
-	type Product struct {
-		Name string
-		Code int
-	}
-
-	fruits1 := []Product{
-		{Name: "orange", Code: 4},
-		{Name: "apple", Code: 9},
-		{Name: "lemon", Code: 12},
-		{Name: "apple", Code: 9},
-	}
-
-	fruits2 := []Product{
-		{Name: "apple", Code: 9},
-	}
-
-	//Order and exclude duplicates.
-	var except []Product
-	From(fruits1).
-		ExceptBy(From(fruits2),
-			func(item interface{}) interface{} { return item.(Product).Code },
-		).
-		ToSlice(&except)
-
-	for _, product := range except {
-		fmt.Printf("%s %d\n", product.Name, product.Code)
-	}
-	// Output:
-	// orange 4
-	// lemon 12
-
-}
-
-// The following code example demonstrates how to use First
-// to return the first element of an array.
-func ExampleQuery_First() {
-	numbers := []int{9, 34, 65, 92, 87, 435, 3, 54, 83, 23, 87, 435, 67, 12, 19}
-
-	first := From(numbers).First()
-
-	fmt.Println(first)
-	// Output:
-	// 9
-
-}
-
-//The following code example demonstrates how to use FirstWith
-// to return the first element of an array that satisfies a condition.
-func ExampleQuery_FirstWith() {
-	numbers := []int{9, 34, 65, 92, 87, 435, 3, 54, 83, 23, 87, 435, 67, 12, 19}
-
-	first := From(numbers).
-		FirstWith(
-			func(item interface{}) bool { return item.(int) > 80 },
-		)
-
-	fmt.Println(first)
-	// Output:
-	// 92
-
-}
-
-//The following code example demonstrates how to use Intersect
-//to return the elements that appear in each of two slices of integers.
-func ExampleQuery_Intersect() {
-	id1 := []int{44, 26, 92, 30, 71, 38}
-	id2 := []int{39, 59, 83, 47, 26, 4, 30}
-
-	var both []int
-	From(id1).
-		Intersect(From(id2)).
-		ToSlice(&both)
-
-	for _, id := range both {
-		fmt.Println(id)
-	}
-	// Output:
-	// 26
-	// 30
-
-}
-
-//The following code example demonstrates how to use IntersectBy
-//to return the elements that appear in each of two slices of products with same Code.
-func ExampleQuery_IntersectBy() {
-	type Product struct {
-		Name string
-		Code int
-	}
-
-	store1 := []Product{
-		{Name: "orange", Code: 4},
-		{Name: "apple", Code: 9},
-	}
-
-	store2 := []Product{
-		{Name: "lemon", Code: 12},
-		{Name: "apple", Code: 9},
-	}
-
-	var duplicates []Product
-	From(store1).
-		IntersectBy(From(store2),
-			func(p interface{}) interface{} { return p.(Product).Code },
-		).
-		ToSlice(&duplicates)
-
-	for _, p := range duplicates {
-		fmt.Println(p.Name, "", p.Code)
-	}
-	// Output:
-	// apple  9
-
-}
-
-// The following code example demonstrates how to use Last
-// to return the last element of an array.
-func ExampleQuery_Last() {
-	numbers := []int{9, 34, 65, 92, 87, 435, 3, 54,
-		83, 23, 87, 67, 12, 19}
-
-	last := From(numbers).Last()
-
-	fmt.Println(last)
-
-	//Output:
-	//19
-
-}
-
-// The following code example demonstrates how to use LastWith
-// to return the last element of an array.
-func ExampleQuery_LastWith() {
-	numbers := []int{9, 34, 65, 92, 87, 435, 3, 54,
-		83, 23, 87, 67, 12, 19}
-
-	last := From(numbers).
-		LastWith(
-			func(n interface{}) bool { return n.(int) > 80 },
-		)
-
-	fmt.Println(last)
-
-	//Output:
-	//87
-
-}
-
-// The following code example demonstrates how to use Max
-// to determine the maximum value in a slice.
-func ExampleQuery_Max() {
-	numbers := []int64{4294967296, 466855135, 81125}
-
-	last := From(numbers).Max()
-
-	fmt.Println(last)
-
-	//Output:
-	//4294967296
-
-}
-
-// The following code example demonstrates how to use Min
-// to determine the minimum value in a slice.
-func ExampleQuery_Min() {
-	grades := []int{78, 92, 99, 37, 81}
-
-	min := From(grades).Min()
-
-	fmt.Println(min)
-
-	//Output:
-	//37
-
-}
-
-// The following code example demonstrates how to use OrderByDescending
-// to sort the elements of a slice in descending order by using a selector function
-func ExampleQuery_OrderByDescending() {
-	names := []string{"Ned", "Ben", "Susan"}
-
-	var result []string
-	From(names).
-		OrderByDescending(
-			func(n interface{}) interface{} { return n },
-		).ToSlice(&result)
-
-	fmt.Println(result)
-	// Output:
-	// [Susan Ned Ben]
-}
-
-// The following code example demonstrates how to use ThenByDescending to perform
-// a secondary ordering of the elements in a slice in descending order.
-func ExampleOrderedQuery_ThenByDescending() {
-	fruits := []string{"apPLe", "baNanA", "apple", "APple", "orange", "BAnana", "ORANGE", "apPLE"}
-
-	// Sort the strings first ascending by their length and
-	// then descending using a custom case insensitive comparer.
-	var query []string
-	From(fruits).
-		OrderBy(
-			func(fruit interface{}) interface{} { return len(fruit.(string)) },
-		).
-		ThenByDescending(
-			func(fruit interface{}) interface{} { return fruit.(string)[0] },
-		).
-		ToSlice(&query)
-
-	for _, fruit := range query {
-		fmt.Println(fruit)
-	}
-	// Output:
-	// apPLe
-	// apPLE
-	// apple
-	// APple
-	// orange
-	// baNanA
-	// ORANGE
-	// BAnana
-
-}
-
-// The following code example demonstrates how to use Concat
-// to concatenate two slices.
-func ExampleQuery_Concat() {
-	q := From([]int{1, 2, 3}).
-		Concat(From([]int{4, 5, 6}))
-
-	fmt.Println(q.Results())
-	// Output:
-	// [1 2 3 4 5 6]
-}
-
-func ExampleQuery_GroupBy() {
-	input := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
-
-	q := From(input).GroupBy(
-		func(i interface{}) interface{} { return i.(int) % 2 },
-		func(i interface{}) interface{} { return i.(int) })
-
-	fmt.Println(q.OrderBy(func(i interface{}) interface{} {
-		return i.(Group).Key
-	}).Results())
-	// Output:
-	// [{0 [2 4 6 8]} {1 [1 3 5 7 9]}]
-}
-
-// The following code example demonstrates how to use GroupJoin
-// to perform a grouped join on two slices
-func ExampleQuery_GroupJoin() {
-	fruits := []string{
-		"apple",
-		"banana",
-		"apricot",
-		"cherry",
-		"clementine",
-	}
-
-	q := FromString("abc").
-		GroupJoin(From(fruits),
-			func(i interface{}) interface{} { return i },
-			func(i interface{}) interface{} { return []rune(i.(string))[0] },
-			func(outer interface{}, inners []interface{}) interface{} {
-				return KeyValue{string(outer.(rune)), inners}
-			},
-		)
-
-	fmt.Println(q.Results())
-	// Output:
-	// [{a [apple apricot]} {b [banana]} {c [cherry clementine]}]
-}
-
-// The following code example demonstrates how to use IndexOf
-// to retrieve the position of an item in the array and then
-// update that item.
-func ExampleQuery_IndexOf() {
-	type Item struct {
-		ID   uint64
-		Name string
-	}
-	items := []Item{
-		{
-			ID:   1,
-			Name: "Joe",
-		},
-		{
-			ID:   2,
-			Name: "Bob",
-		},
-		{
-			ID:   3,
-			Name: "Rickster",
-		},
-		{
-			ID:   4,
-			Name: "Jim",
-		},
-	}
-
-	index := From(items).IndexOf(func(i interface{}) bool {
-		item, ok := i.(Item)
-		return ok && item.Name == "Rickster"
-	})
-
-	if index >= 0 {
-		// We found the item in the array. Change the name using the index.
-		items[index].Name = "Joshua"
-		fmt.Println("Item found at:", index, "new name:", items[index].Name)
-	}
-	// Output:
-	// Item found at: 2 new name: Joshua
-}
-
-// The following code example demonstrates how to use Join
-// to perform an inner join of two slices based on a common key.
-func ExampleQuery_Join() {
-	fruits := []string{
-		"apple",
-		"banana",
-		"apricot",
-		"cherry",
-		"clementine",
-	}
-
-	q := Range(1, 10).
-		Join(From(fruits),
-			func(i interface{}) interface{} { return i },
-			func(i interface{}) interface{} { return len(i.(string)) },
-			func(outer interface{}, inner interface{}) interface{} {
-				return KeyValue{outer, inner}
-			},
-		)
-
-	fmt.Println(q.Results())
-	// Output:
-	// [{5 apple} {6 banana} {6 cherry} {7 apricot} {10 clementine}]
-}
-
-// The following code example demonstrates how to use OrderBy
-// to sort the elements of a slice.
-func ExampleQuery_OrderBy() {
-	q := Range(1, 10).
-		OrderBy(
-			func(i interface{}) interface{} { return i.(int) % 2 },
-		).
-		ThenByDescending(
-			func(i interface{}) interface{} { return i },
-		)
-
-	fmt.Println(q.Results())
-	// Output:
-	// [10 8 6 4 2 9 7 5 3 1]
-}
-
-// The following code example demonstrates how to use Prepend
-// to include an elements in the first position of a slice.
-func ExampleQuery_Prepend() {
-	input := []int{2, 3, 4, 5}
-
-	q := From(input).Prepend(1)
-	first := q.First()
-
-	fmt.Println(first)
-	// Output:
-	// 1
-}
-
-// The following code example demonstrates how to use Reverse
-// to reverse the order of elements in a string.
-func ExampleQuery_Reverse() {
-	input := "apple"
-
-	var output []rune
-	From(input).
-		Reverse().
-		ToSlice(&output)
-
-	fmt.Println(string(output))
-	// Output:
-	// elppa
-}
-
-// The following code example demonstrates how to use Select
-// to project over a slice of values.
-func ExampleQuery_Select() {
-	squares := []int{}
-
-	Range(1, 10).
-		Select(
-			func(x interface{}) interface{} { return x.(int) * x.(int) },
-		).
-		ToSlice(&squares)
-
-	fmt.Println(squares)
-	// Output:
-	// [1 4 9 16 25 36 49 64 81 100]
-}
-
-func ExampleQuery_SelectMany() {
-	input := [][]int{{1, 2, 3}, {4, 5, 6, 7}}
-
-	q := From(input).
-		SelectMany(
-			func(i interface{}) Query { return From(i) },
-		)
-
-	fmt.Println(q.Results())
-	// Output:
-	// [1 2 3 4 5 6 7]
-}
-
-// The following code example demonstrates how to use Select
-// to project over a slice of values and use the index of each element.
-func ExampleQuery_SelectIndexed() {
-	fruits := []string{"apple", "banana", "mango", "orange", "passionfruit", "grape"}
-
-	result := []string{}
-	From(fruits).
-		SelectIndexed(
-			func(index int, fruit interface{}) interface{} { return fruit.(string)[:index] },
-		).
-		ToSlice(&result)
-
-	fmt.Println(result)
-	// Output:
-	// [ b ma ora pass grape]
-
-}
-
-// The following code example demonstrates how to use SelectManyByIndexed
-// to perform a one-to-many projection over an array and use the index of each outer element.
-func ExampleQuery_SelectManyByIndexed() {
-	type Pet struct {
-		Name string
-	}
-
-	type Person struct {
-		Name string
-		Pets []Pet
-	}
-
-	magnus := Person{
-		Name: "Hedlund, Magnus",
-		Pets: []Pet{{Name: "Daisy"}},
-	}
-
-	terry := Person{
-		Name: "Adams, Terry",
-		Pets: []Pet{{Name: "Barley"}, {Name: "Boots"}},
-	}
-	charlotte := Person{
-		Name: "Weiss, Charlotte",
-		Pets: []Pet{{Name: "Whiskers"}},
-	}
-
-	people := []Person{magnus, terry, charlotte}
-	var results []string
-
-	From(people).
-		SelectManyByIndexed(
-			func(index int, person interface{}) Query {
-				return From(person.(Person).Pets).
-					Select(func(pet interface{}) interface{} {
-						return fmt.Sprintf("%d - %s", index, pet.(Pet).Name)
-					})
-			},
-			func(indexedPet, person interface{}) interface{} {
-				return fmt.Sprintf("Pet: %s, Owner: %s", indexedPet, person.(Person).Name)
-			},
-		).
-		ToSlice(&results)
-
-	for _, result := range results {
-		fmt.Println(result)
-	}
-	// Output:
-	// Pet: 0 - Daisy, Owner: Hedlund, Magnus
-	// Pet: 1 - Barley, Owner: Adams, Terry
-	// Pet: 1 - Boots, Owner: Adams, Terry
-	// Pet: 2 - Whiskers, Owner: Weiss, Charlotte
-
-}
-
-// The following code example demonstrates how to use SelectManyIndexed
-// to perform a one-to-many projection over an slice of log data and print out their contents.
-func ExampleQuery_SelectManyIndexed() {
-	type LogFile struct {
-		Name  string
-		Lines []string
-	}
-
-	file1 := LogFile{
-		Name: "file1.log",
-		Lines: []string{
-			"INFO: 2013/11/05 18:11:01 main.go:44: Special Information",
-			"WARNING: 2013/11/05 18:11:01 main.go:45: There is something you need to know about",
-			"ERROR: 2013/11/05 18:11:01 main.go:46: Something has failed",
-		},
-	}
-
-	file2 := LogFile{
-		Name: "file2.log",
-		Lines: []string{
-			"INFO: 2013/11/05 18:11:01 main.go:46: Everything is ok",
-		},
-	}
-
-	file3 := LogFile{
-		Name: "file3.log",
-		Lines: []string{
-			"2013/11/05 18:42:26 Hello World",
-		},
-	}
-
-	logFiles := []LogFile{file1, file2, file3}
-	var results []string
-
-	From(logFiles).
-		SelectManyIndexedT(func(fileIndex int, file LogFile) Query {
-			return From(file.Lines).
-				SelectIndexedT(func(lineIndex int, line string) string {
-					return fmt.Sprintf("File:[%d] - %s => line: %d - %s", fileIndex+1, file.Name, lineIndex+1, line)
-				})
-		}).
-		ToSlice(&results)
-
-	for _, result := range results {
-		fmt.Println(result)
-	}
-	// Output:
-	// File:[1] - file1.log => line: 1 - INFO: 2013/11/05 18:11:01 main.go:44: Special Information
-	// File:[1] - file1.log => line: 2 - WARNING: 2013/11/05 18:11:01 main.go:45: There is something you need to know about
-	// File:[1] - file1.log => line: 3 - ERROR: 2013/11/05 18:11:01 main.go:46: Something has failed
-	// File:[2] - file2.log => line: 1 - INFO: 2013/11/05 18:11:01 main.go:46: Everything is ok
-	// File:[3] - file3.log => line: 1 - 2013/11/05 18:42:26 Hello World
-
-}
-
-// The following code example demonstrates how to use SelectMany
-// to perform a one-to-many projection over a slice
-func ExampleQuery_SelectManyBy() {
-
-	type Pet struct {
-		Name string
-	}
-
-	type Person struct {
-		Name string
-		Pets []Pet
-	}
-
-	magnus := Person{
-		Name: "Hedlund, Magnus",
-		Pets: []Pet{{Name: "Daisy"}},
-	}
-
-	terry := Person{
-		Name: "Adams, Terry",
-		Pets: []Pet{{Name: "Barley"}, {Name: "Boots"}},
-	}
-	charlotte := Person{
-		Name: "Weiss, Charlotte",
-		Pets: []Pet{{Name: "Whiskers"}},
-	}
-
-	people := []Person{magnus, terry, charlotte}
-	var results []string
-	From(people).
-		SelectManyBy(
-			func(person interface{}) Query { return From(person.(Person).Pets) },
-			func(pet, person interface{}) interface{} {
-				return fmt.Sprintf("Owner: %s, Pet: %s", person.(Person).Name, pet.(Pet).Name)
-			},
-		).
-		ToSlice(&results)
-
-	for _, result := range results {
-		fmt.Println(result)
-	}
-	// Output:
-	// Owner: Hedlund, Magnus, Pet: Daisy
-	// Owner: Adams, Terry, Pet: Barley
-	// Owner: Adams, Terry, Pet: Boots
-	// Owner: Weiss, Charlotte, Pet: Whiskers
-}
-
-// The following code example demonstrates how to use SequenceEqual
-// to determine whether two slices are equal.
-func ExampleQuery_SequenceEqual() {
-	type Pet struct {
-		Name string
-		Age  int
-	}
-
-	pets1 := []Pet{
-		{Name: "Barley", Age: 8},
-		{Name: "Boots", Age: 4},
-		{Name: "Whiskers", Age: 1},
-		{Name: "Daisy", Age: 4},
-	}
-
-	pets2 := []Pet{
-		{Name: "Barley", Age: 8},
-		{Name: "Boots", Age: 4},
-		{Name: "Whiskers", Age: 1},
-		{Name: "Daisy", Age: 4},
-	}
-
-	equal := From(pets1).SequenceEqual(From(pets2))
-
-	fmt.Printf("Are the lists equals? %t", equal)
-	// Output:
-	// Are the lists equals? true
-}
-
-// The following code example demonstrates how to use Single
-// to select the only element of a slice.
-func ExampleQuery_Single() {
-	fruits1 := []string{"orange"}
-
-	fruit1 := From(fruits1).Single()
-
-	fmt.Println(fruit1)
-	// Output:
-	// orange
-}
-
-// The following code example demonstrates how to use SingleWith
-// to select the only element of a slice that satisfies a condition.
-func ExampleQuery_SingleWith() {
-	fruits := []string{"apple", "banana", "mango", "orange", "passionfruit", "grape"}
-
-	fruit := From(fruits).
-		SingleWith(
-			func(f interface{}) bool { return len(f.(string)) > 10 },
-		)
-
-	fmt.Println(fruit)
-	// Output:
-	// passionfruit
-}
-
-// The following code example demonstrates how to use Skip
-// to skip a specified number of elements in a sorted array
-// and return the remaining elements.
-func ExampleQuery_Skip() {
-	grades := []int{59, 82, 70, 56, 92, 98, 85}
-	var lowerGrades []int
-	From(grades).
-		OrderByDescending(
-			func(g interface{}) interface{} { return g },
-		).
-		Skip(3).
-		ToSlice(&lowerGrades)
-
-	//All grades except the top three are:
-	fmt.Println(lowerGrades)
-	// Output:
-	// [82 70 59 56]
-}
-
-// The following code example demonstrates how to use SkipWhile
-// to skip elements of an array as long as a condition is true.
-func ExampleQuery_SkipWhile() {
-	grades := []int{59, 82, 70, 56, 92, 98, 85}
-	var lowerGrades []int
-	From(grades).
-		OrderByDescending(
-			func(g interface{}) interface{} { return g },
-		).
-		SkipWhile(
-			func(g interface{}) bool { return g.(int) >= 80 },
-		).
-		ToSlice(&lowerGrades)
-
-	// All grades below 80:
-	fmt.Println(lowerGrades)
-	// Output:
-	// [70 59 56]
-}
-
-// The following code example demonstrates how to use SkipWhileIndexed
-// to skip elements of an array as long as a condition that depends
-// on the element's index is true.
-func ExampleQuery_SkipWhileIndexed() {
-	amounts := []int{5000, 2500, 9000, 8000, 6500, 4000, 1500, 5500}
-
-	var query []int
-	From(amounts).
-		SkipWhileIndexed(
-			func(index int, amount interface{}) bool { return amount.(int) > index*1000 },
-		).
-		ToSlice(&query)
-
-	fmt.Println(query)
-	// Output:
-	// [4000 1500 5500]
-
-}
-
-// The following code example demonstrates how to use Sort
-// to order elements of an slice.
-func ExampleQuery_Sort() {
-	amounts := []int{5000, 2500, 9000, 8000, 6500, 4000, 1500, 5500}
-
-	var query []int
-	From(amounts).
-		Sort(
-			func(i interface{}, j interface{}) bool { return i.(int) < j.(int) },
-		).
-		ToSlice(&query)
-
-	fmt.Println(query)
-	// Output:
-	// [1500 2500 4000 5000 5500 6500 8000 9000]
-
-}
-
-// The following code example demonstrates how to use SumFloats
-// to sum the values of a slice.
-func ExampleQuery_SumFloats() {
-	numbers := []float64{43.68, 1.25, 583.7, 6.5}
-
-	sum := From(numbers).SumFloats()
-
-	fmt.Printf("The sum of the numbers is %f.", sum)
-	// Output:
-	// The sum of the numbers is 635.130000.
-
-}
-
-// The following code example demonstrates how to use SumInts
-// to sum the values of a slice.
-func ExampleQuery_SumInts() {
-	numbers := []int{43, 1, 583, 6}
-
-	sum := From(numbers).SumInts()
-
-	fmt.Printf("The sum of the numbers is %d.", sum)
-	// Output:
-	// The sum of the numbers is 633.
-
-}
-
-// The following code example demonstrates how to use SumUInts
-// to sum the values of a slice.
-func ExampleQuery_SumUInts() {
-	numbers := []uint{43, 1, 583, 6}
-
-	sum := From(numbers).SumUInts()
-
-	fmt.Printf("The sum of the numbers is %d.", sum)
-	// Output:
-	// The sum of the numbers is 633.
-
-}
-
-// The following code example demonstrates how to use Take
-//  to return elements from the start of a slice.
-func ExampleQuery_Take() {
-	grades := []int{59, 82, 70, 56, 92, 98, 85}
-
-	var topThreeGrades []int
-	From(grades).
-		OrderByDescending(
-			func(grade interface{}) interface{} { return grade },
-		).
-		Take(3).
-		ToSlice(&topThreeGrades)
-
-	fmt.Printf("The top three grades are: %v", topThreeGrades)
-	// Output:
-	// The top three grades are: [98 92 85]
-}
-
-// The following code example demonstrates how to use TakeWhile
-// to return elements from the start of a slice.
-func ExampleQuery_TakeWhile() {
-	fruits := []string{"apple", "banana", "mango", "orange", "passionfruit", "grape"}
-
-	var query []string
-	From(fruits).
-		TakeWhile(
-			func(fruit interface{}) bool { return fruit.(string) != "orange" },
-		).
-		ToSlice(&query)
-
-	fmt.Println(query)
-	// Output:
-	// [apple banana mango]
-}
-
-// The following code example demonstrates how to use TakeWhileIndexed
-// to return elements from the start of a slice as long as
-// a condition that uses the element's index is true.
-func ExampleQuery_TakeWhileIndexed() {
-
-	fruits := []string{"apple", "passionfruit", "banana", "mango",
-		"orange", "blueberry", "grape", "strawberry"}
-
-	var query []string
-	From(fruits).
-		TakeWhileIndexed(
-			func(index int, fruit interface{}) bool { return len(fruit.(string)) >= index },
-		).
-		ToSlice(&query)
-
-	fmt.Println(query)
-	// Output:
-	// [apple passionfruit banana mango orange blueberry]
-}
-
-// The following code example demonstrates how to use ToChannel
-// to send a slice to a channel.
-func ExampleQuery_ToChannel() {
-	c := make(chan interface{})
-
-	go func() {
-		Repeat(10, 3).ToChannel(c)
-	}()
-
-	for i := range c {
-		fmt.Println(i)
-	}
-	// Output:
-	// 10
-	// 10
-	// 10
-}
-
-// The following code example demonstrates how to use ToChannelT
-// to send a slice to a typed channel.
-func ExampleQuery_ToChannelT() {
-	c := make(chan string)
-
-	go Repeat("ten", 3).ToChannelT(c)
-
-	for i := range c {
-		fmt.Println(i)
-	}
-	// Output:
-	// ten
-	// ten
-	// ten
-}
-
-// The following code example demonstrates how to use ToMap to populate a map.
-func ExampleQuery_ToMap() {
-	type Product struct {
-		Name string
-		Code int
-	}
-
-	products := []Product{
-		{Name: "orange", Code: 4},
-		{Name: "apple", Code: 9},
-		{Name: "lemon", Code: 12},
-		{Name: "apple", Code: 9},
-	}
-
-	map1 := map[int]string{}
-	From(products).
-		SelectT(
-			func(item Product) KeyValue { return KeyValue{Key: item.Code, Value: item.Name} },
-		).
-		ToMap(&map1)
-
-	fmt.Println(map1[4])
-	fmt.Println(map1[9])
-	fmt.Println(map1[12])
-	// Output:
-	// orange
-	// apple
-	// lemon
-}
-
-// The following code example demonstrates how to use ToMapBy
-// by using a key and value selectors to populate a map.
-func ExampleQuery_ToMapBy() {
-	input := [][]interface{}{{1, true}}
-
-	result := make(map[int]bool)
-	From(input).
-		ToMapBy(&result,
-			func(i interface{}) interface{} {
-				return i.([]interface{})[0]
-			},
-			func(i interface{}) interface{} {
-				return i.([]interface{})[1]
-			},
-		)
-
-	fmt.Println(result)
-	// Output:
-	// map[1:true]
-}
-
-// The following code example demonstrates how to use ToSlice to populate a slice.
-func ExampleQuery_ToSlice() {
-	var result []int
-	Range(1, 10).ToSlice(&result)
-
-	fmt.Println(result)
-	// Output:
-	// [1 2 3 4 5 6 7 8 9 10]
-}
-
-// The following code example demonstrates how to use Union
-// to obtain the union of two slices of integers.
-func ExampleQuery_Union() {
-	q := Range(1, 10).Union(Range(6, 10))
-
-	fmt.Println(q.Results())
-	// Output:
-	// [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
-}
-
-// The following code example demonstrates how to use Where
-// to filter a slices.
-func ExampleQuery_Where() {
-	fruits := []string{"apple", "passionfruit", "banana", "mango",
-		"orange", "blueberry", "grape", "strawberry"}
-	var query []string
-	From(fruits).
-		Where(
-			func(f interface{}) bool { return len(f.(string)) > 6 },
-		).
-		ToSlice(&query)
-
-	fmt.Println(query)
-	// Output:
-	// [passionfruit blueberry strawberry]
-}
-
-// The following code example demonstrates how to use WhereIndexed
-// to filter a slice based on a predicate that involves the index of each element.
-func ExampleQuery_WhereIndexed() {
-	numbers := []int{0, 30, 20, 15, 90, 85, 40, 75}
-
-	var query []int
-	From(numbers).
-		WhereIndexed(
-			func(index int, number interface{}) bool { return number.(int) <= index*10 },
-		).
-		ToSlice(&query)
-
-	fmt.Println(query)
-	// Output:
-	// [0 20 15 40]
-}
-
-// The following code example demonstrates how to use the Zip
-// method to merge two slices.
-func ExampleQuery_Zip() {
-	number := []int{1, 2, 3, 4, 5}
-	words := []string{"one", "two", "three"}
-
-	q := From(number).
-		Zip(From(words),
-			func(a interface{}, b interface{}) interface{} { return []interface{}{a, b} },
-		)
-
-	fmt.Println(q.Results())
-	// Output:
-	// [[1 one] [2 two] [3 three]]
-}
-
-// The following code example demonstrates how to use ThenByDescendingT to perform
-// a order in a slice of dates by year, and then by month descending.
-func ExampleOrderedQuery_ThenByDescendingT() {
-	dates := []time.Time{
-		time.Date(2015, 3, 23, 0, 0, 0, 0, time.Local),
-		time.Date(2014, 7, 11, 0, 0, 0, 0, time.Local),
-		time.Date(2013, 5, 4, 0, 0, 0, 0, time.Local),
-		time.Date(2015, 1, 2, 0, 0, 0, 0, time.Local),
-		time.Date(2015, 7, 10, 0, 0, 0, 0, time.Local),
-	}
-
-	var orderedDates []time.Time
-	From(dates).
-		OrderByT(
-			func(date time.Time) int {
-				return date.Year()
-			}).
-		ThenByDescendingT(
-			func(date time.Time) int { return int(date.Month()) },
-		).
-		ToSlice(&orderedDates)
-
-	for _, date := range orderedDates {
-		fmt.Println(date.Format("2006-Jan-02"))
-	}
-	// Output:
-	// 2013-May-04
-	// 2014-Jul-11
-	// 2015-Jul-10
-	// 2015-Mar-23
-	// 2015-Jan-02
-
-}
-
-// The following code example demonstrates how to use ThenByT to perform
-// a orders in a slice of dates by year, and then by day.
-func ExampleOrderedQuery_ThenByT() {
-	dates := []time.Time{
-		time.Date(2015, 3, 23, 0, 0, 0, 0, time.Local),
-		time.Date(2014, 7, 11, 0, 0, 0, 0, time.Local),
-		time.Date(2013, 5, 4, 0, 0, 0, 0, time.Local),
-		time.Date(2015, 1, 2, 0, 0, 0, 0, time.Local),
-		time.Date(2015, 7, 10, 0, 0, 0, 0, time.Local),
-	}
-
-	var orderedDates []time.Time
-	From(dates).
-		OrderByT(
-			func(date time.Time) int { return date.Year() },
-		).
-		ThenByT(
-			func(date time.Time) int { return int(date.Day()) },
-		).
-		ToSlice(&orderedDates)
-
-	for _, date := range orderedDates {
-		fmt.Println(date.Format("2006-Jan-02"))
-	}
-	// Output:
-	// 2013-May-04
-	// 2014-Jul-11
-	// 2015-Jan-02
-	// 2015-Jul-10
-	// 2015-Mar-23
-
-}
-
-// The following code example demonstrates how to reverse
-// the order of words in a string using AggregateT.
-func ExampleQuery_AggregateT() {
-	sentence := "the quick brown fox jumps over the lazy dog"
-	// Split the string into individual words.
-	words := strings.Split(sentence, " ")
-
-	// Prepend each word to the beginning of the
-	// new sentence to reverse the word order.
-	reversed := From(words).AggregateT(
-		func(workingSentence string, next string) string { return next + " " + workingSentence },
-	)
-
-	fmt.Println(reversed)
-	// Output:
-	// dog lazy the over jumps fox brown quick the
-}
-
-// The following code example demonstrates how to use AggregateWithSeed function
-func ExampleQuery_AggregateWithSeedT() {
-
-	fruits := []string{"apple", "mango", "orange", "passionfruit", "grape"}
-
-	// Determine whether any string in the array is longer than "banana".
-	longestName := From(fruits).
-		AggregateWithSeedT("banana",
-			func(longest, next string) string {
-				if len(next) > len(longest) {
-					return next
-				}
-				return longest
-			},
-		)
-
-	fmt.Printf("The fruit with the longest name is %s.", longestName)
-	// Output:
-	// The fruit with the longest name is passionfruit.
-
-}
-
-// The following code example demonstrates how to use AggregateWithSeedByT function
-func ExampleQuery_AggregateWithSeedByT() {
-	input := []string{"apple", "mango", "orange", "passionfruit", "grape"}
-
-	// Determine whether any string in the array is longer than "banana".
-	longestName := From(input).AggregateWithSeedByT("banana",
-		func(longest string, next string) string {
-			if len(longest) > len(next) {
-				return longest
-			}
-			return next
-
-		},
-		// Return the final result
-		func(result string) string {
-			return fmt.Sprintf("The fruit with the longest name is %s.", result)
-		},
-	)
-
-	fmt.Println(longestName)
-	// Output:
-	// The fruit with the longest name is passionfruit.
-}
-
-// The following code example demonstrates how to use AllT
-// to get the students having all marks greater than 70.
-func ExampleQuery_AllT() {
-
-	type Student struct {
-		Name  string
-		Marks []int
-	}
-
-	students := []Student{
-		{Name: "Hugo", Marks: []int{91, 88, 76, 93}},
-		{Name: "Rick", Marks: []int{70, 73, 66, 90}},
-		{Name: "Michael", Marks: []int{73, 80, 75, 88}},
-		{Name: "Fadi", Marks: []int{82, 75, 66, 84}},
-		{Name: "Peter", Marks: []int{67, 78, 70, 82}},
-	}
-
-	var approvedStudents []Student
-	From(students).
-		WhereT(
-			func(student Student) bool {
-				return From(student.Marks).
-					AllT(
-						func(mark int) bool { return mark > 70 },
-					)
-			},
-		).
-		ToSlice(&approvedStudents)
-
-	//List of approved students
-	for _, student := range approvedStudents {
-		fmt.Println(student.Name)
-	}
-	// Output:
-	// Hugo
-	// Michael
-}
-
-// The following code example demonstrates how to use AnyWithT
-// to get the students with any mark lower than 70.
-func ExampleQuery_AnyWithT() {
-	type Student struct {
-		Name  string
-		Marks []int
-	}
-
-	students := []Student{
-		{Name: "Hugo", Marks: []int{91, 88, 76, 93}},
-		{Name: "Rick", Marks: []int{70, 73, 66, 90}},
-		{Name: "Michael", Marks: []int{73, 80, 75, 88}},
-		{Name: "Fadi", Marks: []int{82, 75, 66, 84}},
-		{Name: "Peter", Marks: []int{67, 78, 70, 82}},
-	}
-
-	var studentsWithAnyMarkLt70 []Student
-	From(students).
-		WhereT(
-			func(student Student) bool {
-				return From(student.Marks).
-					AnyWithT(
-						func(mark int) bool { return mark < 70 },
-					)
-			},
-		).
-		ToSlice(&studentsWithAnyMarkLt70)
-
-	//List of students with any mark lower than 70
-	for _, student := range studentsWithAnyMarkLt70 {
-		fmt.Println(student.Name)
-	}
-	// Output:
-	// Rick
-	// Fadi
-	// Peter
-
-}
-
-// The following code example demonstrates how to use CountWithT
-// to count the elements in an slice that satisfy a condition.
-func ExampleQuery_CountWithT() {
-	type Pet struct {
-		Name       string
-		Vaccinated bool
-	}
-
-	pets := []Pet{
-		{Name: "Barley", Vaccinated: true},
-		{Name: "Boots", Vaccinated: false},
-		{Name: "Whiskers", Vaccinated: false},
-	}
-
-	numberUnvaccinated := From(pets).
-		CountWithT(
-			func(p Pet) bool { return p.Vaccinated == false },
-		)
-
-	fmt.Printf("There are %d unvaccinated animals.", numberUnvaccinated)
-
-	//Output:
-	//There are 2 unvaccinated animals.
-}
-
-// The following code example demonstrates how to use DistinctByT
-// to return distinct elements from a slice of structs.
-func ExampleQuery_DistinctByT() {
-	type Product struct {
-		Name string
-		Code int
-	}
-
-	products := []Product{
-		{Name: "apple", Code: 9},
-		{Name: "orange", Code: 4},
-		{Name: "apple", Code: 9},
-		{Name: "lemon", Code: 12},
-	}
-
-	//Exclude duplicates.
-	var noduplicates []Product
-	From(products).
-		DistinctByT(
-			func(item Product) int { return item.Code },
-		).
-		ToSlice(&noduplicates)
-
-	for _, product := range noduplicates {
-		fmt.Printf("%s %d\n", product.Name, product.Code)
-	}
-	// Output:
-	// apple 9
-	// orange 4
-	// lemon 12
-}
-
-// The following code example demonstrates how to use ExceptByT
-func ExampleQuery_ExceptByT() {
-	type Product struct {
-		Name string
-		Code int
-	}
-
-	fruits1 := []Product{
-		{Name: "orange", Code: 4},
-		{Name: "apple", Code: 9},
-		{Name: "lemon", Code: 12},
-		{Name: "apple", Code: 9},
-	}
-
-	fruits2 := []Product{
-		{Name: "apple", Code: 9},
-	}
-
-	//Order and exclude duplicates.
-	var except []Product
-	From(fruits1).
-		ExceptByT(From(fruits2),
-			func(item Product) int { return item.Code },
-		).
-		ToSlice(&except)
-
-	for _, product := range except {
-		fmt.Printf("%s %d\n", product.Name, product.Code)
-	}
-	// Output:
-	// orange 4
-	// lemon 12
-
-}
-
-// The following code example demonstrates how to use FirstWithT
-// to return the first element of an array that satisfies a condition.
-func ExampleQuery_FirstWithT() {
-	numbers := []int{9, 34, 65, 92, 87, 435, 3, 54, 83, 23, 87, 435, 67, 12, 19}
-
-	first := From(numbers).
-		FirstWithT(
-			func(item int) bool { return item > 80 },
-		)
-
-	fmt.Println(first)
-	// Output:
-	// 92
-
-}
-
-// The following code example demonstrates how to use ForEach
-// to output all elements of an array.
-func ExampleQuery_ForEach() {
-	fruits := []string{"orange", "apple", "lemon", "apple"}
-
-	From(fruits).ForEach(func(fruit interface{}) {
-		fmt.Println(fruit)
-	})
-	// Output:
-	// orange
-	// apple
-	// lemon
-	// apple
-}
-
-// The following code example demonstrates how to use ForEachIndexed
-// to output all elements of an array with its index.
-func ExampleQuery_ForEachIndexed() {
-	fruits := []string{"orange", "apple", "lemon", "apple"}
-
-	From(fruits).ForEachIndexed(func(i int, fruit interface{}) {
-		fmt.Printf("%d.%s\n", i, fruit)
-	})
-	// Output:
-	// 0.orange
-	// 1.apple
-	// 2.lemon
-	// 3.apple
-}
-
-// The following code example demonstrates how to use ForEachT
-// to output all elements of an array.
-func ExampleQuery_ForEachT() {
-	fruits := []string{"orange", "apple", "lemon", "apple"}
-
-	From(fruits).ForEachT(func(fruit string) {
-		fmt.Println(fruit)
-	})
-	// Output:
-	// orange
-	// apple
-	// lemon
-	// apple
-}
-
-// The following code example demonstrates how to use ForEachIndexedT
-// to output all elements of an array with its index.
-func ExampleQuery_ForEachIndexedT() {
-	fruits := []string{"orange", "apple", "lemon", "apple"}
-
-	From(fruits).ForEachIndexedT(func(i int, fruit string) {
-		fmt.Printf("%d.%s\n", i, fruit)
-	})
-	// Output:
-	// 0.orange
-	// 1.apple
-	// 2.lemon
-	// 3.apple
-}
-
-// The following code example demonstrates how to use GroupByT
-// to group the elements of a slice.
-func ExampleQuery_GroupByT() {
-
-	type Pet struct {
-		Name string
-		Age  int
-	}
-	// Create a list of pets.
-	pets := []Pet{
-		{Name: "Barley", Age: 8},
-		{Name: "Boots", Age: 4},
-		{Name: "Whiskers", Age: 1},
-		{Name: "Daisy", Age: 4},
-	}
-
-	// Group the pets using Age as the key value
-	// and selecting only the pet's Name for each value.
-	var query []Group
-	From(pets).GroupByT(
-		func(p Pet) int { return p.Age },
-		func(p Pet) string { return p.Name },
-	).OrderByT(
-		func(g Group) int { return g.Key.(int) },
-	).ToSlice(&query)
-
-	for _, petGroup := range query {
-		fmt.Printf("%d\n", petGroup.Key)
-		for _, petName := range petGroup.Group {
-			fmt.Printf("  %s\n", petName)
-		}
-
-	}
-	// Output:
-	// 1
-	//   Whiskers
-	// 4
-	//   Boots
-	//   Daisy
-	// 8
-	//   Barley
-}
-
-// The following code example demonstrates how to use GroupJoinT
-//  to perform a grouped join on two slices.
-func ExampleQuery_GroupJoinT() {
-
-	type Person struct {
-		Name string
-	}
-
-	type Pet struct {
-		Name  string
-		Owner Person
-	}
-
-	magnus := Person{Name: "Hedlund, Magnus"}
-	terry := Person{Name: "Adams, Terry"}
-	charlotte := Person{Name: "Weiss, Charlotte"}
-
-	barley := Pet{Name: "Barley", Owner: terry}
-	boots := Pet{Name: "Boots", Owner: terry}
-	whiskers := Pet{Name: "Whiskers", Owner: charlotte}
-	daisy := Pet{Name: "Daisy", Owner: magnus}
-
-	people := []Person{magnus, terry, charlotte}
-	pets := []Pet{barley, boots, whiskers, daisy}
-
-	// Create a slice where each element is a KeyValue
-	// that contains a person's name as the key and a slice of strings
-	// of names of the pets they own as a value.
-
-	q := []KeyValue{}
-	From(people).
-		GroupJoinT(From(pets),
-			func(p Person) Person { return p },
-			func(p Pet) Person { return p.Owner },
-			func(person Person, pets []Pet) KeyValue {
-				var petNames []string
-				From(pets).
-					SelectT(
-						func(pet Pet) string { return pet.Name },
-					).
-					ToSlice(&petNames)
-				return KeyValue{person.Name, petNames}
-			},
-		).ToSlice(&q)
-
-	for _, obj := range q {
-		// Output the owner's name.
-		fmt.Printf("%s:\n", obj.Key)
-		// Output each of the owner's pet's names.
-		for _, petName := range obj.Value.([]string) {
-			fmt.Printf("  %s\n", petName)
-		}
-	}
-	// Output:
-	// Hedlund, Magnus:
-	//   Daisy
-	// Adams, Terry:
-	//   Barley
-	//   Boots
-	// Weiss, Charlotte:
-	//   Whiskers
-}
-
-// The following code example demonstrates how to use IntersectByT
-// to return the elements that appear in each of two slices of products
-// with same Code.
-func ExampleQuery_IntersectByT() {
-	type Product struct {
-		Name string
-		Code int
-	}
-
-	store1 := []Product{
-		{Name: "orange", Code: 4},
-		{Name: "apple", Code: 9},
-	}
-
-	store2 := []Product{
-		{Name: "lemon", Code: 12},
-		{Name: "apple", Code: 9},
-	}
-
-	var duplicates []Product
-	From(store1).
-		IntersectByT(From(store2),
-			func(p Product) int { return p.Code },
-		).
-		ToSlice(&duplicates)
-
-	for _, p := range duplicates {
-		fmt.Println(p.Name, "", p.Code)
-	}
-	// Output:
-	// apple  9
-
-}
-
-// The following code example demonstrates how to use JoinT
-// to perform an inner join of two slices based on a common key.
-func ExampleQuery_JoinT() {
-	type Person struct {
-		Name string
-	}
-
-	type Pet struct {
-		Name  string
-		Owner Person
-	}
-
-	magnus := Person{Name: "Hedlund, Magnus"}
-	terry := Person{Name: "Adams, Terry"}
-	charlotte := Person{Name: "Weiss, Charlotte"}
-
-	barley := Pet{Name: "Barley", Owner: terry}
-	boots := Pet{Name: "Boots", Owner: terry}
-	whiskers := Pet{Name: "Whiskers", Owner: charlotte}
-	daisy := Pet{Name: "Daisy", Owner: magnus}
-
-	people := []Person{magnus, terry, charlotte}
-	pets := []Pet{barley, boots, whiskers, daisy}
-
-	// Create a list of Person-Pet pairs where
-	// each element is an anonymous type that contains a
-	// Pet's name and the name of the Person that owns the Pet.
-
-	query := []string{}
-	From(people).
-		JoinT(From(pets),
-			func(person Person) Person { return person },
-			func(pet Pet) Person { return pet.Owner },
-			func(person Person, pet Pet) string { return fmt.Sprintf("%s - %s", person.Name, pet.Name) },
-		).ToSlice(&query)
-
-	for _, line := range query {
-		fmt.Println(line)
-	}
-	//Output:
-	//Hedlund, Magnus - Daisy
-	//Adams, Terry - Barley
-	//Adams, Terry - Boots
-	//Weiss, Charlotte - Whiskers
-}
-
-// The following code example demonstrates how to use LastWithT
-// to return the last element of an array.
-func ExampleQuery_LastWithT() {
-	numbers := []int{9, 34, 65, 92, 87, 435, 3, 54,
-		83, 23, 87, 67, 12, 19}
-
-	last := From(numbers).
-		LastWithT(
-			func(n int) bool { return n > 80 },
-		)
-
-	fmt.Println(last)
-
-	//Output:
-	//87
-
-}
-
-// The following code example demonstrates how to use OrderByDescendingT
-// to order an slice.
-func ExampleQuery_OrderByDescendingT() {
-	type Player struct {
-		Name   string
-		Points int64
-	}
-
-	players := []Player{
-		{Name: "Hugo", Points: 4757},
-		{Name: "Rick", Points: 7365},
-		{Name: "Michael", Points: 2857},
-		{Name: "Fadi", Points: 85897},
-		{Name: "Peter", Points: 48576},
-	}
-
-	//Order and get the top 3 players
-	var top3Players []KeyValue
-	From(players).
-		OrderByDescendingT(
-			func(p Player) int64 { return p.Points },
-		).
-		Take(3).
-		SelectIndexedT(
-			func(i int, p Player) KeyValue { return KeyValue{Key: i + 1, Value: p} },
-		).
-		ToSlice(&top3Players)
-
-	for _, rank := range top3Players {
-		fmt.Printf(
-			"Rank: #%d - Player: %s - Points: %d\n",
-			rank.Key,
-			rank.Value.(Player).Name,
-			rank.Value.(Player).Points,
-		)
-
-	}
-	// Output:
-	// Rank: #1 - Player: Fadi - Points: 85897
-	// Rank: #2 - Player: Peter - Points: 48576
-	// Rank: #3 - Player: Rick - Points: 7365
-}
-
-// The following code example demonstrates how to use OrderByT
-// to sort the elements of a slice.
-func ExampleQuery_OrderByT() {
-	type Pet struct {
-		Name string
-		Age  int
-	}
-	// Create a list of pets.
-	pets := []Pet{
-		{Name: "Barley", Age: 8},
-		{Name: "Boots", Age: 4},
-		{Name: "Whiskers", Age: 1},
-		{Name: "Daisy", Age: 4},
-	}
-
-	var orderedPets []Pet
-	From(pets).
-		OrderByT(
-			func(pet Pet) int { return pet.Age },
-		).
-		ToSlice(&orderedPets)
-
-	for _, pet := range orderedPets {
-		fmt.Println(pet.Name, "-", pet.Age)
-	}
-	// Output:
-	// Whiskers - 1
-	// Boots - 4
-	// Daisy - 4
-	// Barley - 8
-}
-
-// The following code example demonstrates how to use SelectT
-// to project over a slice.
-func ExampleQuery_SelectT() {
-	squares := []int{}
-
-	Range(1, 10).
-		SelectT(
-			func(x int) int { return x * x },
-		).
-		ToSlice(&squares)
-
-	fmt.Println(squares)
-	// Output:
-	// [1 4 9 16 25 36 49 64 81 100]
-}
-
-// The following code example demonstrates how to use SelectIndexedT
-// to determine if the value in a slice of int match their position
-// in the slice.
-func ExampleQuery_SelectIndexedT() {
-	numbers := []int{5, 4, 1, 3, 9, 8, 6, 7, 2, 0}
-
-	var numsInPlace []KeyValue
-
-	From(numbers).
-		SelectIndexedT(
-			func(index, num int) KeyValue { return KeyValue{Key: num, Value: num == index} },
-		).
-		ToSlice(&numsInPlace)
-
-	fmt.Println("Number: In-place?")
-	for _, n := range numsInPlace {
-		fmt.Printf("%d: %t\n", n.Key, n.Value)
-	}
-	// Output:
-	// Number: In-place?
-	// 5: false
-	// 4: false
-	// 1: false
-	// 3: true
-	// 9: false
-	// 8: false
-	// 6: true
-	// 7: true
-	// 2: false
-	// 0: false
-
-}
-
-// The following code example demonstrates how to use SelectManyT
-// to perform a one-to-many projection over a slice
-func ExampleQuery_SelectManyByT() {
-
-	type Pet struct {
-		Name string
-	}
-
-	type Person struct {
-		Name string
-		Pets []Pet
-	}
-
-	magnus := Person{
-		Name: "Hedlund, Magnus",
-		Pets: []Pet{{Name: "Daisy"}},
-	}
-
-	terry := Person{
-		Name: "Adams, Terry",
-		Pets: []Pet{{Name: "Barley"}, {Name: "Boots"}},
-	}
-	charlotte := Person{
-		Name: "Weiss, Charlotte",
-		Pets: []Pet{{Name: "Whiskers"}},
-	}
-
-	people := []Person{magnus, terry, charlotte}
-	var results []string
-	From(people).
-		SelectManyByT(
-			func(person Person) Query { return From(person.Pets) },
-			func(pet Pet, person Person) interface{} {
-				return fmt.Sprintf("Owner: %s, Pet: %s", person.Name, pet.Name)
-			},
-		).
-		ToSlice(&results)
-
-	for _, result := range results {
-		fmt.Println(result)
-	}
-	// Output:
-	// Owner: Hedlund, Magnus, Pet: Daisy
-	// Owner: Adams, Terry, Pet: Barley
-	// Owner: Adams, Terry, Pet: Boots
-	// Owner: Weiss, Charlotte, Pet: Whiskers
-}
-
-// The following code example demonstrates how to use SelectManyT
-// to perform a projection over a list of sentences and rank the
-// top 5 most used words
-func ExampleQuery_SelectManyT() {
-	sentences := []string{
-		"the quick brown fox jumps over the lazy dog",
-		"pack my box with five dozen liquor jugs",
-		"several fabulous dixieland jazz groups played with quick tempo",
-		"back in my quaint garden jaunty zinnias vie with flaunting phlox",
-		"five or six big jet planes zoomed quickly by the new tower",
-		"I quickly explained that many big jobs involve few hazards",
-		"The wizard quickly jinxed the gnomes before they vaporized",
-	}
-
-	var results []string
-	From(sentences).
-		//Split the sentences in words
-		SelectManyT(func(sentence string) Query {
-			return From(strings.Split(sentence, " "))
-		}).
-		//Grouping by word
-		GroupByT(
-			func(word string) string { return word },
-			func(word string) string { return word },
-		).
-		//Ordering by word counts
-		OrderByDescendingT(func(wordGroup Group) int {
-			return len(wordGroup.Group)
-		}).
-		//Then order by word
-		ThenByT(func(wordGroup Group) string {
-			return wordGroup.Key.(string)
-		}).
-		//Take the top 5
-		Take(5).
-		//Project the words using the index as rank
-		SelectIndexedT(func(index int, wordGroup Group) string {
-			return fmt.Sprintf("Rank: #%d, Word: %s, Counts: %d", index+1, wordGroup.Key, len(wordGroup.Group))
-		}).
-		ToSlice(&results)
-
-	for _, result := range results {
-		fmt.Println(result)
-	}
-	// Output:
-	// Rank: #1, Word: the, Counts: 4
-	// Rank: #2, Word: quickly, Counts: 3
-	// Rank: #3, Word: with, Counts: 3
-	// Rank: #4, Word: big, Counts: 2
-	// Rank: #5, Word: five, Counts: 2
-}
-
-// The following code example demonstrates how to use SelectManyIndexedT
-// to perform a one-to-many projection over an slice of log files and
-// print out their contents.
-func ExampleQuery_SelectManyIndexedT() {
-	type LogFile struct {
-		Name  string
-		Lines []string
-	}
-
-	file1 := LogFile{
-		Name: "file1.log",
-		Lines: []string{
-			"INFO: 2013/11/05 18:11:01 main.go:44: Special Information",
-			"WARNING: 2013/11/05 18:11:01 main.go:45: There is something you need to know about",
-			"ERROR: 2013/11/05 18:11:01 main.go:46: Something has failed",
-		},
-	}
-
-	file2 := LogFile{
-		Name: "file2.log",
-		Lines: []string{
-			"INFO: 2013/11/05 18:11:01 main.go:46: Everything is ok",
-		},
-	}
-
-	file3 := LogFile{
-		Name: "file3.log",
-		Lines: []string{
-			"2013/11/05 18:42:26 Hello World",
-		},
-	}
-
-	logFiles := []LogFile{file1, file2, file3}
-	var results []string
-
-	From(logFiles).
-		SelectManyIndexedT(func(fileIndex int, file LogFile) Query {
-			return From(file.Lines).
-				SelectIndexedT(func(lineIndex int, line string) string {
-					return fmt.Sprintf("File:[%d] - %s => line: %d - %s", fileIndex+1, file.Name, lineIndex+1, line)
-				})
-		}).
-		ToSlice(&results)
-
-	for _, result := range results {
-		fmt.Println(result)
-	}
-	// Output:
-	// File:[1] - file1.log => line: 1 - INFO: 2013/11/05 18:11:01 main.go:44: Special Information
-	// File:[1] - file1.log => line: 2 - WARNING: 2013/11/05 18:11:01 main.go:45: There is something you need to know about
-	// File:[1] - file1.log => line: 3 - ERROR: 2013/11/05 18:11:01 main.go:46: Something has failed
-	// File:[2] - file2.log => line: 1 - INFO: 2013/11/05 18:11:01 main.go:46: Everything is ok
-	// File:[3] - file3.log => line: 1 - 2013/11/05 18:42:26 Hello World
-
-}
-
-// The following code example demonstrates how to use SelectManyByIndexedT
-// to perform a one-to-many projection over an array and use the index of
-// each outer element.
-func ExampleQuery_SelectManyByIndexedT() {
-	type Pet struct {
-		Name string
-	}
-
-	type Person struct {
-		Name string
-		Pets []Pet
-	}
-
-	magnus := Person{
-		Name: "Hedlund, Magnus",
-		Pets: []Pet{{Name: "Daisy"}},
-	}
-
-	terry := Person{
-		Name: "Adams, Terry",
-		Pets: []Pet{{Name: "Barley"}, {Name: "Boots"}},
-	}
-	charlotte := Person{
-		Name: "Weiss, Charlotte",
-		Pets: []Pet{{Name: "Whiskers"}},
-	}
-
-	people := []Person{magnus, terry, charlotte}
-	var results []string
-
-	From(people).
-		SelectManyByIndexedT(
-			func(index int, person Person) Query {
-				return From(person.Pets).
-					SelectT(func(pet Pet) string {
-						return fmt.Sprintf("%d - %s", index, pet.Name)
-					})
-			},
-			func(indexedPet string, person Person) string {
-				return fmt.Sprintf("Pet: %s, Owner: %s", indexedPet, person.Name)
-			},
-		).
-		ToSlice(&results)
-
-	for _, result := range results {
-		fmt.Println(result)
-	}
-	// Output:
-	// Pet: 0 - Daisy, Owner: Hedlund, Magnus
-	// Pet: 1 - Barley, Owner: Adams, Terry
-	// Pet: 1 - Boots, Owner: Adams, Terry
-	// Pet: 2 - Whiskers, Owner: Weiss, Charlotte
-
-}
-
-//The following code example demonstrates how to use SingleWithT
-// to select the only element of a slice that satisfies a condition.
-func ExampleQuery_SingleWithT() {
-	fruits := []string{"apple", "banana", "mango", "orange", "passionfruit", "grape"}
-
-	fruit := From(fruits).
-		SingleWithT(
-			func(f string) bool { return len(f) > 10 },
-		)
-
-	fmt.Println(fruit)
-	// Output:
-	// passionfruit
-}
-
-// The following code example demonstrates how to use SkipWhileT
-// to skip elements of an array as long as a condition is true.
-func ExampleQuery_SkipWhileT() {
-	grades := []int{59, 82, 70, 56, 92, 98, 85}
-	var lowerGrades []int
-	From(grades).
-		OrderByDescendingT(
-			func(g int) int { return g },
-		).
-		SkipWhileT(
-			func(g int) bool { return g >= 80 },
-		).
-		ToSlice(&lowerGrades)
-
-	//"All grades below 80:
-	fmt.Println(lowerGrades)
-	// Output:
-	// [70 59 56]
-}
-
-// The following code example demonstrates how to use SkipWhileIndexedT
-// to skip elements of an array as long as a condition that depends
-// on the element's index is true.
-func ExampleQuery_SkipWhileIndexedT() {
-	amounts := []int{5000, 2500, 9000, 8000, 6500, 4000, 1500, 5500}
-
-	var query []int
-	From(amounts).
-		SkipWhileIndexedT(
-			func(index int, amount int) bool { return amount > index*1000 },
-		).
-		ToSlice(&query)
-
-	fmt.Println(query)
-	// Output:
-	// [4000 1500 5500]
-
-}
-
-// The following code example demonstrates how to use SortT
-// to order elements of an slice.
-func ExampleQuery_SortT() {
-	type Pet struct {
-		Name string
-		Age  int
-	}
-	// Create a list of pets.
-	pets := []Pet{
-		{Name: "Barley", Age: 8},
-		{Name: "Boots", Age: 4},
-		{Name: "Whiskers", Age: 1},
-		{Name: "Daisy", Age: 4},
-	}
-
-	orderedPets := []Pet{}
-	From(pets).
-		SortT(
-			func(pet1 Pet, pet2 Pet) bool { return pet1.Age < pet2.Age },
-		).
-		ToSlice(&orderedPets)
-
-	for _, pet := range orderedPets {
-		fmt.Println(pet.Name, "-", pet.Age)
-	}
-	// Output:
-	// Whiskers - 1
-	// Boots - 4
-	// Daisy - 4
-	// Barley - 8
-
-}
-
-// The following code example demonstrates how to use TakeWhileT
-// to return elements from the start of a slice.
-func ExampleQuery_TakeWhileT() {
-	fruits := []string{"apple", "banana", "mango", "orange", "passionfruit", "grape"}
-
-	var query []string
-	From(fruits).
-		TakeWhileT(
-			func(fruit string) bool { return fruit != "orange" },
-		).
-		ToSlice(&query)
-
-	fmt.Println(query)
-	// Output:
-	// [apple banana mango]
-}
-
-// The following code example demonstrates how to use TakeWhileIndexedT
-// to return elements from the start of a slice as long asa condition
-// that uses the element's index is true.
-func ExampleQuery_TakeWhileIndexedT() {
-
-	fruits := []string{"apple", "passionfruit", "banana", "mango",
-		"orange", "blueberry", "grape", "strawberry"}
-
-	var query []string
-	From(fruits).
-		TakeWhileIndexedT(
-			func(index int, fruit string) bool { return len(fruit) >= index },
-		).
-		ToSlice(&query)
-
-	fmt.Println(query)
-	// Output:
-	// [apple passionfruit banana mango orange blueberry]
-}
-
-// The following code example demonstrates how to use ToMapBy
-// by using a key and value selectors to populate a map.
-func ExampleQuery_ToMapByT() {
-	type Product struct {
-		Name string
-		Code int
-	}
-
-	products := []Product{
-		{Name: "orange", Code: 4},
-		{Name: "apple", Code: 9},
-		{Name: "lemon", Code: 12},
-		{Name: "apple", Code: 9},
-	}
-
-	map1 := map[int]string{}
-	From(products).
-		ToMapByT(&map1,
-			func(item Product) int { return item.Code },
-			func(item Product) string { return item.Name },
-		)
-
-	fmt.Println(map1[4])
-	fmt.Println(map1[9])
-	fmt.Println(map1[12])
-	// Output:
-	// orange
-	// apple
-	// lemon
-}
-
-// The following code example demonstrates how to use WhereT
-// to filter a slices.
-func ExampleQuery_WhereT() {
-	fruits := []string{"apple", "passionfruit", "banana", "mango",
-		"orange", "blueberry", "grape", "strawberry"}
-	var query []string
-	From(fruits).
-		WhereT(
-			func(f string) bool { return len(f) > 6 },
-		).
-		ToSlice(&query)
-
-	fmt.Println(query)
-	// Output:
-	// [passionfruit blueberry strawberry]
-}
-
-// The following code example demonstrates how to use WhereIndexedT
-// to filter a slice based on a predicate that involves the index of each element.
-func ExampleQuery_WhereIndexedT() {
-	numbers := []int{0, 30, 20, 15, 90, 85, 40, 75}
-
-	var query []int
-	From(numbers).
-		WhereIndexedT(
-			func(index int, number int) bool { return number <= index*10 },
-		).
-		ToSlice(&query)
-
-	fmt.Println(query)
-	// Output:
-	// [0 20 15 40]
-}
-
-// The following code example demonstrates how to use the ZipT
-// method to merge two slices.
-func ExampleQuery_ZipT() {
-	number := []int{1, 2, 3, 4, 5}
-	words := []string{"one", "two", "three"}
-
-	q := From(number).
-		ZipT(From(words),
-			func(a int, b string) []interface{} { return []interface{}{a, b} },
-		)
-
-	fmt.Println(q.Results())
-	// Output:
-	// [[1 one] [2 two] [3 three]]
-}
-
-// The following code example demonstrates how to use the FromChannelT
-// to make a Query from typed channel.
-func ExampleFromChannelT() {
-	ch := make(chan string, 3)
-	ch <- "one"
-	ch <- "two"
-	ch <- "three"
-	close(ch)
-
-	q := FromChannelT(ch)
-
-	fmt.Println(q.Results())
-	// Output:
-	// [one two three]
-}

+ 0 - 79
tool/help/except.go

@@ -1,79 +0,0 @@
-package help
-
-// Except produces the set difference of two sequences. The set difference is
-// the members of the first sequence that don't appear in the second sequence.
-func (q Query) Except(q2 Query) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-
-			next2 := q2.Iterate()
-			set := make(map[interface{}]bool)
-			for i, ok := next2(); ok; i, ok = next2() {
-				set[i] = true
-			}
-
-			return func() (item interface{}, ok bool) {
-				for item, ok = next(); ok; item, ok = next() {
-					if _, has := set[item]; !has {
-						return
-					}
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// ExceptBy invokes a transform function on each element of a collection and
-// produces the set difference of two sequences. The set difference is the
-// members of the first sequence that don't appear in the second sequence.
-func (q Query) ExceptBy(q2 Query,
-	selector func(interface{}) interface{}) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-
-			next2 := q2.Iterate()
-			set := make(map[interface{}]bool)
-			for i, ok := next2(); ok; i, ok = next2() {
-				s := selector(i)
-				set[s] = true
-			}
-
-			return func() (item interface{}, ok bool) {
-				for item, ok = next(); ok; item, ok = next() {
-					s := selector(item)
-					if _, has := set[s]; !has {
-						return
-					}
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// ExceptByT is the typed version of ExceptBy.
-//
-//   - selectorFn is of type "func(TSource) TSource"
-//
-// NOTE: ExceptBy has better performance than ExceptByT.
-func (q Query) ExceptByT(q2 Query,
-	selectorFn interface{}) Query {
-	selectorGenericFunc, err := newGenericFunc(
-		"ExceptByT", "selectorFn", selectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	selectorFunc := func(item interface{}) interface{} {
-		return selectorGenericFunc.Call(item)
-	}
-
-	return q.ExceptBy(q2, selectorFunc)
-}

+ 0 - 31
tool/help/except_test.go

@@ -1,31 +0,0 @@
-package help
-
-import "testing"
-
-func TestExcept(t *testing.T) {
-	input1 := []int{1, 2, 3, 4, 5, 1, 2, 5}
-	input2 := []int{1, 2}
-	want := []interface{}{3, 4, 5, 5}
-
-	if q := From(input1).Except(From(input2)); !validateQuery(q, want) {
-		t.Errorf("From(%v).Except(%v)=%v expected %v", input1, input2, toSlice(q), want)
-	}
-}
-
-func TestExceptBy(t *testing.T) {
-	input1 := []int{1, 2, 3, 4, 5, 1, 2, 5}
-	input2 := []int{1}
-	want := []interface{}{2, 4, 2}
-
-	if q := From(input1).ExceptBy(From(input2), func(i interface{}) interface{} {
-		return i.(int) % 2
-	}); !validateQuery(q, want) {
-		t.Errorf("From(%v).ExceptBy(%v)=%v expected %v", input1, input2, toSlice(q), want)
-	}
-}
-
-func TestExceptByT_PanicWhenSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "ExceptByT: parameter [selectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).ExceptByT(From([]int{1}), func(x, item int) int { return item + 2 })
-	})
-}

+ 0 - 193
tool/help/from.go

@@ -1,193 +0,0 @@
-package help
-
-import "reflect"
-
-// Iterator is an alias for function to iterate over data.
-type Iterator func() (item interface{}, ok bool)
-
-// Query is the type returned from query functions. It can be iterated manually
-// as shown in the example.
-type Query struct {
-	Iterate func() Iterator
-}
-
-// KeyValue is a type that is used to iterate over a map (if query is created
-// from a map). This type is also used by ToMap() method to output result of a
-// query into a map.
-type KeyValue struct {
-	Key   interface{}
-	Value interface{}
-}
-
-// Iterable is an interface that has to be implemented by a custom collection in
-// order to work with linq.
-type Iterable interface {
-	Iterate() Iterator
-}
-
-// From initializes a linq query with passed slice, array or map as the source.
-// String, channel or struct implementing Iterable interface can be used as an
-// input. In this case From delegates it to FromString, FromChannel and
-// FromIterable internally.
-func From(source interface{}) Query {
-	src := reflect.ValueOf(source)
-
-	switch src.Kind() {
-	case reflect.Slice, reflect.Array:
-		len := src.Len()
-
-		return Query{
-			Iterate: func() Iterator {
-				index := 0
-
-				return func() (item interface{}, ok bool) {
-					ok = index < len
-					if ok {
-						item = src.Index(index).Interface()
-						index++
-					}
-
-					return
-				}
-			},
-		}
-	case reflect.Map:
-		len := src.Len()
-
-		return Query{
-			Iterate: func() Iterator {
-				index := 0
-				keys := src.MapKeys()
-
-				return func() (item interface{}, ok bool) {
-					ok = index < len
-					if ok {
-						key := keys[index]
-						item = KeyValue{
-							Key:   key.Interface(),
-							Value: src.MapIndex(key).Interface(),
-						}
-
-						index++
-					}
-
-					return
-				}
-			},
-		}
-	case reflect.String:
-		return FromString(source.(string))
-	case reflect.Chan:
-		if _, ok := source.(chan interface{}); ok {
-			return FromChannel(source.(chan interface{}))
-		} else {
-			return FromChannelT(source)
-		}
-	default:
-		return FromIterable(source.(Iterable))
-	}
-}
-
-// FromChannel initializes a linq query with passed channel, linq iterates over
-// channel until it is closed.
-func FromChannel(source <-chan interface{}) Query {
-	return Query{
-		Iterate: func() Iterator {
-			return func() (item interface{}, ok bool) {
-				item, ok = <-source
-				return
-			}
-		},
-	}
-}
-
-// FromChannelT is the typed version of FromChannel.
-//
-//   - source is of type "chan TSource"
-//
-// NOTE: FromChannel has better performance than FromChannelT.
-func FromChannelT(source interface{}) Query {
-	src := reflect.ValueOf(source)
-	return Query{
-		Iterate: func() Iterator {
-			return func() (interface{}, bool) {
-				value, ok := src.Recv()
-				return value.Interface(), ok
-			}
-		},
-	}
-}
-
-// FromString initializes a linq query with passed string, linq iterates over
-// runes of string.
-func FromString(source string) Query {
-	runes := []rune(source)
-	len := len(runes)
-
-	return Query{
-		Iterate: func() Iterator {
-			index := 0
-
-			return func() (item interface{}, ok bool) {
-				ok = index < len
-				if ok {
-					item = runes[index]
-					index++
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// FromIterable initializes a linq query with custom collection passed. This
-// collection has to implement Iterable interface, linq iterates over items,
-// that has to implement Comparable interface or be basic types.
-func FromIterable(source Iterable) Query {
-	return Query{
-		Iterate: source.Iterate,
-	}
-}
-
-// Range generates a sequence of integral numbers within a specified range.
-func Range(start, count int) Query {
-	return Query{
-		Iterate: func() Iterator {
-			index := 0
-			current := start
-
-			return func() (item interface{}, ok bool) {
-				if index >= count {
-					return nil, false
-				}
-
-				item, ok = current, true
-
-				index++
-				current++
-				return
-			}
-		},
-	}
-}
-
-// Repeat generates a sequence that contains one repeated value.
-func Repeat(value interface{}, count int) Query {
-	return Query{
-		Iterate: func() Iterator {
-			index := 0
-
-			return func() (item interface{}, ok bool) {
-				if index >= count {
-					return nil, false
-				}
-
-				item, ok = value, true
-
-				index++
-				return
-			}
-		},
-	}
-}

+ 0 - 107
tool/help/from_test.go

@@ -1,107 +0,0 @@
-package help
-
-import "testing"
-
-func TestFrom(t *testing.T) {
-	c := make(chan interface{}, 3)
-	c <- -1
-	c <- 0
-	c <- 1
-	close(c)
-
-	ct := make(chan int, 3)
-	ct <- -10
-	ct <- 0
-	ct <- 10
-	close(ct)
-
-	tests := []struct {
-		input  interface{}
-		output []interface{}
-		want   bool
-	}{
-		{[]int{1, 2, 3}, []interface{}{1, 2, 3}, true},
-		{[]int{1, 2, 4}, []interface{}{1, 2, 3}, false},
-		{[3]int{1, 2, 3}, []interface{}{1, 2, 3}, true},
-		{[3]int{1, 2, 4}, []interface{}{1, 2, 3}, false},
-		{"str", []interface{}{'s', 't', 'r'}, true},
-		{"str", []interface{}{'s', 't', 'g'}, false},
-		{map[string]bool{"foo": true}, []interface{}{KeyValue{"foo", true}}, true},
-		{map[string]bool{"foo": true}, []interface{}{KeyValue{"foo", false}}, false},
-		{c, []interface{}{-1, 0, 1}, true},
-		{ct, []interface{}{-10, 0, 10}, true},
-		{foo{f1: 1, f2: true, f3: "string"}, []interface{}{1, true, "string"}, true},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input); validateQuery(q, test.output) != test.want {
-			if test.want {
-				t.Errorf("From(%v)=%v expected %v", test.input, toSlice(q), test.output)
-			} else {
-				t.Errorf("From(%v)=%v expected not equal", test.input, test.output)
-			}
-		}
-	}
-}
-
-func TestFromChannel(t *testing.T) {
-	c := make(chan interface{}, 3)
-	c <- 10
-	c <- 15
-	c <- -3
-	close(c)
-
-	w := []interface{}{10, 15, -3}
-
-	if q := FromChannel(c); !validateQuery(q, w) {
-		t.Errorf("FromChannel() failed expected %v", w)
-	}
-}
-
-func TestFromChannelT(t *testing.T) {
-	c := make(chan int, 3)
-	c <- 10
-	c <- 15
-	c <- -3
-	close(c)
-
-	w := []interface{}{10, 15, -3}
-
-	if q := FromChannelT(c); !validateQuery(q, w) {
-		t.Errorf("FromChannelT() failed expected %v", w)
-	}
-}
-
-func TestFromString(t *testing.T) {
-	s := "string"
-	w := []interface{}{'s', 't', 'r', 'i', 'n', 'g'}
-
-	if q := FromString(s); !validateQuery(q, w) {
-		t.Errorf("FromString(%v)!=%v", s, w)
-	}
-}
-
-func TestFromIterable(t *testing.T) {
-	s := foo{f1: 1, f2: true, f3: "string"}
-	w := []interface{}{1, true, "string"}
-
-	if q := FromIterable(s); !validateQuery(q, w) {
-		t.Errorf("FromIterable(%v)!=%v", s, w)
-	}
-}
-
-func TestRange(t *testing.T) {
-	w := []interface{}{-2, -1, 0, 1, 2}
-
-	if q := Range(-2, 5); !validateQuery(q, w) {
-		t.Errorf("Range(-2, 5)=%v expected %v", toSlice(q), w)
-	}
-}
-
-func TestRepeat(t *testing.T) {
-	w := []interface{}{1, 1, 1, 1, 1}
-
-	if q := Repeat(1, 5); !validateQuery(q, w) {
-		t.Errorf("Repeat(1, 5)=%v expected %v", toSlice(q), w)
-	}
-}

+ 0 - 36
tool/help/general_test.go

@@ -1,36 +0,0 @@
-package help
-
-import (
-	"reflect"
-	"testing"
-)
-
-func TestChannelToChannel(t *testing.T) {
-	input := []int{30, 40, 50}
-
-	inpCh := make(chan interface{})
-	resCh := make(chan interface{})
-
-	go func() {
-		for _, i := range input {
-			inpCh <- i
-		}
-
-		close(inpCh)
-	}()
-
-	go func() {
-		FromChannel(inpCh).Where(func(i interface{}) bool {
-			return i.(int) > 20
-		}).ToChannel(resCh)
-	}()
-
-	result := []int{}
-	for value := range resCh {
-		result = append(result, value.(int))
-	}
-
-	if !reflect.DeepEqual(result, input) {
-		t.Errorf("FromChannel().ToChannel()=%v expected %v", result, input)
-	}
-}

+ 0 - 138
tool/help/genericfunc.go

@@ -1,138 +0,0 @@
-package help
-
-import (
-	"fmt"
-	"reflect"
-	"strings"
-)
-
-// genericType represents a any reflect.Type.
-type genericType int
-
-var genericTp = reflect.TypeOf(new(genericType)).Elem()
-
-// functionCache keeps genericFunc reflection objects in cache.
-type functionCache struct {
-	MethodName string
-	ParamName  string
-	FnValue    reflect.Value
-	FnType     reflect.Type
-	TypesIn    []reflect.Type
-	TypesOut   []reflect.Type
-}
-
-// genericFunc is a type used to validate and call dynamic functions.
-type genericFunc struct {
-	Cache *functionCache
-}
-
-// Call calls a dynamic function.
-func (g *genericFunc) Call(params ...interface{}) interface{} {
-	paramsIn := make([]reflect.Value, len(params))
-	for i, param := range params {
-		paramsIn[i] = reflect.ValueOf(param)
-	}
-	paramsOut := g.Cache.FnValue.Call(paramsIn)
-	if len(paramsOut) >= 1 {
-		return paramsOut[0].Interface()
-	}
-	return nil
-}
-
-// newGenericFunc instantiates a new genericFunc pointer
-func newGenericFunc(methodName, paramName string, fn interface{}, validateFunc func(*functionCache) error) (*genericFunc, error) {
-	cache := &functionCache{}
-	cache.FnValue = reflect.ValueOf(fn)
-
-	if cache.FnValue.Kind() != reflect.Func {
-		return nil, fmt.Errorf("%s: parameter [%s] is not a function type. It is a '%s'", methodName, paramName, cache.FnValue.Type())
-	}
-	cache.MethodName = methodName
-	cache.ParamName = paramName
-	cache.FnType = cache.FnValue.Type()
-	numTypesIn := cache.FnType.NumIn()
-	cache.TypesIn = make([]reflect.Type, numTypesIn)
-	for i := 0; i < numTypesIn; i++ {
-		cache.TypesIn[i] = cache.FnType.In(i)
-	}
-
-	numTypesOut := cache.FnType.NumOut()
-	cache.TypesOut = make([]reflect.Type, numTypesOut)
-	for i := 0; i < numTypesOut; i++ {
-		cache.TypesOut[i] = cache.FnType.Out(i)
-	}
-	if err := validateFunc(cache); err != nil {
-		return nil, err
-	}
-
-	return &genericFunc{Cache: cache}, nil
-}
-
-// simpleParamValidator creates a function to validate genericFunc based in the
-// In and Out function parameters.
-func simpleParamValidator(In []reflect.Type, Out []reflect.Type) func(cache *functionCache) error {
-	return func(cache *functionCache) error {
-		var isValid = func() bool {
-			if In != nil {
-				if len(In) != len(cache.TypesIn) {
-					return false
-				}
-				for i, paramIn := range In {
-					if paramIn != genericTp && paramIn != cache.TypesIn[i] {
-						return false
-					}
-				}
-			}
-			if Out != nil {
-				if len(Out) != len(cache.TypesOut) {
-					return false
-				}
-				for i, paramOut := range Out {
-					if paramOut != genericTp && paramOut != cache.TypesOut[i] {
-						return false
-					}
-				}
-			}
-			return true
-		}
-
-		if !isValid() {
-			return fmt.Errorf("%s: parameter [%s] has a invalid function signature. Expected: '%s', actual: '%s'", cache.MethodName, cache.ParamName, formatFnSignature(In, Out), formatFnSignature(cache.TypesIn, cache.TypesOut))
-		}
-		return nil
-	}
-}
-
-// newElemTypeSlice creates a slice of items elem types.
-func newElemTypeSlice(items ...interface{}) []reflect.Type {
-	typeList := make([]reflect.Type, len(items))
-	for i, item := range items {
-		typeItem := reflect.TypeOf(item)
-		if typeItem.Kind() == reflect.Ptr {
-			typeList[i] = typeItem.Elem()
-		}
-	}
-	return typeList
-}
-
-// formatFnSignature formats the func signature based in the parameters types.
-func formatFnSignature(In []reflect.Type, Out []reflect.Type) string {
-	paramInNames := make([]string, len(In))
-	for i, typeIn := range In {
-		if typeIn == genericTp {
-			paramInNames[i] = "T"
-		} else {
-			paramInNames[i] = typeIn.String()
-		}
-
-	}
-	paramOutNames := make([]string, len(Out))
-	for i, typeOut := range Out {
-		if typeOut == genericTp {
-			paramOutNames[i] = "T"
-		} else {
-			paramOutNames[i] = typeOut.String()
-		}
-	}
-	return fmt.Sprintf("func(%s)%s", strings.Join(paramInNames, ","), strings.Join(paramOutNames, ","))
-}

+ 0 - 130
tool/help/genericfunc_test.go

@@ -1,130 +0,0 @@
-package help
-
-import (
-	"errors"
-	"reflect"
-	"testing"
-)
-
-func TestNewGenericFunc(t *testing.T) {
-	tests := []struct {
-		methodName     string
-		paramName      string
-		function       interface{}
-		validationFunc func(*functionCache) error
-		exception      error
-	}{
-		{ // A valid function
-			"TestNewGenericFunc", "test1",
-			func(item int) bool { return item > 10 },
-			simpleParamValidator(newElemTypeSlice(new(int)), newElemTypeSlice(new(bool))),
-			nil,
-		},
-		{ // A valid generic function
-			"TestNewGenericFunc", "test1",
-			func(item int) bool { return item > 10 },
-			simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(bool))),
-			nil,
-		},
-		{ //returns error when the function parameter has not the function kind
-			"TestNewGenericFunc", "test2",
-			"Not a function",
-			simpleParamValidator(nil, []reflect.Type{}),
-			errors.New("TestNewGenericFunc: parameter [test2] is not a function type. It is a 'string'"),
-		},
-		{ // Returns error when expected parameters number are not equal
-			"TestNewGenericFunc", "test3",
-			func(idx, item int) {},
-			simpleParamValidator(newElemTypeSlice(new(int)), []reflect.Type{}),
-			errors.New("TestNewGenericFunc: parameter [test3] has a invalid function signature. Expected: 'func(int)', actual: 'func(int,int)'"),
-		},
-		{ // Returns error when expected parameters types are not equal
-			"TestNewGenericFunc", "test4",
-			func(items ...int) bool { return false },
-			simpleParamValidator(newElemTypeSlice(new([]bool)), newElemTypeSlice(new(bool))),
-			errors.New("TestNewGenericFunc: parameter [test4] has a invalid function signature. Expected: 'func([]bool)bool', actual: 'func([]int)bool'"),
-		},
-		{ // Returns error when expected returns number are not equal
-			"TestNewGenericFunc", "test5",
-			func(item int) bool { return item > 10 },
-			simpleParamValidator(newElemTypeSlice(new(int)), []reflect.Type{}),
-			errors.New("TestNewGenericFunc: parameter [test5] has a invalid function signature. Expected: 'func(int)', actual: 'func(int)bool'"),
-		},
-		{ // Returns error when expected return types are not equal
-			"TestNewGenericFunc", "test6",
-			func(items ...int) bool { return false },
-			simpleParamValidator(newElemTypeSlice(new([]int)), newElemTypeSlice(new(int64))),
-			errors.New("TestNewGenericFunc: parameter [test6] has a invalid function signature. Expected: 'func([]int)int64', actual: 'func([]int)bool'"),
-		},
-		{ // Returns error when expected return types are not equal
-			"TestNewGenericFunc", "test7",
-			func(items ...int) bool { return false },
-			simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(int64))),
-			errors.New("TestNewGenericFunc: parameter [test7] has a invalid function signature. Expected: 'func(T)int64', actual: 'func([]int)bool'"),
-		},
-	}
-
-	for _, test := range tests {
-		_, err := newGenericFunc(test.methodName, test.paramName, test.function, test.validationFunc)
-		if !(err == test.exception || err.Error() == test.exception.Error()) {
-			t.Errorf("Validate expect error: %s, actual: %s", test.exception, err)
-		}
-	}
-}
-
-func TestCall(t *testing.T) {
-	tests := []struct {
-		methodName     string
-		paramName      string
-		function       interface{}
-		validationFunc func(*functionCache) error
-		fnParameter    interface{}
-		result         interface{}
-		exception      error
-	}{
-		{ // A valid function and parameters
-			"TestCall", "test1",
-			func(i int) int { return i * 3 },
-			simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(int))),
-			3,
-			9,
-			nil,
-		},
-		{ // Returns error when the required type doesn't match with the specification
-			"TestCall", "test2",
-			func(i int) int { return i * 3 },
-			simpleParamValidator(newElemTypeSlice(new(int)), newElemTypeSlice(new(int))),
-			"not a int",
-			9,
-			errors.New("reflect: Call using string as type int"),
-		},
-		{ // A valid function and parameters
-			"TestCall", "test3",
-			func(i int) {},
-			simpleParamValidator(newElemTypeSlice(new(genericType)), []reflect.Type{}),
-			3,
-			nil,
-			nil,
-		},
-	}
-
-	for _, test := range tests {
-		func() {
-			defer func() {
-				r := recover()
-				if !(r == test.exception || r == test.exception.Error()) {
-					t.Errorf("expect error: nil, actual: %s", r)
-				}
-			}()
-			dynaFunc, err := newGenericFunc(test.methodName, test.paramName, test.function, test.validationFunc)
-			if err != nil {
-				t.Errorf("expect error: nil, actual: %s", err)
-			}
-			result := dynaFunc.Call(test.fnParameter)
-
-			if result != nil && result != test.result {
-				t.Errorf("expect result: %d, actual: %d", test.result, result)
-			}
-		}()
-	}
-}

+ 0 - 81
tool/help/groupby.go

@@ -1,81 +0,0 @@
-package help
-
-// Group is a type that is used to store the result of GroupBy method.
-type Group struct {
-	Key   interface{}
-	Group []interface{}
-}
-
-// GroupBy method groups the elements of a collection according to a specified
-// key selector function and projects the elements for each group by using a
-// specified function.
-func (q Query) GroupBy(keySelector func(interface{}) interface{},
-	elementSelector func(interface{}) interface{}) Query {
-	return Query{
-		func() Iterator {
-			next := q.Iterate()
-			set := make(map[interface{}][]interface{})
-
-			for item, ok := next(); ok; item, ok = next() {
-				key := keySelector(item)
-				set[key] = append(set[key], elementSelector(item))
-			}
-
-			len := len(set)
-			idx := 0
-			groups := make([]Group, len)
-			for k, v := range set {
-				groups[idx] = Group{k, v}
-				idx++
-			}
-
-			index := 0
-
-			return func() (item interface{}, ok bool) {
-				ok = index < len
-				if ok {
-					item = groups[index]
-					index++
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// GroupByT is the typed version of GroupBy.
-//
-//   - keySelectorFn is of type "func(TSource) TKey"
-//   - elementSelectorFn is of type "func(TSource) TElement"
-//
-// NOTE: GroupBy has better performance than GroupByT.
-func (q Query) GroupByT(keySelectorFn interface{},
-	elementSelectorFn interface{}) Query {
-	keySelectorGenericFunc, err := newGenericFunc(
-		"GroupByT", "keySelectorFn", keySelectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	keySelectorFunc := func(item interface{}) interface{} {
-		return keySelectorGenericFunc.Call(item)
-	}
-
-	elementSelectorGenericFunc, err := newGenericFunc(
-		"GroupByT", "elementSelectorFn", elementSelectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	elementSelectorFunc := func(item interface{}) interface{} {
-		return elementSelectorGenericFunc.Call(item)
-
-	}
-
-	return q.GroupBy(keySelectorFunc, elementSelectorFunc)
-}

+ 0 - 59
tool/help/groupby_test.go

@@ -1,59 +0,0 @@
-package help
-
-import (
-	"reflect"
-	"testing"
-)
-
-func TestGroupBy(t *testing.T) {
-	input := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
-	wantEven := []interface{}{2, 4, 6, 8}
-	wantOdd := []interface{}{1, 3, 5, 7, 9}
-
-	q := From(input).GroupBy(
-		func(i interface{}) interface{} { return i.(int) % 2 },
-		func(i interface{}) interface{} { return i.(int) },
-	)
-
-	next := q.Iterate()
-	eq := true
-	for item, ok := next(); ok; item, ok = next() {
-		group := item.(Group)
-		switch group.Key.(int) {
-		case 0:
-			if !reflect.DeepEqual(group.Group, wantEven) {
-				eq = false
-			}
-		case 1:
-			if !reflect.DeepEqual(group.Group, wantOdd) {
-				eq = false
-			}
-		default:
-			eq = false
-		}
-	}
-	t.Logf("From(%v).GroupBy()=%v", input, toSlice(q))
-	if !eq {
-		t.Errorf("From(%v).GroupBy()=%v", input, toSlice(q))
-	}
-}
-
-func TestGroupByT_PanicWhenKeySelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "GroupByT: parameter [keySelectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)bool'", func() {
-		var r []int
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).GroupByT(
-			func(i, j int) bool { return true },
-			func(i int) int { return i },
-		).ToSlice(&r)
-	})
-}
-
-func TestGroupByT_PanicWhenElementSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "GroupByT: parameter [elementSelectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)int'", func() {
-		var r []int
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).GroupByT(
-			func(i int) bool { return true },
-			func(i, j int) int { return i },
-		).ToSlice(&r)
-	})
-}

+ 0 - 107
tool/help/groupjoin.go

@@ -1,107 +0,0 @@
-package help
-
-import "reflect"
-
-// GroupJoin correlates the elements of two collections based on key equality,
-// and groups the results.
-//
-// This method produces hierarchical results, which means that elements from
-// outer query are paired with collections of matching elements from inner.
-// GroupJoin enables you to base your results on a whole set of matches for each
-// element of outer query.
-//
-// The resultSelector function is called only one time for each outer element
-// together with a collection of all the inner elements that match the outer
-// element. This differs from the Join method, in which the result selector
-// function is invoked on pairs that contain one element from outer and one
-// element from inner.
-//
-// GroupJoin preserves the order of the elements of outer, and for each element
-// of outer, the order of the matching elements from inner.
-func (q Query) GroupJoin(inner Query,
-	outerKeySelector func(interface{}) interface{},
-	innerKeySelector func(interface{}) interface{},
-	resultSelector func(outer interface{}, inners []interface{}) interface{}) Query {
-
-	return Query{
-		Iterate: func() Iterator {
-			outernext := q.Iterate()
-			innernext := inner.Iterate()
-
-			innerLookup := make(map[interface{}][]interface{})
-			for innerItem, ok := innernext(); ok; innerItem, ok = innernext() {
-				innerKey := innerKeySelector(innerItem)
-				innerLookup[innerKey] = append(innerLookup[innerKey], innerItem)
-			}
-
-			return func() (item interface{}, ok bool) {
-				if item, ok = outernext(); !ok {
-					return
-				}
-
-				if group, has := innerLookup[outerKeySelector(item)]; !has {
-					item = resultSelector(item, []interface{}{})
-				} else {
-					item = resultSelector(item, group)
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// GroupJoinT is the typed version of GroupJoin.
-//
-//   - inner: The query to join to the outer query.
-//   - outerKeySelectorFn is of type "func(TOuter) TKey"
-//   - innerKeySelectorFn is of type "func(TInner) TKey"
-//   - resultSelectorFn: is of type "func(TOuter, inners []TInner) TResult"
-//
-// NOTE: GroupJoin has better performance than GroupJoinT.
-func (q Query) GroupJoinT(inner Query,
-	outerKeySelectorFn interface{},
-	innerKeySelectorFn interface{},
-	resultSelectorFn interface{}) Query {
-	outerKeySelectorGenericFunc, err := newGenericFunc(
-		"GroupJoinT", "outerKeySelectorFn", outerKeySelectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	outerKeySelectorFunc := func(item interface{}) interface{} {
-		return outerKeySelectorGenericFunc.Call(item)
-	}
-
-	innerKeySelectorFuncGenericFunc, err := newGenericFunc(
-		"GroupJoinT", "innerKeySelectorFn", innerKeySelectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	innerKeySelectorFunc := func(item interface{}) interface{} {
-		return innerKeySelectorFuncGenericFunc.Call(item)
-	}
-
-	resultSelectorGenericFunc, err := newGenericFunc(
-		"GroupJoinT", "resultSelectorFn", resultSelectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType), new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	resultSelectorFunc := func(outer interface{}, inners []interface{}) interface{} {
-		innerSliceType := reflect.MakeSlice(resultSelectorGenericFunc.Cache.TypesIn[1], 0, 0)
-		innersSlicePointer := reflect.New(innerSliceType.Type())
-		From(inners).ToSlice(innersSlicePointer.Interface())
-		innersTyped := reflect.Indirect(innersSlicePointer).Interface()
-		return resultSelectorGenericFunc.Call(outer, innersTyped)
-	}
-
-	return q.GroupJoin(inner, outerKeySelectorFunc, innerKeySelectorFunc, resultSelectorFunc)
-}

+ 0 - 58
tool/help/groupjoin_test.go

@@ -1,58 +0,0 @@
-package help
-
-import "testing"
-
-func TestGroupJoin(t *testing.T) {
-	outer := []int{0, 1, 2}
-	inner := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
-	want := []interface{}{
-		KeyValue{0, 4},
-		KeyValue{1, 5},
-		KeyValue{2, 0},
-	}
-
-	q := From(outer).GroupJoin(
-		From(inner),
-		func(i interface{}) interface{} { return i },
-		func(i interface{}) interface{} { return i.(int) % 2 },
-		func(outer interface{}, inners []interface{}) interface{} {
-			return KeyValue{outer, len(inners)}
-		})
-
-	if !validateQuery(q, want) {
-		t.Errorf("From().GroupJoin()=%v expected %v", toSlice(q), want)
-	}
-}
-
-func TestGroupJoinT_PanicWhenOuterKeySelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "GroupJoinT: parameter [outerKeySelectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)int'", func() {
-		From([]int{0, 1, 2}).GroupJoinT(
-			From([]int{1, 2, 3, 4, 5, 6, 7, 8, 9}),
-			func(i, j int) int { return i },
-			func(i int) int { return i % 2 },
-			func(outer int, inners []int) KeyValue { return KeyValue{outer, len(inners)} },
-		)
-	})
-}
-
-func TestGroupJoinT_PanicWhenInnerKeySelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "GroupJoinT: parameter [innerKeySelectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)int'", func() {
-		From([]int{0, 1, 2}).GroupJoinT(
-			From([]int{1, 2, 3, 4, 5, 6, 7, 8, 9}),
-			func(i int) int { return i },
-			func(i, j int) int { return i % 2 },
-			func(outer int, inners []int) KeyValue { return KeyValue{outer, len(inners)} },
-		)
-	})
-}
-
-func TestGroupJoinT_PanicWhenResultSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "GroupJoinT: parameter [resultSelectorFn] has a invalid function signature. Expected: 'func(T,T)T', actual: 'func(int,int,[]int)linq.KeyValue'", func() {
-		From([]int{0, 1, 2}).GroupJoinT(
-			From([]int{1, 2, 3, 4, 5, 6, 7, 8, 9}),
-			func(i int) int { return i },
-			func(i int) int { return i % 2 },
-			func(outer, j int, inners []int) KeyValue { return KeyValue{outer, len(inners)} },
-		)
-	})
-}

+ 0 - 40
tool/help/index.go

@@ -1,40 +0,0 @@
-package help
-
-// IndexOf searches for an element that matches the conditions defined by a specified predicate
-// and returns the zero-based index of the first occurrence within the collection. This method
-// returns -1 if an item that matches the conditions is not found.
-func (q Query) IndexOf(predicate func(interface{}) bool) int {
-	index := 0
-	next := q.Iterate()
-
-	for item, ok := next(); ok; item, ok = next() {
-		if predicate(item) {
-			return index
-		}
-		index++
-	}
-
-	return -1
-}
-
-// IndexOfT is the typed version of IndexOf.
-//
-//   - predicateFn is of type "func(int,TSource)bool"
-//
-// NOTE: IndexOf has better performance than IndexOfT.
-func (q Query) IndexOfT(predicateFn interface{}) int {
-
-	predicateGenericFunc, err := newGenericFunc(
-		"IndexOfT", "predicateFn", predicateFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(bool))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	predicateFunc := func(item interface{}) bool {
-		return predicateGenericFunc.Call(item).(bool)
-	}
-
-	return q.IndexOf(predicateFunc)
-}

+ 0 - 53
tool/help/index_test.go

@@ -1,53 +0,0 @@
-package help
-
-import (
-	"testing"
-)
-
-func TestIndexOf(t *testing.T) {
-	tests := []struct {
-		input     interface{}
-		predicate func(interface{}) bool
-		expected  int
-	}{
-		{
-			input: [9]int{1, 2, 3, 4, 5, 6, 7, 8, 9},
-			predicate: func(i interface{}) bool {
-				return i.(int) == 3
-			},
-			expected: 2,
-		},
-		{
-			input: "sstr",
-			predicate: func(i interface{}) bool {
-				return i.(rune) == 'r'
-			},
-			expected: 3,
-		},
-		{
-			input: "gadsgsadgsda",
-			predicate: func(i interface{}) bool {
-				return i.(rune) == 'z'
-			},
-			expected: -1,
-		},
-	}
-
-	for _, test := range tests {
-		index := From(test.input).IndexOf(test.predicate)
-		if index != test.expected {
-			t.Errorf("From(%v).IndexOf() expected %v received %v", test.input, test.expected, index)
-		}
-
-		index = From(test.input).IndexOfT(test.predicate)
-		if index != test.expected {
-			t.Errorf("From(%v).IndexOfT() expected %v received %v", test.input, test.expected, index)
-		}
-	}
-}
-
-func TestIndexOfT_PanicWhenPredicateFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "IndexOfT: parameter [predicateFn] has a invalid function signature. Expected: 'func(T)bool', actual: 'func(int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).IndexOfT(func(item int) int { return item + 2 })
-	})
-}

+ 0 - 87
tool/help/intersect.go

@@ -1,87 +0,0 @@
-package help
-
-// Intersect produces the set intersection of the source collection and the
-// provided input collection. The intersection of two sets A and B is defined as
-// the set that contains all the elements of A that also appear in B, but no
-// other elements.
-func (q Query) Intersect(q2 Query) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			next2 := q2.Iterate()
-
-			set := make(map[interface{}]bool)
-			for item, ok := next2(); ok; item, ok = next2() {
-				set[item] = true
-			}
-
-			return func() (item interface{}, ok bool) {
-				for item, ok = next(); ok; item, ok = next() {
-					if _, has := set[item]; has {
-						delete(set, item)
-						return
-					}
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// IntersectBy produces the set intersection of the source collection and the
-// provided input collection. The intersection of two sets A and B is defined as
-// the set that contains all the elements of A that also appear in B, but no
-// other elements.
-//
-// IntersectBy invokes a transform function on each element of both collections.
-func (q Query) IntersectBy(q2 Query,
-	selector func(interface{}) interface{}) Query {
-
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			next2 := q2.Iterate()
-
-			set := make(map[interface{}]bool)
-			for item, ok := next2(); ok; item, ok = next2() {
-				s := selector(item)
-				set[s] = true
-			}
-
-			return func() (item interface{}, ok bool) {
-				for item, ok = next(); ok; item, ok = next() {
-					s := selector(item)
-					if _, has := set[s]; has {
-						delete(set, s)
-						return
-					}
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// IntersectByT is the typed version of IntersectBy.
-//
-//   - selectorFn is of type "func(TSource) TSource"
-//
-// NOTE: IntersectBy has better performance than IntersectByT.
-func (q Query) IntersectByT(q2 Query,
-	selectorFn interface{}) Query {
-	selectorGenericFunc, err := newGenericFunc(
-		"IntersectByT", "selectorFn", selectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	selectorFunc := func(item interface{}) interface{} {
-		return selectorGenericFunc.Call(item)
-	}
-
-	return q.IntersectBy(q2, selectorFunc)
-}

+ 0 - 33
tool/help/intersect_test.go

@@ -1,33 +0,0 @@
-package help
-
-import "testing"
-
-func TestIntersect(t *testing.T) {
-	input1 := []int{1, 2, 3}
-	input2 := []int{1, 4, 7, 9, 12, 3}
-	want := []interface{}{1, 3}
-
-	if q := From(input1).Intersect(From(input2)); !validateQuery(q, want) {
-		t.Errorf("From(%v).Intersect(%v)=%v expected %v", input1, input2, toSlice(q), want)
-	}
-}
-
-func TestIntersectBy(t *testing.T) {
-	input1 := []int{5, 7, 8}
-	input2 := []int{1, 4, 7, 9, 12, 3}
-	want := []interface{}{5, 8}
-
-	if q := From(input1).IntersectBy(From(input2), func(i interface{}) interface{} {
-		return i.(int) % 2
-	}); !validateQuery(q, want) {
-		t.Errorf("From(%v).IntersectBy(%v)=%v expected %v", input1, input2, toSlice(q), want)
-	}
-}
-
-func TestIntersectByT_PanicWhenSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "IntersectByT: parameter [selectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)int'", func() {
-		From([]int{5, 7, 8}).IntersectByT(From([]int{1, 4, 7, 9, 12, 3}), func(i, x int) int {
-			return i % 2
-		})
-	})
-}

+ 0 - 105
tool/help/join.go

@@ -1,105 +0,0 @@
-package help
-
-// Join correlates the elements of two collection based on matching keys.
-//
-// A join refers to the operation of correlating the elements of two sources of
-// information based on a common key. Join brings the two information sources
-// and the keys by which they are matched together in one method call. This
-// differs from the use of SelectMany, which requires more than one method call
-// to perform the same operation.
-//
-// Join preserves the order of the elements of outer collection, and for each of
-// these elements, the order of the matching elements of inner.
-func (q Query) Join(inner Query,
-	outerKeySelector func(interface{}) interface{},
-	innerKeySelector func(interface{}) interface{},
-	resultSelector func(outer interface{}, inner interface{}) interface{}) Query {
-
-	return Query{
-		Iterate: func() Iterator {
-			outernext := q.Iterate()
-			innernext := inner.Iterate()
-
-			innerLookup := make(map[interface{}][]interface{})
-			for innerItem, ok := innernext(); ok; innerItem, ok = innernext() {
-				innerKey := innerKeySelector(innerItem)
-				innerLookup[innerKey] = append(innerLookup[innerKey], innerItem)
-			}
-
-			var outerItem interface{}
-			var innerGroup []interface{}
-			innerLen, innerIndex := 0, 0
-
-			return func() (item interface{}, ok bool) {
-				if innerIndex >= innerLen {
-					has := false
-					for !has {
-						outerItem, ok = outernext()
-						if !ok {
-							return
-						}
-
-						innerGroup, has = innerLookup[outerKeySelector(outerItem)]
-						innerLen = len(innerGroup)
-						innerIndex = 0
-					}
-				}
-
-				item = resultSelector(outerItem, innerGroup[innerIndex])
-				innerIndex++
-				return item, true
-			}
-		},
-	}
-}
-
-// JoinT is the typed version of Join.
-//
-//   - outerKeySelectorFn is of type "func(TOuter) TKey"
-//   - innerKeySelectorFn is of type "func(TInner) TKey"
-//   - resultSelectorFn is of type "func(TOuter,TInner) TResult"
-//
-// NOTE: Join has better performance than JoinT.
-func (q Query) JoinT(inner Query,
-	outerKeySelectorFn interface{},
-	innerKeySelectorFn interface{},
-	resultSelectorFn interface{}) Query {
-	outerKeySelectorGenericFunc, err := newGenericFunc(
-		"JoinT", "outerKeySelectorFn", outerKeySelectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	outerKeySelectorFunc := func(item interface{}) interface{} {
-		return outerKeySelectorGenericFunc.Call(item)
-	}
-
-	innerKeySelectorFuncGenericFunc, err := newGenericFunc(
-		"JoinT", "innerKeySelectorFn",
-		innerKeySelectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	innerKeySelectorFunc := func(item interface{}) interface{} {
-		return innerKeySelectorFuncGenericFunc.Call(item)
-	}
-
-	resultSelectorGenericFunc, err := newGenericFunc(
-		"JoinT", "resultSelectorFn", resultSelectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType), new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	resultSelectorFunc := func(outer interface{}, inner interface{}) interface{} {
-		return resultSelectorGenericFunc.Call(outer, inner)
-	}
-
-	return q.Join(inner, outerKeySelectorFunc, innerKeySelectorFunc, resultSelectorFunc)
-}

+ 0 - 60
tool/help/join_test.go

@@ -1,60 +0,0 @@
-package help
-
-import "testing"
-
-func TestJoin(t *testing.T) {
-	outer := []int{0, 1, 2, 3, 4, 5, 8}
-	inner := []int{1, 2, 1, 4, 7, 6, 7, 2}
-	want := []interface{}{
-		KeyValue{1, 1},
-		KeyValue{1, 1},
-		KeyValue{2, 2},
-		KeyValue{2, 2},
-		KeyValue{4, 4},
-	}
-
-	q := From(outer).Join(
-		From(inner),
-		func(i interface{}) interface{} { return i },
-		func(i interface{}) interface{} { return i },
-		func(outer interface{}, inner interface{}) interface{} {
-			return KeyValue{outer, inner}
-		})
-
-	if !validateQuery(q, want) {
-		t.Errorf("From().Join()=%v expected %v", toSlice(q), want)
-	}
-}
-
-func TestJoinT_PanicWhenOuterKeySelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "JoinT: parameter [outerKeySelectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)int'", func() {
-		From([]int{0, 1, 2}).JoinT(
-			From([]int{1, 2, 3, 4, 5, 6, 7, 8, 9}),
-			func(i, j int) int { return i },
-			func(i int) int { return i % 2 },
-			func(outer int, inner int) KeyValue { return KeyValue{outer, inner} },
-		)
-	})
-}
-
-func TestJoinT_PanicWhenInnerKeySelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "JoinT: parameter [innerKeySelectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)int'", func() {
-		From([]int{0, 1, 2}).JoinT(
-			From([]int{1, 2, 3, 4, 5, 6, 7, 8, 9}),
-			func(i int) int { return i },
-			func(i, j int) int { return i % 2 },
-			func(outer int, inners []int) KeyValue { return KeyValue{outer, len(inners)} },
-		)
-	})
-}
-
-func TestJoinT_PanicWhenResultSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "JoinT: parameter [resultSelectorFn] has a invalid function signature. Expected: 'func(T,T)T', actual: 'func(int,int,int)linq.KeyValue'", func() {
-		From([]int{0, 1, 2}).JoinT(
-			From([]int{1, 2, 3, 4, 5, 6, 7, 8, 9}),
-			func(i int) int { return i },
-			func(i int) int { return i % 2 },
-			func(outer int, inner, j int) KeyValue { return KeyValue{outer, inner} },
-		)
-	})
-}

+ 0 - 313
tool/help/orderby.go

@@ -1,313 +0,0 @@
-package help
-
-import "sort"
-
-type order struct {
-	selector func(interface{}) interface{}
-	compare  comparer
-	desc     bool
-}
-
-// OrderedQuery is the type returned from OrderBy, OrderByDescending ThenBy and
-// ThenByDescending functions.
-type OrderedQuery struct {
-	Query
-	original Query
-	orders   []order
-}
-
-// OrderBy sorts the elements of a collection in ascending order. Elements are
-// sorted according to a key.
-func (q Query) OrderBy(selector func(interface{}) interface{}) OrderedQuery {
-	return OrderedQuery{
-		orders:   []order{{selector: selector}},
-		original: q,
-		Query: Query{
-			Iterate: func() Iterator {
-				items := q.sort([]order{{selector: selector}})
-				len := len(items)
-				index := 0
-
-				return func() (item interface{}, ok bool) {
-					ok = index < len
-					if ok {
-						item = items[index]
-						index++
-					}
-
-					return
-				}
-			},
-		},
-	}
-}
-
-// OrderByT is the typed version of OrderBy.
-//
-//   - selectorFn is of type "func(TSource) TKey"
-//
-// NOTE: OrderBy has better performance than OrderByT.
-func (q Query) OrderByT(selectorFn interface{}) OrderedQuery {
-	selectorGenericFunc, err := newGenericFunc(
-		"OrderByT", "selectorFn", selectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	selectorFunc := func(item interface{}) interface{} {
-		return selectorGenericFunc.Call(item)
-	}
-
-	return q.OrderBy(selectorFunc)
-}
-
-// OrderByDescending sorts the elements of a collection in descending order.
-// Elements are sorted according to a key.
-func (q Query) OrderByDescending(selector func(interface{}) interface{}) OrderedQuery {
-	return OrderedQuery{
-		orders:   []order{{selector: selector, desc: true}},
-		original: q,
-		Query: Query{
-			Iterate: func() Iterator {
-				items := q.sort([]order{{selector: selector, desc: true}})
-				len := len(items)
-				index := 0
-
-				return func() (item interface{}, ok bool) {
-					ok = index < len
-					if ok {
-						item = items[index]
-						index++
-					}
-
-					return
-				}
-			},
-		},
-	}
-}
-
-// OrderByDescendingT is the typed version of OrderByDescending.
-//   - selectorFn is of type "func(TSource) TKey"
-// NOTE: OrderByDescending has better performance than OrderByDescendingT.
-func (q Query) OrderByDescendingT(selectorFn interface{}) OrderedQuery {
-	selectorGenericFunc, err := newGenericFunc(
-		"OrderByDescendingT", "selectorFn", selectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	selectorFunc := func(item interface{}) interface{} {
-		return selectorGenericFunc.Call(item)
-	}
-
-	return q.OrderByDescending(selectorFunc)
-}
-
-// ThenBy performs a subsequent ordering of the elements in a collection in
-// ascending order. This method enables you to specify multiple sort criteria by
-// applying any number of ThenBy or ThenByDescending methods.
-func (oq OrderedQuery) ThenBy(
-	selector func(interface{}) interface{}) OrderedQuery {
-	return OrderedQuery{
-		orders:   append(oq.orders, order{selector: selector}),
-		original: oq.original,
-		Query: Query{
-			Iterate: func() Iterator {
-				items := oq.original.sort(append(oq.orders, order{selector: selector}))
-				len := len(items)
-				index := 0
-
-				return func() (item interface{}, ok bool) {
-					ok = index < len
-					if ok {
-						item = items[index]
-						index++
-					}
-
-					return
-				}
-			},
-		},
-	}
-}
-
-// ThenByT is the typed version of ThenBy.
-//   - selectorFn is of type "func(TSource) TKey"
-// NOTE: ThenBy has better performance than ThenByT.
-func (oq OrderedQuery) ThenByT(selectorFn interface{}) OrderedQuery {
-	selectorGenericFunc, err := newGenericFunc(
-		"ThenByT", "selectorFn", selectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	selectorFunc := func(item interface{}) interface{} {
-		return selectorGenericFunc.Call(item)
-	}
-
-	return oq.ThenBy(selectorFunc)
-}
-
-// ThenByDescending performs a subsequent ordering of the elements in a
-// collection in descending order. This method enables you to specify multiple
-// sort criteria by applying any number of ThenBy or ThenByDescending methods.
-func (oq OrderedQuery) ThenByDescending(selector func(interface{}) interface{}) OrderedQuery {
-	return OrderedQuery{
-		orders:   append(oq.orders, order{selector: selector, desc: true}),
-		original: oq.original,
-		Query: Query{
-			Iterate: func() Iterator {
-				items := oq.original.sort(append(oq.orders, order{selector: selector, desc: true}))
-				len := len(items)
-				index := 0
-
-				return func() (item interface{}, ok bool) {
-					ok = index < len
-					if ok {
-						item = items[index]
-						index++
-					}
-
-					return
-				}
-			},
-		},
-	}
-}
-
-// ThenByDescendingT is the typed version of ThenByDescending.
-//   - selectorFn is of type "func(TSource) TKey"
-// NOTE: ThenByDescending has better performance than ThenByDescendingT.
-func (oq OrderedQuery) ThenByDescendingT(selectorFn interface{}) OrderedQuery {
-	selectorFunc, ok := selectorFn.(func(interface{}) interface{})
-	if !ok {
-		selectorGenericFunc, err := newGenericFunc(
-			"ThenByDescending", "selectorFn", selectorFn,
-			simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-		)
-		if err != nil {
-			panic(err)
-		}
-
-		selectorFunc = func(item interface{}) interface{} {
-			return selectorGenericFunc.Call(item)
-		}
-	}
-	return oq.ThenByDescending(selectorFunc)
-}
-
-// Sort returns a new query by sorting elements with provided less function in
-// ascending order. The comparer function should return true if the parameter i
-// is less than j. While this method is uglier than chaining OrderBy,
-// OrderByDescending, ThenBy and ThenByDescending methods, it's performance is
-// much better.
-func (q Query) Sort(less func(i, j interface{}) bool) Query {
-	return Query{
-		Iterate: func() Iterator {
-			items := q.lessSort(less)
-			len := len(items)
-			index := 0
-
-			return func() (item interface{}, ok bool) {
-				ok = index < len
-				if ok {
-					item = items[index]
-					index++
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// SortT is the typed version of Sort.
-//   - lessFn is of type "func(TSource,TSource) bool"
-// NOTE: Sort has better performance than SortT.
-func (q Query) SortT(lessFn interface{}) Query {
-	lessGenericFunc, err := newGenericFunc(
-		"SortT", "lessFn", lessFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType), new(genericType)), newElemTypeSlice(new(bool))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	lessFunc := func(i, j interface{}) bool {
-		return lessGenericFunc.Call(i, j).(bool)
-	}
-
-	return q.Sort(lessFunc)
-}
-
-type sorter struct {
-	items []interface{}
-	less  func(i, j interface{}) bool
-}
-
-func (s sorter) Len() int {
-	return len(s.items)
-}
-
-func (s sorter) Swap(i, j int) {
-	s.items[i], s.items[j] = s.items[j], s.items[i]
-}
-
-func (s sorter) Less(i, j int) bool {
-	return s.less(s.items[i], s.items[j])
-}
-
-func (q Query) sort(orders []order) (r []interface{}) {
-	next := q.Iterate()
-	for item, ok := next(); ok; item, ok = next() {
-		r = append(r, item)
-	}
-
-	if len(r) == 0 {
-		return
-	}
-
-	for i, j := range orders {
-		orders[i].compare = getComparer(j.selector(r[0]))
-	}
-
-	s := sorter{
-		items: r,
-		less: func(i, j interface{}) bool {
-			for _, order := range orders {
-				x, y := order.selector(i), order.selector(j)
-				switch order.compare(x, y) {
-				case 0:
-					continue
-				case -1:
-					return !order.desc
-				default:
-					return order.desc
-				}
-			}
-
-			return false
-		}}
-
-	sort.Sort(s)
-	return
-}
-
-func (q Query) lessSort(less func(i, j interface{}) bool) (r []interface{}) {
-	next := q.Iterate()
-	for item, ok := next(); ok; item, ok = next() {
-		r = append(r, item)
-	}
-
-	s := sorter{items: r, less: less}
-
-	sort.Sort(s)
-	return
-}

+ 0 - 158
tool/help/orderby_test.go

@@ -1,158 +0,0 @@
-package help
-
-import "testing"
-
-func TestEmpty(t *testing.T) {
-	q := From([]string{}).OrderBy(func(in interface{}) interface{} {
-		return 0
-	})
-
-	_, ok := q.Iterate()()
-	if ok {
-		t.Errorf("Iterator for empty collection must return ok=false")
-	}
-}
-
-func TestOrderBy(t *testing.T) {
-	slice := make([]foo, 100)
-
-	for i := len(slice) - 1; i >= 0; i-- {
-		slice[i].f1 = i
-	}
-
-	q := From(slice).OrderBy(func(i interface{}) interface{} {
-		return i.(foo).f1
-	})
-
-	j := 0
-	next := q.Iterate()
-	for item, ok := next(); ok; item, ok = next() {
-		if item.(foo).f1 != j {
-			t.Errorf("OrderBy()[%v]=%v expected %v", j, item, foo{f1: j})
-		}
-
-		j++
-	}
-}
-
-func TestOrderByT_PanicWhenSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "OrderByT: parameter [selectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).OrderByT(func(item, j int) int { return item + 2 })
-	})
-}
-
-func TestOrderByDescending(t *testing.T) {
-	slice := make([]foo, 100)
-
-	for i := 0; i < len(slice); i++ {
-		slice[i].f1 = i
-	}
-
-	q := From(slice).OrderByDescending(func(i interface{}) interface{} {
-		return i.(foo).f1
-	})
-
-	j := len(slice) - 1
-	next := q.Iterate()
-	for item, ok := next(); ok; item, ok = next() {
-		if item.(foo).f1 != j {
-			t.Errorf("OrderByDescending()[%v]=%v expected %v", j, item, foo{f1: j})
-		}
-
-		j--
-	}
-}
-
-func TestOrderByDescendingT_PanicWhenSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "OrderByDescendingT: parameter [selectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).OrderByDescendingT(func(item, j int) int { return item + 2 })
-	})
-}
-
-func TestThenBy(t *testing.T) {
-	slice := make([]foo, 1000)
-
-	for i := len(slice) - 1; i >= 0; i-- {
-		slice[i].f1 = i
-		slice[i].f2 = i%2 == 0
-	}
-
-	q := From(slice).OrderBy(func(i interface{}) interface{} {
-		return i.(foo).f2
-	}).ThenBy(func(i interface{}) interface{} {
-		return i.(foo).f1
-	})
-
-	next := q.Iterate()
-	for item, ok := next(); ok; item, ok = next() {
-		if item.(foo).f2 != (item.(foo).f1%2 == 0) {
-			t.Errorf("OrderBy().ThenBy()=%v", item)
-		}
-	}
-}
-
-func TestThenByT_PanicWhenSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "ThenByT: parameter [selectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)bool'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).
-			OrderByT(func(item int) int { return item }).
-			ThenByT(func(item, j int) bool { return true })
-	})
-}
-
-func TestThenByDescending(t *testing.T) {
-	slice := make([]foo, 1000)
-
-	for i := len(slice) - 1; i >= 0; i-- {
-		slice[i].f1 = i
-		slice[i].f2 = i%2 == 0
-	}
-
-	q := From(slice).OrderBy(func(i interface{}) interface{} {
-		return i.(foo).f2
-	}).ThenByDescending(func(i interface{}) interface{} {
-		return i.(foo).f1
-	})
-
-	next := q.Iterate()
-	for item, ok := next(); ok; item, ok = next() {
-		if item.(foo).f2 != (item.(foo).f1%2 == 0) {
-			t.Errorf("OrderBy().ThenByDescending()=%v", item)
-		}
-	}
-}
-
-func TestThenByDescendingT_PanicWhenSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "ThenByDescending: parameter [selectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)bool'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).
-			OrderByT(func(item int) int { return item }).
-			ThenByDescendingT(func(item, j int) bool { return true })
-	})
-}
-
-func TestSort(t *testing.T) {
-	slice := make([]foo, 100)
-
-	for i := len(slice) - 1; i >= 0; i-- {
-		slice[i].f1 = i
-	}
-
-	q := From(slice).Sort(func(i, j interface{}) bool {
-		return i.(foo).f1 < j.(foo).f1
-	})
-
-	j := 0
-	next := q.Iterate()
-	for item, ok := next(); ok; item, ok = next() {
-		if item.(foo).f1 != j {
-			t.Errorf("Sort()[%v]=%v expected %v", j, item, foo{f1: j})
-		}
-
-		j++
-	}
-}
-
-func TestSortT_PanicWhenLessFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "SortT: parameter [lessFn] has a invalid function signature. Expected: 'func(T,T)bool', actual: 'func(int,int)string'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).SortT(func(i, j int) string { return "" })
-	})
-}

+ 0 - 674
tool/help/result.go

@@ -1,674 +0,0 @@
-package help
-
-import (
-	"math"
-	"reflect"
-)
-
-// All determines whether all elements of a collection satisfy a condition.
-func (q Query) All(predicate func(interface{}) bool) bool {
-	next := q.Iterate()
-
-	for item, ok := next(); ok; item, ok = next() {
-		if !predicate(item) {
-			return false
-		}
-	}
-
-	return true
-}
-
-// AllT is the typed version of All.
-//
-//   - predicateFn is of type "func(TSource) bool"
-//
-// NOTE: All has better performance than AllT.
-func (q Query) AllT(predicateFn interface{}) bool {
-
-	predicateGenericFunc, err := newGenericFunc(
-		"AllT", "predicateFn", predicateFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(bool))),
-	)
-	if err != nil {
-		panic(err)
-	}
-	predicateFunc := func(item interface{}) bool {
-		return predicateGenericFunc.Call(item).(bool)
-	}
-
-	return q.All(predicateFunc)
-}
-
-// Any determines whether any element of a collection exists.
-func (q Query) Any() bool {
-	_, ok := q.Iterate()()
-	return ok
-}
-
-// AnyWith determines whether any element of a collection satisfies a condition.
-func (q Query) AnyWith(predicate func(interface{}) bool) bool {
-	next := q.Iterate()
-
-	for item, ok := next(); ok; item, ok = next() {
-		if predicate(item) {
-			return true
-		}
-	}
-
-	return false
-}
-
-// AnyWithT is the typed version of AnyWith.
-//
-//   - predicateFn is of type "func(TSource) bool"
-//
-// NOTE: AnyWith has better performance than AnyWithT.
-func (q Query) AnyWithT(predicateFn interface{}) bool {
-
-	predicateGenericFunc, err := newGenericFunc(
-		"AnyWithT", "predicateFn", predicateFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(bool))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	predicateFunc := func(item interface{}) bool {
-		return predicateGenericFunc.Call(item).(bool)
-	}
-
-	return q.AnyWith(predicateFunc)
-}
-
-// Average computes the average of a collection of numeric values.
-func (q Query) Average() (r float64) {
-	next := q.Iterate()
-	item, ok := next()
-	if !ok {
-		return math.NaN()
-	}
-
-	n := 1
-	switch item.(type) {
-	case int, int8, int16, int32, int64:
-		conv := getIntConverter(item)
-		sum := conv(item)
-
-		for item, ok = next(); ok; item, ok = next() {
-			sum += conv(item)
-			n++
-		}
-
-		r = float64(sum)
-	case uint, uint8, uint16, uint32, uint64:
-		conv := getUIntConverter(item)
-		sum := conv(item)
-
-		for item, ok = next(); ok; item, ok = next() {
-			sum += conv(item)
-			n++
-		}
-
-		r = float64(sum)
-	default:
-		conv := getFloatConverter(item)
-		r = conv(item)
-
-		for item, ok = next(); ok; item, ok = next() {
-			r += conv(item)
-			n++
-		}
-	}
-
-	return r / float64(n)
-}
-
-// Contains determines whether a collection contains a specified element.
-func (q Query) Contains(value interface{}) bool {
-	next := q.Iterate()
-
-	for item, ok := next(); ok; item, ok = next() {
-		if item == value {
-			return true
-		}
-	}
-
-	return false
-}
-
-// Count returns the number of elements in a collection.
-func (q Query) Count() (r int) {
-	next := q.Iterate()
-
-	for _, ok := next(); ok; _, ok = next() {
-		r++
-	}
-
-	return
-}
-
-// CountWith returns a number that represents how many elements in the specified
-// collection satisfy a condition.
-func (q Query) CountWith(predicate func(interface{}) bool) (r int) {
-	next := q.Iterate()
-
-	for item, ok := next(); ok; item, ok = next() {
-		if predicate(item) {
-			r++
-		}
-	}
-
-	return
-}
-
-// CountWithT is the typed version of CountWith.
-//
-//   - predicateFn is of type "func(TSource) bool"
-//
-// NOTE: CountWith has better performance than CountWithT.
-func (q Query) CountWithT(predicateFn interface{}) int {
-
-	predicateGenericFunc, err := newGenericFunc(
-		"CountWithT", "predicateFn", predicateFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(bool))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	predicateFunc := func(item interface{}) bool {
-		return predicateGenericFunc.Call(item).(bool)
-	}
-
-	return q.CountWith(predicateFunc)
-}
-
-// First returns the first element of a collection.
-func (q Query) First() interface{} {
-	item, _ := q.Iterate()()
-	return item
-}
-
-// FirstWith returns the first element of a collection that satisfies a
-// specified condition.
-func (q Query) FirstWith(predicate func(interface{}) bool) interface{} {
-	next := q.Iterate()
-
-	for item, ok := next(); ok; item, ok = next() {
-		if predicate(item) {
-			return item
-		}
-	}
-
-	return nil
-}
-
-// FirstWithT is the typed version of FirstWith.
-//
-//   - predicateFn is of type "func(TSource) bool"
-//
-// NOTE: FirstWith has better performance than FirstWithT.
-func (q Query) FirstWithT(predicateFn interface{}) interface{} {
-
-	predicateGenericFunc, err := newGenericFunc(
-		"FirstWithT", "predicateFn", predicateFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(bool))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	predicateFunc := func(item interface{}) bool {
-		return predicateGenericFunc.Call(item).(bool)
-	}
-
-	return q.FirstWith(predicateFunc)
-}
-
-// ForEach performs the specified action on each element of a collection.
-func (q Query) ForEach(action func(interface{})) {
-	next := q.Iterate()
-
-	for item, ok := next(); ok; item, ok = next() {
-		action(item)
-	}
-}
-
-// ForEachT is the typed version of ForEach.
-//
-//   - actionFn is of type "func(TSource)"
-//
-// NOTE: ForEach has better performance than ForEachT.
-func (q Query) ForEachT(actionFn interface{}) {
-	actionGenericFunc, err := newGenericFunc(
-		"ForEachT", "actionFn", actionFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), nil),
-	)
-
-	if err != nil {
-		panic(err)
-	}
-
-	actionFunc := func(item interface{}) {
-		actionGenericFunc.Call(item)
-	}
-
-	q.ForEach(actionFunc)
-}
-
-// ForEachIndexed performs the specified action on each element of a collection.
-//
-// The first argument to action represents the zero-based index of that
-// element in the source collection. This can be useful if the elements are in a
-// known order and you want to do something with an element at a particular
-// index, for example. It can also be useful if you want to retrieve the index
-// of one or more elements. The second argument to action represents the
-// element to process.
-func (q Query) ForEachIndexed(action func(int, interface{})) {
-	next := q.Iterate()
-	index := 0
-
-	for item, ok := next(); ok; item, ok = next() {
-		action(index, item)
-		index++
-	}
-}
-
-// ForEachIndexedT is the typed version of ForEachIndexed.
-//
-//   - actionFn is of type "func(int, TSource)"
-//
-// NOTE: ForEachIndexed has better performance than ForEachIndexedT.
-func (q Query) ForEachIndexedT(actionFn interface{}) {
-	actionGenericFunc, err := newGenericFunc(
-		"ForEachIndexedT", "actionFn", actionFn,
-		simpleParamValidator(newElemTypeSlice(new(int), new(genericType)), nil),
-	)
-
-	if err != nil {
-		panic(err)
-	}
-
-	actionFunc := func(index int, item interface{}) {
-		actionGenericFunc.Call(index, item)
-	}
-
-	q.ForEachIndexed(actionFunc)
-}
-
-// Last returns the last element of a collection.
-func (q Query) Last() (r interface{}) {
-	next := q.Iterate()
-
-	for item, ok := next(); ok; item, ok = next() {
-		r = item
-	}
-
-	return
-}
-
-// LastWith returns the last element of a collection that satisfies a specified
-// condition.
-func (q Query) LastWith(predicate func(interface{}) bool) (r interface{}) {
-	next := q.Iterate()
-
-	for item, ok := next(); ok; item, ok = next() {
-		if predicate(item) {
-			r = item
-		}
-	}
-
-	return
-}
-
-// LastWithT is the typed version of LastWith.
-//
-//   - predicateFn is of type "func(TSource) bool"
-//
-// NOTE: LastWith has better performance than LastWithT.
-func (q Query) LastWithT(predicateFn interface{}) interface{} {
-
-	predicateGenericFunc, err := newGenericFunc(
-		"LastWithT", "predicateFn", predicateFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(bool))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	predicateFunc := func(item interface{}) bool {
-		return predicateGenericFunc.Call(item).(bool)
-	}
-
-	return q.LastWith(predicateFunc)
-}
-
-// Max returns the maximum value in a collection of values.
-func (q Query) Max() (r interface{}) {
-	next := q.Iterate()
-	item, ok := next()
-	if !ok {
-		return nil
-	}
-
-	compare := getComparer(item)
-	r = item
-
-	for item, ok := next(); ok; item, ok = next() {
-		if compare(item, r) > 0 {
-			r = item
-		}
-	}
-
-	return
-}
-
-// Min returns the minimum value in a collection of values.
-func (q Query) Min() (r interface{}) {
-	next := q.Iterate()
-	item, ok := next()
-	if !ok {
-		return nil
-	}
-
-	compare := getComparer(item)
-	r = item
-
-	for item, ok := next(); ok; item, ok = next() {
-		if compare(item, r) < 0 {
-			r = item
-		}
-	}
-
-	return
-}
-
-// Results iterates over a collection and returnes slice of interfaces
-func (q Query) Results() (r []interface{}) {
-	next := q.Iterate()
-
-	for item, ok := next(); ok; item, ok = next() {
-		r = append(r, item)
-	}
-
-	return
-}
-
-// SequenceEqual determines whether two collections are equal.
-func (q Query) SequenceEqual(q2 Query) bool {
-	next := q.Iterate()
-	next2 := q2.Iterate()
-
-	for item, ok := next(); ok; item, ok = next() {
-		item2, ok2 := next2()
-		if !ok2 || item != item2 {
-			return false
-		}
-	}
-
-	_, ok2 := next2()
-	return !ok2
-}
-
-// Single returns the only element of a collection, and nil if there is not
-// exactly one element in the collection.
-func (q Query) Single() interface{} {
-	next := q.Iterate()
-	item, ok := next()
-	if !ok {
-		return nil
-	}
-
-	_, ok = next()
-	if ok {
-		return nil
-	}
-
-	return item
-}
-
-// SingleWith returns the only element of a collection that satisfies a
-// specified condition, and nil if more than one such element exists.
-func (q Query) SingleWith(predicate func(interface{}) bool) (r interface{}) {
-	next := q.Iterate()
-	found := false
-
-	for item, ok := next(); ok; item, ok = next() {
-		if predicate(item) {
-			if found {
-				return nil
-			}
-
-			found = true
-			r = item
-		}
-	}
-
-	return
-}
-
-// SingleWithT is the typed version of SingleWith.
-//
-//   - predicateFn is of type "func(TSource) bool"
-//
-// NOTE: SingleWith has better performance than SingleWithT.
-func (q Query) SingleWithT(predicateFn interface{}) interface{} {
-	predicateGenericFunc, err := newGenericFunc(
-		"SingleWithT", "predicateFn", predicateFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(bool))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	predicateFunc := func(item interface{}) bool {
-		return predicateGenericFunc.Call(item).(bool)
-	}
-
-	return q.SingleWith(predicateFunc)
-}
-
-// SumInts computes the sum of a collection of numeric values.
-//
-// Values can be of any integer type: int, int8, int16, int32, int64. The result
-// is int64. Method returns zero if collection contains no elements.
-func (q Query) SumInts() (r int64) {
-	next := q.Iterate()
-	item, ok := next()
-	if !ok {
-		return 0
-	}
-
-	conv := getIntConverter(item)
-	r = conv(item)
-
-	for item, ok = next(); ok; item, ok = next() {
-		r += conv(item)
-	}
-
-	return
-}
-
-// SumUInts computes the sum of a collection of numeric values.
-//
-// Values can be of any unsigned integer type: uint, uint8, uint16, uint32,
-// uint64. The result is uint64. Method returns zero if collection contains no
-// elements.
-func (q Query) SumUInts() (r uint64) {
-	next := q.Iterate()
-	item, ok := next()
-	if !ok {
-		return 0
-	}
-
-	conv := getUIntConverter(item)
-	r = conv(item)
-
-	for item, ok = next(); ok; item, ok = next() {
-		r += conv(item)
-	}
-
-	return
-}
-
-// SumFloats computes the sum of a collection of numeric values.
-//
-// Values can be of any float type: float32 or float64. The result is float64.
-// Method returns zero if collection contains no elements.
-func (q Query) SumFloats() (r float64) {
-	next := q.Iterate()
-	item, ok := next()
-	if !ok {
-		return 0
-	}
-
-	conv := getFloatConverter(item)
-	r = conv(item)
-
-	for item, ok = next(); ok; item, ok = next() {
-		r += conv(item)
-	}
-
-	return
-}
-
-// ToChannel iterates over a collection and outputs each element to a channel,
-// then closes it.
-func (q Query) ToChannel(result chan<- interface{}) {
-	next := q.Iterate()
-
-	for item, ok := next(); ok; item, ok = next() {
-		result <- item
-	}
-
-	close(result)
-}
-
-// ToChannelT is the typed version of ToChannel.
-//
-//   - result is of type "chan TSource"
-//
-// NOTE: ToChannel has better performance than ToChannelT.
-func (q Query) ToChannelT(result interface{}) {
-	r := reflect.ValueOf(result)
-	next := q.Iterate()
-
-	for item, ok := next(); ok; item, ok = next() {
-		r.Send(reflect.ValueOf(item))
-	}
-
-	r.Close()
-}
-
-// ToMap iterates over a collection and populates result map with elements.
-// Collection elements have to be of KeyValue type to use this method. To
-// populate a map with elements of different type use ToMapBy method. ToMap
-// doesn't empty the result map before populating it.
-func (q Query) ToMap(result interface{}) {
-	q.ToMapBy(
-		result,
-		func(i interface{}) interface{} {
-			return i.(KeyValue).Key
-		},
-		func(i interface{}) interface{} {
-			return i.(KeyValue).Value
-		})
-}
-
-// ToMapBy iterates over a collection and populates the result map with
-// elements. Functions keySelector and valueSelector are executed for each
-// element of the collection to generate key and value for the map. Generated
-// key and value types must be assignable to the map's key and value types.
-// ToMapBy doesn't empty the result map before populating it.
-func (q Query) ToMapBy(result interface{},
-	keySelector func(interface{}) interface{},
-	valueSelector func(interface{}) interface{}) {
-	res := reflect.ValueOf(result)
-	m := reflect.Indirect(res)
-	next := q.Iterate()
-
-	for item, ok := next(); ok; item, ok = next() {
-		key := reflect.ValueOf(keySelector(item))
-		value := reflect.ValueOf(valueSelector(item))
-
-		m.SetMapIndex(key, value)
-	}
-
-	res.Elem().Set(m)
-}
-
-// ToMapByT is the typed version of ToMapBy.
-//
-//   - keySelectorFn is of type "func(TSource)TKey"
-//   - valueSelectorFn is of type "func(TSource)TValue"
-//
-// NOTE: ToMapBy has better performance than ToMapByT.
-func (q Query) ToMapByT(result interface{},
-	keySelectorFn interface{}, valueSelectorFn interface{}) {
-	keySelectorGenericFunc, err := newGenericFunc(
-		"ToMapByT", "keySelectorFn", keySelectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	keySelectorFunc := func(item interface{}) interface{} {
-		return keySelectorGenericFunc.Call(item)
-	}
-
-	valueSelectorGenericFunc, err := newGenericFunc(
-		"ToMapByT", "valueSelectorFn", valueSelectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	valueSelectorFunc := func(item interface{}) interface{} {
-		return valueSelectorGenericFunc.Call(item)
-	}
-
-	q.ToMapBy(result, keySelectorFunc, valueSelectorFunc)
-}
-
-// ToSlice iterates over a collection and saves the results in the slice pointed
-// by v. It overwrites the existing slice, starting from index 0.
-//
-// If the slice pointed by v has sufficient capacity, v will be pointed to a
-// resliced slice. If it does not, a new underlying array will be allocated and
-// v will point to it.
-func (q Query) ToSlice(v interface{}) {
-	res := reflect.ValueOf(v)
-	slice := reflect.Indirect(res)
-
-	cap := slice.Cap()
-	res.Elem().Set(slice.Slice(0, cap)) // make len(slice)==cap(slice) from now on
-
-	next := q.Iterate()
-	index := 0
-	for item, ok := next(); ok; item, ok = next() {
-		if index >= cap {
-			slice, cap = grow(slice)
-		}
-		slice.Index(index).Set(reflect.ValueOf(item))
-		index++
-	}
-
-	// reslice the len(res)==cap(res) actual res size
-	res.Elem().Set(slice.Slice(0, index))
-}
-
-// grow grows the slice s by doubling its capacity, then it returns the new
-// slice (resliced to its full capacity) and the new capacity.
-func grow(s reflect.Value) (v reflect.Value, newCap int) {
-	cap := s.Cap()
-	if cap == 0 {
-		cap = 1
-	} else {
-		cap *= 2
-	}
-	newSlice := reflect.MakeSlice(s.Type(), cap, cap)
-	reflect.Copy(newSlice, s)
-	return newSlice, cap
-}

+ 0 - 622
tool/help/result_test.go

@@ -1,622 +0,0 @@
-package help
-
-import (
-	"math"
-	"reflect"
-	"testing"
-	"unsafe"
-)
-
-func TestAll(t *testing.T) {
-	input := []int{2, 4, 6, 8}
-
-	r1 := From(input).All(func(i interface{}) bool {
-		return i.(int)%2 == 0
-	})
-	r2 := From(input).All(func(i interface{}) bool {
-		return i.(int)%2 != 0
-	})
-
-	if !r1 {
-		t.Errorf("From(%v).All()=%v", input, r1)
-	}
-
-	if r2 {
-		t.Errorf("From(%v).All()=%v", input, r2)
-	}
-}
-
-func TestAllT_PanicWhenPredicateFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "AllT: parameter [predicateFn] has a invalid function signature. Expected: 'func(T)bool', actual: 'func(int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).AllT(func(item int) int { return item + 2 })
-	})
-}
-
-func TestAny(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  bool
-	}{
-		{[]int{1, 2, 2, 3, 1}, true},
-		{[9]int{1, 1, 1, 2, 1, 2, 3, 4, 2}, true},
-		{"sstr", true},
-		{[]int{}, false},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).Any(); r != test.want {
-			t.Errorf("From(%v).Any()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestAnyWith(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  bool
-	}{
-		{[]int{1, 2, 2, 3, 1}, false},
-		{[9]int{1, 1, 1, 2, 1, 2, 3, 4, 2}, true},
-		{[]int{}, false},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).AnyWith(func(i interface{}) bool {
-			return i.(int) == 4
-		}); r != test.want {
-			t.Errorf("From(%v).Any()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestAnyWithT_PanicWhenPredicateFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "AnyWithT: parameter [predicateFn] has a invalid function signature. Expected: 'func(T)bool', actual: 'func(int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).AnyWithT(func(item int) int { return item + 2 })
-	})
-}
-
-func TestAverage(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  float64
-	}{
-		{[]int{1, 2, 2, 3, 1}, 1.8},
-		{[5]uint{1, 2, 5, 7, 10}, 5.},
-		{[]float32{1., 1.}, 1.},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).Average(); r != test.want {
-			t.Errorf("From(%v).Average()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestAverageForNaN(t *testing.T) {
-	if r := From([]int{}).Average(); !math.IsNaN(r) {
-		t.Errorf("From([]int{}).Average()=%v expected %v", r, math.NaN())
-	}
-}
-
-func TestContains(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		value interface{}
-		want  bool
-	}{
-		{[]int{1, 2, 2, 3, 1}, 10, false},
-		{[5]uint{1, 2, 5, 7, 10}, uint(5), true},
-		{[]float32{}, 1., false},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).Contains(test.value); r != test.want {
-			t.Errorf("From(%v).Contains(%v)=%v expected %v", test.input, test.value, r, test.want)
-		}
-	}
-}
-
-func TestCount(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  int
-	}{
-		{[]int{1, 2, 2, 3, 1}, 5},
-		{[7]uint{1, 2, 5, 7, 10, 12, 15}, 7},
-		{[]float32{}, 0},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).Count(); r != test.want {
-			t.Errorf("From(%v).Count()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestCountWith(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  int
-	}{
-		{[]int{1, 2, 2, 3, 1}, 4},
-		{[]int{}, 0},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).CountWith(func(i interface{}) bool {
-			return i.(int) <= 2
-		}); r != test.want {
-			t.Errorf("From(%v).CountWith()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestCountWithT_PanicWhenPredicateFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "CountWithT: parameter [predicateFn] has a invalid function signature. Expected: 'func(T)bool', actual: 'func(int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).CountWithT(func(item int) int { return item + 2 })
-	})
-}
-
-func TestFirst(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  interface{}
-	}{
-		{[]int{1, 2, 2, 3, 1}, 1},
-		{[]int{}, nil},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).First(); r != test.want {
-			t.Errorf("From(%v).First()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestFirstWith(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  interface{}
-	}{
-		{[]int{1, 2, 2, 3, 1}, 3},
-		{[]int{}, nil},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).FirstWith(func(i interface{}) bool {
-			return i.(int) > 2
-		}); r != test.want {
-			t.Errorf("From(%v).FirstWith()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestFirstWithT_PanicWhenPredicateFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "FirstWithT: parameter [predicateFn] has a invalid function signature. Expected: 'func(T)bool', actual: 'func(int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).FirstWithT(func(item int) int { return item + 2 })
-	})
-}
-
-func TestForEach(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  interface{}
-	}{
-		{[5]int{1, 2, 2, 35, 111}, []int{2, 4, 4, 70, 222}},
-		{[]int{}, []int{}},
-	}
-
-	for _, test := range tests {
-		output := []int{}
-		From(test.input).ForEach(func(item interface{}) {
-			output = append(output, item.(int)*2)
-		})
-
-		if !reflect.DeepEqual(output, test.want) {
-			t.Fatalf("From(%#v).ForEach()=%#v expected=%#v", test.input, output, test.want)
-		}
-	}
-}
-
-func TestForEachT_PanicWhenActionFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "ForEachT: parameter [actionFn] has a invalid function signature. Expected: 'func(T)', actual: 'func(int,int)'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).ForEachT(func(item, idx int) { item = item + 2 })
-	})
-}
-
-func TestForEachIndexed(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  interface{}
-	}{
-		{[5]int{1, 2, 2, 35, 111}, []int{1, 3, 4, 38, 115}},
-		{[]int{}, []int{}},
-	}
-
-	for _, test := range tests {
-		output := []int{}
-		From(test.input).ForEachIndexed(func(index int, item interface{}) {
-			output = append(output, item.(int)+index)
-		})
-
-		if !reflect.DeepEqual(output, test.want) {
-			t.Fatalf("From(%#v).ForEachIndexed()=%#v expected=%#v", test.input, output, test.want)
-		}
-	}
-}
-
-func TestForEachIndexedT_PanicWhenActionFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "ForEachIndexedT: parameter [actionFn] has a invalid function signature. Expected: 'func(int,T)', actual: 'func(int)'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).ForEachIndexedT(func(item int) { item = item + 2 })
-	})
-}
-
-func TestLast(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  interface{}
-	}{
-		{[]int{1, 2, 2, 3, 1}, 1},
-		{[]int{}, nil},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).Last(); r != test.want {
-			t.Errorf("From(%v).Last()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestLastWith(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  interface{}
-	}{
-		{[]int{1, 2, 2, 3, 1, 4, 2, 5, 1, 1}, 5},
-		{[]int{}, nil},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).LastWith(func(i interface{}) bool {
-			return i.(int) > 2
-		}); r != test.want {
-			t.Errorf("From(%v).LastWith()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestLastWithT_PanicWhenPredicateFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "LastWithT: parameter [predicateFn] has a invalid function signature. Expected: 'func(T)bool', actual: 'func(int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).LastWithT(func(item int) int { return item + 2 })
-	})
-}
-
-func TestMax(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  interface{}
-	}{
-		{[]int{1, 2, 2, 3, 1}, 3},
-		{[]int{1}, 1},
-		{[]int{}, nil},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).Max(); r != test.want {
-			t.Errorf("From(%v).Max()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestMin(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  interface{}
-	}{
-		{[]int{1, 2, 2, 3, 0}, 0},
-		{[]int{1}, 1},
-		{[]int{}, nil},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).Min(); r != test.want {
-			t.Errorf("From(%v).Min()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestResults(t *testing.T) {
-	input := []int{1, 2, 3}
-	want := []interface{}{1, 2, 3}
-
-	if r := From(input).Results(); !reflect.DeepEqual(r, want) {
-		t.Errorf("From(%v).Raw()=%v expected %v", input, r, want)
-	}
-}
-
-func TestSequenceEqual(t *testing.T) {
-	tests := []struct {
-		input  interface{}
-		input2 interface{}
-		want   bool
-	}{
-		{[]int{1, 2, 2, 3, 1}, []int{4, 6}, false},
-		{[]int{1, -1, 100}, []int{1, -1, 100}, true},
-		{[]int{}, []int{}, true},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).SequenceEqual(From(test.input2)); r != test.want {
-			t.Errorf("From(%v).SequenceEqual(%v)=%v expected %v", test.input, test.input2, r, test.want)
-		}
-	}
-}
-
-func TestSingle(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  interface{}
-	}{
-		{[]int{1, 2, 2, 3, 1}, nil},
-		{[]int{1}, 1},
-		{[]int{}, nil},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).Single(); r != test.want {
-			t.Errorf("From(%v).Single()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestSingleWith(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  interface{}
-	}{
-		{[]int{1, 2, 2, 3, 1}, 3},
-		{[]int{1, 1, 1}, nil},
-		{[]int{5, 1, 1, 10, 2, 2}, nil},
-		{[]int{}, nil},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).SingleWith(func(i interface{}) bool {
-			return i.(int) > 2
-		}); r != test.want {
-			t.Errorf("From(%v).SingleWith()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestSingleWithT_PanicWhenPredicateFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "SingleWithT: parameter [predicateFn] has a invalid function signature. Expected: 'func(T)bool', actual: 'func(int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).SingleWithT(func(item int) int { return item + 2 })
-	})
-}
-
-func TestSumInts(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  int64
-	}{
-		{[]int{1, 2, 2, 3, 1}, 9},
-		{[]int{1}, 1},
-		{[]int{}, 0},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).SumInts(); r != test.want {
-			t.Errorf("From(%v).SumInts()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestSumUInts(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  uint64
-	}{
-		{[]uint{1, 2, 2, 3, 1}, 9},
-		{[]uint{1}, 1},
-		{[]uint{}, 0},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).SumUInts(); r != test.want {
-			t.Errorf("From(%v).SumInts()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestSumFloats(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  float64
-	}{
-		{[]float32{1., 2., 2., 3., 1.}, 9.},
-		{[]float64{1.}, 1.},
-		{[]float32{}, 0.},
-	}
-
-	for _, test := range tests {
-		if r := From(test.input).SumFloats(); r != test.want {
-			t.Errorf("From(%v).SumFloats()=%v expected %v", test.input, r, test.want)
-		}
-	}
-}
-
-func TestToChannel(t *testing.T) {
-	c := make(chan interface{})
-	input := []int{1, 2, 3, 4, 5}
-
-	go func() {
-		From(input).ToChannel(c)
-	}()
-
-	result := []int{}
-	for value := range c {
-		result = append(result, value.(int))
-	}
-
-	if !reflect.DeepEqual(result, input) {
-		t.Errorf("From(%v).ToChannel()=%v expected %v", input, result, input)
-	}
-}
-
-func TestToChannelT(t *testing.T) {
-	c := make(chan string)
-	input := []string{"1", "2", "3", "4", "5"}
-
-	go From(input).ToChannelT(c)
-
-	result := []string{}
-	for value := range c {
-		result = append(result, value)
-	}
-
-	if !reflect.DeepEqual(result, input) {
-		t.Errorf("From(%v).ToChannelT()=%v expected %v", input, result, input)
-	}
-}
-
-func TestToMap(t *testing.T) {
-	input := make(map[int]bool)
-	input[1] = true
-	input[2] = false
-	input[3] = true
-
-	result := make(map[int]bool)
-	From(input).ToMap(&result)
-
-	if !reflect.DeepEqual(result, input) {
-		t.Errorf("From(%v).ToMap()=%v expected %v", input, result, input)
-	}
-}
-
-func TestToMapBy(t *testing.T) {
-	input := make(map[int]bool)
-	input[1] = true
-	input[2] = false
-	input[3] = true
-
-	result := make(map[int]bool)
-	From(input).ToMapBy(&result,
-		func(i interface{}) interface{} {
-			return i.(KeyValue).Key
-		},
-		func(i interface{}) interface{} {
-			return i.(KeyValue).Value
-		})
-
-	if !reflect.DeepEqual(result, input) {
-		t.Errorf("From(%v).ToMapBy()=%v expected %v", input, result, input)
-	}
-}
-
-func TestToMapByT_PanicWhenKeySelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "ToMapByT: parameter [keySelectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)int'", func() {
-		result := make(map[int]bool)
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).ToMapByT(
-			&result,
-			func(item, j int) int { return item + 2 },
-			func(item int) int { return item + 2 },
-		)
-	})
-}
-
-func TestToMapByT_PanicWhenValueSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "ToMapByT: parameter [valueSelectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)int'", func() {
-		result := make(map[int]bool)
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).ToMapByT(
-			&result,
-			func(item int) int { return item + 2 },
-			func(item, j int) int { return item + 2 },
-		)
-	})
-}
-
-func TestToSlice(t *testing.T) {
-	tests := []struct {
-		input             []int
-		output            []int
-		want              []int
-		wantedOutputCap   int
-		outputIsANewSlice bool
-	}{
-		// output is nil slice
-		{
-			[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
-			nil,
-			[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
-			16,
-			true},
-		// output is empty slice (cap=0)
-		{
-			[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
-			[]int{},
-			[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
-			16,
-			true},
-		// ToSlice() overwrites existing elements and reslices.
-		{[]int{1, 2, 3},
-			[]int{99, 98, 97, 96, 95},
-			[]int{1, 2, 3},
-			5,
-			false},
-		// cap(out)>len(result): we get the same slice, resliced. cap unchanged.
-		{[]int{1, 2, 3, 4, 5},
-			make([]int, 0, 11),
-			[]int{1, 2, 3, 4, 5},
-			11,
-			false},
-		// cap(out)==len(result): we get the same slice, cap unchanged.
-		{[]int{1, 2, 3, 4, 5},
-			make([]int, 0, 5),
-			[]int{1, 2, 3, 4, 5},
-			5,
-			false},
-		// cap(out)<len(result): we get a new slice with len(out)=len(result) and cap doubled: cap(out')==2*cap(out)
-		{[]int{1, 2, 3, 4, 5},
-			make([]int, 0, 4),
-			[]int{1, 2, 3, 4, 5},
-			8,
-			true},
-		// cap(out)<<len(result): trigger capacity to double more than once (26 -> 52 -> 104)
-		{make([]int, 100),
-			make([]int, 0, 26),
-			make([]int, 100),
-			104,
-			true},
-		// len(out) > len(result): we get the same slice with len(out)=len(result) and cap unchanged: cap(out')==cap(out)
-		{[]int{1, 2, 3, 4, 5},
-			make([]int, 0, 50),
-			[]int{1, 2, 3, 4, 5},
-			50,
-			false},
-	}
-
-	for c, test := range tests {
-		initialOutputValue := test.output
-		From(test.input).ToSlice(&test.output)
-		modifiedOutputValue := test.output
-
-		// test slice values
-		if !reflect.DeepEqual(test.output, test.want) {
-			t.Fatalf("case #%d: From(%#v).ToSlice()=%#v expected=%#v", c, test.input, test.output, test.want)
-		}
-
-		// test capacity of output slice
-		if cap(test.output) != test.wantedOutputCap {
-			t.Fatalf("case #%d: cap(output)=%d expected=%d", c, cap(test.output), test.wantedOutputCap)
-		}
-
-		// test if a new slice is allocated
-		inPtr := (*reflect.SliceHeader)(unsafe.Pointer(&initialOutputValue)).Data
-		outPtr := (*reflect.SliceHeader)(unsafe.Pointer(&modifiedOutputValue)).Data
-		isNewSlice := inPtr != outPtr
-		if isNewSlice != test.outputIsANewSlice {
-			t.Fatalf("case #%d: isNewSlice=%v (in=0x%X out=0x%X) expected=%v", c, isNewSlice, inPtr, outPtr, test.outputIsANewSlice)
-		}
-	}
-}

+ 0 - 30
tool/help/reverse.go

@@ -1,30 +0,0 @@
-package help
-
-// Reverse inverts the order of the elements in a collection.
-//
-// Unlike OrderBy, this sorting method does not consider the actual values
-// themselves in determining the order. Rather, it just returns the elements in
-// the reverse order from which they are produced by the underlying source.
-func (q Query) Reverse() Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-
-			items := []interface{}{}
-			for item, ok := next(); ok; item, ok = next() {
-				items = append(items, item)
-			}
-
-			index := len(items) - 1
-			return func() (item interface{}, ok bool) {
-				if index < 0 {
-					return
-				}
-
-				item, ok = items[index], true
-				index--
-				return
-			}
-		},
-	}
-}

+ 0 - 18
tool/help/reverse_test.go

@@ -1,18 +0,0 @@
-package help
-
-import "testing"
-
-func TestReverse(t *testing.T) {
-	tests := []struct {
-		input interface{}
-		want  []interface{}
-	}{
-		{[]int{1, 2, 3}, []interface{}{3, 2, 1}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).Reverse(); !validateQuery(q, test.want) {
-			t.Errorf("From(%v).Reverse()=%v expected %v", test.input, toSlice(q), test.want)
-		}
-	}
-}

+ 0 - 109
tool/help/select.go

@@ -1,109 +0,0 @@
-package help
-
-// Select projects each element of a collection into a new form. Returns a query
-// with the result of invoking the transform function on each element of
-// original source.
-//
-// This projection method requires the transform function, selector, to produce
-// one value for each value in the source collection. If selector returns a
-// value that is itself a collection, it is up to the consumer to traverse the
-// subcollections manually. In such a situation, it might be better for your
-// query to return a single coalesced collection of values. To achieve this, use
-// the SelectMany method instead of Select. Although SelectMany works similarly
-// to Select, it differs in that the transform function returns a collection
-// that is then expanded by SelectMany before it is returned.
-func (q Query) Select(selector func(interface{}) interface{}) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-
-			return func() (item interface{}, ok bool) {
-				var it interface{}
-				it, ok = next()
-				if ok {
-					item = selector(it)
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// SelectT is the typed version of Select.
-//   - selectorFn is of type "func(TSource)TResult"
-// NOTE: Select has better performance than SelectT.
-func (q Query) SelectT(selectorFn interface{}) Query {
-
-	selectGenericFunc, err := newGenericFunc(
-		"SelectT", "selectorFn", selectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	selectorFunc := func(item interface{}) interface{} {
-		return selectGenericFunc.Call(item)
-	}
-
-	return q.Select(selectorFunc)
-}
-
-// SelectIndexed projects each element of a collection into a new form by
-// incorporating the element's index. Returns a query with the result of
-// invoking the transform function on each element of original source.
-//
-// The first argument to selector represents the zero-based index of that
-// element in the source collection. This can be useful if the elements are in a
-// known order and you want to do something with an element at a particular
-// index, for example. It can also be useful if you want to retrieve the index
-// of one or more elements. The second argument to selector represents the
-// element to process.
-//
-// This projection method requires the transform function, selector, to produce
-// one value for each value in the source collection. If selector returns a
-// value that is itself a collection, it is up to the consumer to traverse the
-// subcollections manually. In such a situation, it might be better for your
-// query to return a single coalesced collection of values. To achieve this, use
-// the SelectMany method instead of Select. Although SelectMany works similarly
-// to Select, it differs in that the transform function returns a collection
-// that is then expanded by SelectMany before it is returned.
-func (q Query) SelectIndexed(selector func(int, interface{}) interface{}) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			index := 0
-
-			return func() (item interface{}, ok bool) {
-				var it interface{}
-				it, ok = next()
-				if ok {
-					item = selector(index, it)
-					index++
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// SelectIndexedT is the typed version of SelectIndexed.
-//   - selectorFn is of type "func(int,TSource)TResult"
-// NOTE: SelectIndexed has better performance than SelectIndexedT.
-func (q Query) SelectIndexedT(selectorFn interface{}) Query {
-	selectGenericFunc, err := newGenericFunc(
-		"SelectIndexedT", "selectorFn", selectorFn,
-		simpleParamValidator(newElemTypeSlice(new(int), new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	selectorFunc := func(index int, item interface{}) interface{} {
-		return selectGenericFunc.Call(index, item)
-	}
-
-	return q.SelectIndexed(selectorFunc)
-}

+ 0 - 60
tool/help/select_test.go

@@ -1,60 +0,0 @@
-package help
-
-import (
-	"strconv"
-	"testing"
-)
-
-func TestSelect(t *testing.T) {
-	tests := []struct {
-		input    interface{}
-		selector func(interface{}) interface{}
-		output   []interface{}
-	}{
-		{[]int{1, 2, 3}, func(i interface{}) interface{} {
-			return i.(int) * 2
-		}, []interface{}{2, 4, 6}},
-		{"str", func(i interface{}) interface{} {
-			return string(i.(rune)) + "1"
-		}, []interface{}{"s1", "t1", "r1"}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).Select(test.selector); !validateQuery(q, test.output) {
-			t.Errorf("From(%v).Select()=%v expected %v", test.input, toSlice(q), test.output)
-		}
-	}
-}
-
-func TestSelectT_PanicWhenSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "SelectT: parameter [selectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).SelectT(func(item, idx int) int { return item + 2 })
-	})
-}
-
-func TestSelectIndexed(t *testing.T) {
-	tests := []struct {
-		input    interface{}
-		selector func(int, interface{}) interface{}
-		output   []interface{}
-	}{
-		{[]int{1, 2, 3}, func(i int, x interface{}) interface{} {
-			return x.(int) * i
-		}, []interface{}{0, 2, 6}},
-		{"str", func(i int, x interface{}) interface{} {
-			return string(x.(rune)) + strconv.Itoa(i)
-		}, []interface{}{"s0", "t1", "r2"}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).SelectIndexed(test.selector); !validateQuery(q, test.output) {
-			t.Errorf("From(%v).SelectIndexed()=%v expected %v", test.input, toSlice(q), test.output)
-		}
-	}
-}
-
-func TestSelectIndexedT_PanicWhenSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "SelectIndexedT: parameter [selectorFn] has a invalid function signature. Expected: 'func(int,T)T', actual: 'func(string,int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).SelectIndexedT(func(index string, item int) int { return item + 2 })
-	})
-}

+ 0 - 265
tool/help/selectmany.go

@@ -1,265 +0,0 @@
-package help
-
-// SelectMany projects each element of a collection to a Query, iterates and
-// flattens the resulting collection into one collection.
-func (q Query) SelectMany(selector func(interface{}) Query) Query {
-	return Query{
-		Iterate: func() Iterator {
-			outernext := q.Iterate()
-			var inner interface{}
-			var innernext Iterator
-
-			return func() (item interface{}, ok bool) {
-				for !ok {
-					if inner == nil {
-						inner, ok = outernext()
-						if !ok {
-							return
-						}
-
-						innernext = selector(inner).Iterate()
-					}
-
-					item, ok = innernext()
-					if !ok {
-						inner = nil
-					}
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// SelectManyT is the typed version of SelectMany.
-//
-//   - selectorFn is of type "func(TSource)Query"
-//
-// NOTE: SelectMany has better performance than SelectManyT.
-func (q Query) SelectManyT(selectorFn interface{}) Query {
-
-	selectManyGenericFunc, err := newGenericFunc(
-		"SelectManyT", "selectorFn", selectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(Query))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	selectorFunc := func(inner interface{}) Query {
-		return selectManyGenericFunc.Call(inner).(Query)
-	}
-	return q.SelectMany(selectorFunc)
-
-}
-
-// SelectManyIndexed projects each element of a collection to a Query, iterates
-// and flattens the resulting collection into one collection.
-//
-// The first argument to selector represents the zero-based index of that
-// element in the source collection. This can be useful if the elements are in a
-// known order and you want to do something with an element at a particular
-// index, for example. It can also be useful if you want to retrieve the index
-// of one or more elements. The second argument to selector represents the
-// element to process.
-func (q Query) SelectManyIndexed(selector func(int, interface{}) Query) Query {
-	return Query{
-		Iterate: func() Iterator {
-			outernext := q.Iterate()
-			index := 0
-			var inner interface{}
-			var innernext Iterator
-
-			return func() (item interface{}, ok bool) {
-				for !ok {
-					if inner == nil {
-						inner, ok = outernext()
-						if !ok {
-							return
-						}
-
-						innernext = selector(index, inner).Iterate()
-						index++
-					}
-
-					item, ok = innernext()
-					if !ok {
-						inner = nil
-					}
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// SelectManyIndexedT is the typed version of SelectManyIndexed.
-//
-//   - selectorFn is of type "func(int,TSource)Query"
-//
-// NOTE: SelectManyIndexed has better performance than SelectManyIndexedT.
-func (q Query) SelectManyIndexedT(selectorFn interface{}) Query {
-
-	selectManyIndexedGenericFunc, err := newGenericFunc(
-		"SelectManyIndexedT", "selectorFn", selectorFn,
-		simpleParamValidator(newElemTypeSlice(new(int), new(genericType)), newElemTypeSlice(new(Query))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	selectorFunc := func(index int, inner interface{}) Query {
-		return selectManyIndexedGenericFunc.Call(index, inner).(Query)
-	}
-
-	return q.SelectManyIndexed(selectorFunc)
-}
-
-// SelectManyBy projects each element of a collection to a Query, iterates and
-// flattens the resulting collection into one collection, and invokes a result
-// selector function on each element therein.
-func (q Query) SelectManyBy(selector func(interface{}) Query,
-	resultSelector func(interface{}, interface{}) interface{}) Query {
-
-	return Query{
-		Iterate: func() Iterator {
-			outernext := q.Iterate()
-			var outer interface{}
-			var innernext Iterator
-
-			return func() (item interface{}, ok bool) {
-				for !ok {
-					if outer == nil {
-						outer, ok = outernext()
-						if !ok {
-							return
-						}
-
-						innernext = selector(outer).Iterate()
-					}
-
-					item, ok = innernext()
-					if !ok {
-						outer = nil
-					}
-				}
-
-				item = resultSelector(item, outer)
-				return
-			}
-		},
-	}
-}
-
-// SelectManyByT is the typed version of SelectManyBy.
-//
-//   - selectorFn is of type "func(TSource)Query"
-//   - resultSelectorFn is of type "func(TSource,TCollection)TResult"
-//
-// NOTE: SelectManyBy has better performance than SelectManyByT.
-func (q Query) SelectManyByT(selectorFn interface{},
-	resultSelectorFn interface{}) Query {
-
-	selectorGenericFunc, err := newGenericFunc(
-		"SelectManyByT", "selectorFn", selectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(Query))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	selectorFunc := func(outer interface{}) Query {
-		return selectorGenericFunc.Call(outer).(Query)
-	}
-
-	resultSelectorGenericFunc, err := newGenericFunc(
-		"SelectManyByT", "resultSelectorFn", resultSelectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType), new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	resultSelectorFunc := func(outer interface{}, item interface{}) interface{} {
-		return resultSelectorGenericFunc.Call(outer, item)
-	}
-
-	return q.SelectManyBy(selectorFunc, resultSelectorFunc)
-}
-
-// SelectManyByIndexed projects each element of a collection to a Query,
-// iterates and flattens the resulting collection into one collection, and
-// invokes a result selector function on each element therein. The index of each
-// source element is used in the intermediate projected form of that element.
-func (q Query) SelectManyByIndexed(selector func(int, interface{}) Query,
-	resultSelector func(interface{}, interface{}) interface{}) Query {
-
-	return Query{
-		Iterate: func() Iterator {
-			outernext := q.Iterate()
-			index := 0
-			var outer interface{}
-			var innernext Iterator
-
-			return func() (item interface{}, ok bool) {
-				for !ok {
-					if outer == nil {
-						outer, ok = outernext()
-						if !ok {
-							return
-						}
-
-						innernext = selector(index, outer).Iterate()
-						index++
-					}
-
-					item, ok = innernext()
-					if !ok {
-						outer = nil
-					}
-				}
-
-				item = resultSelector(item, outer)
-				return
-			}
-		},
-	}
-}
-
-// SelectManyByIndexedT is the typed version of SelectManyByIndexed.
-//
-//   - selectorFn is of type "func(int,TSource)Query"
-//   - resultSelectorFn is of type "func(TSource,TCollection)TResult"
-//
-// NOTE: SelectManyByIndexed has better performance than
-// SelectManyByIndexedT.
-func (q Query) SelectManyByIndexedT(selectorFn interface{},
-	resultSelectorFn interface{}) Query {
-	selectorGenericFunc, err := newGenericFunc(
-		"SelectManyByIndexedT", "selectorFn", selectorFn,
-		simpleParamValidator(newElemTypeSlice(new(int), new(genericType)), newElemTypeSlice(new(Query))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	selectorFunc := func(index int, outer interface{}) Query {
-		return selectorGenericFunc.Call(index, outer).(Query)
-	}
-
-	resultSelectorGenericFunc, err := newGenericFunc(
-		"SelectManyByIndexedT", "resultSelectorFn", resultSelectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType), new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	resultSelectorFunc := func(outer interface{}, item interface{}) interface{} {
-		return resultSelectorGenericFunc.Call(outer, item)
-	}
-
-	return q.SelectManyByIndexed(selectorFunc, resultSelectorFunc)
-}

+ 0 - 154
tool/help/selectmany_test.go

@@ -1,154 +0,0 @@
-package help
-
-import (
-	"strconv"
-	"testing"
-)
-
-func TestSelectMany(t *testing.T) {
-	tests := []struct {
-		input    interface{}
-		selector func(interface{}) Query
-		output   []interface{}
-	}{
-		{[][]int{{1, 2, 3}, {4, 5, 6, 7}}, func(i interface{}) Query {
-			return From(i)
-		}, []interface{}{1, 2, 3, 4, 5, 6, 7}},
-		{[]string{"str", "ing"}, func(i interface{}) Query {
-			return FromString(i.(string))
-		}, []interface{}{'s', 't', 'r', 'i', 'n', 'g'}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).SelectMany(test.selector); !validateQuery(q, test.output) {
-			t.Errorf("From(%v).SelectMany()=%v expected %v", test.input, toSlice(q), test.output)
-		}
-	}
-}
-
-func TestSelectManyT_PanicWhenSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "SelectManyT: parameter [selectorFn] has a invalid function signature. Expected: 'func(T)linq.Query', actual: 'func(int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).SelectManyT(func(item int) int { return item + 2 })
-	})
-}
-
-func TestSelectManyIndexed(t *testing.T) {
-	tests := []struct {
-		input    interface{}
-		selector func(int, interface{}) Query
-		output   []interface{}
-	}{
-		{[][]int{{1, 2, 3}, {4, 5, 6, 7}}, func(i int, x interface{}) Query {
-			if i > 0 {
-				return From(x.([]int)[1:])
-			}
-			return From(x)
-		}, []interface{}{1, 2, 3, 5, 6, 7}},
-		{[]string{"str", "ing"}, func(i int, x interface{}) Query {
-			return FromString(x.(string) + strconv.Itoa(i))
-		}, []interface{}{'s', 't', 'r', '0', 'i', 'n', 'g', '1'}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).SelectManyIndexed(test.selector); !validateQuery(q, test.output) {
-			t.Errorf("From(%v).SelectManyIndexed()=%v expected %v", test.input, toSlice(q), test.output)
-		}
-	}
-}
-
-func TestSelectManyIndexedT_PanicWhenSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "SelectManyIndexedT: parameter [selectorFn] has a invalid function signature. Expected: 'func(int,T)linq.Query', actual: 'func(int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).SelectManyIndexedT(func(item int) int { return item + 2 })
-	})
-}
-
-func TestSelectManyBy(t *testing.T) {
-	tests := []struct {
-		input          interface{}
-		selector       func(interface{}) Query
-		resultSelector func(interface{}, interface{}) interface{}
-		output         []interface{}
-	}{
-		{[][]int{{1, 2, 3}, {4, 5, 6, 7}}, func(i interface{}) Query {
-			return From(i)
-		}, func(x interface{}, y interface{}) interface{} {
-			return x.(int) + 1
-		}, []interface{}{2, 3, 4, 5, 6, 7, 8}},
-		{[]string{"str", "ing"}, func(i interface{}) Query {
-			return FromString(i.(string))
-		}, func(x interface{}, y interface{}) interface{} {
-			return string(x.(rune)) + "_"
-		}, []interface{}{"s_", "t_", "r_", "i_", "n_", "g_"}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).SelectManyBy(test.selector, test.resultSelector); !validateQuery(q, test.output) {
-			t.Errorf("From(%v).SelectManyBy()=%v expected %v", test.input, toSlice(q), test.output)
-		}
-	}
-}
-
-func TestSelectManyByT_PanicWhenSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "SelectManyByT: parameter [selectorFn] has a invalid function signature. Expected: 'func(T)linq.Query', actual: 'func(int)interface {}'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).SelectManyByT(func(item int) interface{} { return item + 2 }, 2)
-	})
-}
-
-func TestSelectManyByT_PanicWhenResultSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "SelectManyByT: parameter [resultSelectorFn] has a invalid function signature. Expected: 'func(T,T)T', actual: 'func()'", func() {
-		From([][]int{{1, 1, 1, 2}, {1, 2, 3, 4, 2}}).SelectManyByT(
-			func(item interface{}) Query { return From(item) },
-			func() {},
-		)
-	})
-}
-
-func TestSelectManyIndexedBy(t *testing.T) {
-	tests := []struct {
-		input          interface{}
-		selector       func(int, interface{}) Query
-		resultSelector func(interface{}, interface{}) interface{}
-		output         []interface{}
-	}{
-		{[][]int{{1, 2, 3}, {4, 5, 6, 7}}, func(i int, x interface{}) Query {
-			if i == 0 {
-				return From([]int{10, 20, 30})
-			}
-			return From(x)
-		}, func(x interface{}, y interface{}) interface{} {
-			return x.(int) + 1
-		}, []interface{}{11, 21, 31, 5, 6, 7, 8}},
-		{[]string{"st", "ng"}, func(i int, x interface{}) Query {
-			if i == 0 {
-				return FromString(x.(string) + "r")
-			}
-			return FromString("i" + x.(string))
-		}, func(x interface{}, y interface{}) interface{} {
-			return string(x.(rune)) + "_"
-		}, []interface{}{"s_", "t_", "r_", "i_", "n_", "g_"}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).SelectManyByIndexed(test.selector, test.resultSelector); !validateQuery(q, test.output) {
-			t.Errorf("From(%v).SelectManyIndexedBy()=%v expected %v", test.input, toSlice(q), test.output)
-		}
-	}
-}
-
-func TestSelectManyIndexedByT_PanicWhenSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "SelectManyByIndexedT: parameter [selectorFn] has a invalid function signature. Expected: 'func(int,T)linq.Query', actual: 'func(int)interface {}'", func() {
-		From([][]int{{1, 1, 1, 2}, {1, 2, 3, 4, 2}}).SelectManyByIndexedT(
-			func(item int) interface{} { return item + 2 },
-			2,
-		)
-	})
-}
-
-func TestSelectManyIndexedByT_PanicWhenResultSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "SelectManyByIndexedT: parameter [resultSelectorFn] has a invalid function signature. Expected: 'func(T,T)T', actual: 'func()'", func() {
-		From([][]int{{1, 1, 1, 2}, {1, 2, 3, 4, 2}}).SelectManyByIndexedT(
-			func(index int, item interface{}) Query { return From(item) },
-			func() {},
-		)
-	})
-}

+ 0 - 83
tool/help/setup_test.go

@@ -1,83 +0,0 @@
-package help
-
-import "testing"
-
-import "fmt"
-
-type foo struct {
-	f1 int
-	f2 bool
-	f3 string
-}
-
-func (f foo) Iterate() Iterator {
-	i := 0
-
-	return func() (item interface{}, ok bool) {
-		switch i {
-		case 0:
-			item = f.f1
-			ok = true
-		case 1:
-			item = f.f2
-			ok = true
-		case 2:
-			item = f.f3
-			ok = true
-		default:
-			ok = false
-		}
-
-		i++
-		return
-	}
-}
-
-func (f foo) CompareTo(c Comparable) int {
-	a, b := f.f1, c.(foo).f1
-
-	if a < b {
-		return -1
-	} else if a > b {
-		return 1
-	}
-
-	return 0
-}
-
-func toSlice(q Query) (result []interface{}) {
-	next := q.Iterate()
-
-	for item, ok := next(); ok; item, ok = next() {
-		result = append(result, item)
-	}
-
-	return
-}
-
-func validateQuery(q Query, output []interface{}) bool {
-	next := q.Iterate()
-
-	for _, oitem := range output {
-		qitem, _ := next()
-
-		if oitem != qitem {
-			return false
-		}
-	}
-
-	_, ok := next()
-	_, ok2 := next()
-	return !(ok || ok2)
-}
-
-func mustPanicWithError(t *testing.T, expectedErr string, f func()) {
-	defer func() {
-		r := recover()
-		err := fmt.Sprintf("%s", r)
-		if err != expectedErr {
-			t.Fatalf("got=[%v] expected=[%v]", err, expectedErr)
-		}
-	}()
-	f()
-}

+ 0 - 134
tool/help/skip.go

@@ -1,134 +0,0 @@
-package help
-
-// Skip bypasses a specified number of elements in a collection and then returns
-// the remaining elements.
-func (q Query) Skip(count int) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			n := count
-
-			return func() (item interface{}, ok bool) {
-				for ; n > 0; n-- {
-					item, ok = next()
-					if !ok {
-						return
-					}
-				}
-
-				return next()
-			}
-		},
-	}
-}
-
-// SkipWhile bypasses elements in a collection as long as a specified condition
-// is true and then returns the remaining elements.
-//
-// This method tests each element by using predicate and skips the element if
-// the result is true. After the predicate function returns false for an
-// element, that element and the remaining elements in source are returned and
-// there are no more invocations of predicate.
-func (q Query) SkipWhile(predicate func(interface{}) bool) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			ready := false
-
-			return func() (item interface{}, ok bool) {
-				for !ready {
-					item, ok = next()
-					if !ok {
-						return
-					}
-
-					ready = !predicate(item)
-					if ready {
-						return
-					}
-				}
-
-				return next()
-			}
-		},
-	}
-}
-
-// SkipWhileT is the typed version of SkipWhile.
-//
-//   - predicateFn is of type "func(TSource)bool"
-//
-// NOTE: SkipWhile has better performance than SkipWhileT.
-func (q Query) SkipWhileT(predicateFn interface{}) Query {
-
-	predicateGenericFunc, err := newGenericFunc(
-		"SkipWhileT", "predicateFn", predicateFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(bool))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	predicateFunc := func(item interface{}) bool {
-		return predicateGenericFunc.Call(item).(bool)
-	}
-
-	return q.SkipWhile(predicateFunc)
-}
-
-// SkipWhileIndexed bypasses elements in a collection as long as a specified
-// condition is true and then returns the remaining elements. The element's
-// index is used in the logic of the predicate function.
-//
-// This method tests each element by using predicate and skips the element if
-// the result is true. After the predicate function returns false for an
-// element, that element and the remaining elements in source are returned and
-// there are no more invocations of predicate.
-func (q Query) SkipWhileIndexed(predicate func(int, interface{}) bool) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			ready := false
-			index := 0
-
-			return func() (item interface{}, ok bool) {
-				for !ready {
-					item, ok = next()
-					if !ok {
-						return
-					}
-
-					ready = !predicate(index, item)
-					if ready {
-						return
-					}
-
-					index++
-				}
-
-				return next()
-			}
-		},
-	}
-}
-
-// SkipWhileIndexedT is the typed version of SkipWhileIndexed.
-//
-//   - predicateFn is of type "func(int,TSource)bool"
-//
-// NOTE: SkipWhileIndexed has better performance than SkipWhileIndexedT.
-func (q Query) SkipWhileIndexedT(predicateFn interface{}) Query {
-	predicateGenericFunc, err := newGenericFunc(
-		"SkipWhileIndexedT", "predicateFn", predicateFn,
-		simpleParamValidator(newElemTypeSlice(new(int), new(genericType)), newElemTypeSlice(new(bool))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	predicateFunc := func(index int, item interface{}) bool {
-		return predicateGenericFunc.Call(index, item).(bool)
-	}
-
-	return q.SkipWhileIndexed(predicateFunc)
-}

+ 0 - 87
tool/help/skip_test.go

@@ -1,87 +0,0 @@
-package help
-
-import "testing"
-
-func TestSkip(t *testing.T) {
-	tests := []struct {
-		input  interface{}
-		output []interface{}
-	}{
-		{[]int{1, 2}, []interface{}{}},
-		{[]int{1, 2, 2, 3, 1}, []interface{}{3, 1}},
-		{[9]int{1, 1, 1, 2, 1, 2, 3, 4, 2}, []interface{}{2, 1, 2, 3, 4, 2}},
-		{"sstr", []interface{}{'r'}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).Skip(3); !validateQuery(q, test.output) {
-			t.Errorf("From(%v).Skip(3)=%v expected %v", test.input, toSlice(q), test.output)
-		}
-	}
-}
-
-func TestSkipWhile(t *testing.T) {
-	tests := []struct {
-		input     interface{}
-		predicate func(interface{}) bool
-		output    []interface{}
-	}{
-		{[]int{1, 2}, func(i interface{}) bool {
-			return i.(int) < 3
-		}, []interface{}{}},
-		{[]int{4, 1, 2}, func(i interface{}) bool {
-			return i.(int) < 3
-		}, []interface{}{4, 1, 2}},
-		{[9]int{1, 1, 1, 2, 1, 2, 3, 4, 2}, func(i interface{}) bool {
-			return i.(int) < 3
-		}, []interface{}{3, 4, 2}},
-		{"sstr", func(i interface{}) bool {
-			return i.(rune) == 's'
-		}, []interface{}{'t', 'r'}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).SkipWhile(test.predicate); !validateQuery(q, test.output) {
-			t.Errorf("From(%v).SkipWhile()=%v expected %v", test.input, toSlice(q), test.output)
-		}
-	}
-}
-
-func TestSkipWhileT_PanicWhenPredicateFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "SkipWhileT: parameter [predicateFn] has a invalid function signature. Expected: 'func(T)bool', actual: 'func(int,int)bool'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).SkipWhileT(func(item int, x int) bool { return item == 1 })
-	})
-}
-
-func TestSkipWhileIndexed(t *testing.T) {
-	tests := []struct {
-		input     interface{}
-		predicate func(int, interface{}) bool
-		output    []interface{}
-	}{
-		{[]int{1, 2}, func(i int, x interface{}) bool {
-			return x.(int) < 3
-		}, []interface{}{}},
-		{[]int{4, 1, 2}, func(i int, x interface{}) bool {
-			return x.(int) < 3
-		}, []interface{}{4, 1, 2}},
-		{[9]int{1, 1, 1, 2, 1, 2, 3, 4, 2}, func(i int, x interface{}) bool {
-			return x.(int) < 2 || i < 5
-		}, []interface{}{2, 3, 4, 2}},
-		{"sstr", func(i int, x interface{}) bool {
-			return x.(rune) == 's' && i < 1
-		}, []interface{}{'s', 't', 'r'}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).SkipWhileIndexed(test.predicate); !validateQuery(q, test.output) {
-			t.Errorf("From(%v).SkipWhileIndexed()=%v expected %v", test.input, toSlice(q), test.output)
-		}
-	}
-}
-
-func TestSkipWhileIndexedT_PanicWhenPredicateFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "SkipWhileIndexedT: parameter [predicateFn] has a invalid function signature. Expected: 'func(int,T)bool', actual: 'func(int,int,int)bool'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).SkipWhileIndexedT(func(item int, x int, y int) bool { return item == 1 })
-	})
-}

+ 0 - 129
tool/help/take.go

@@ -1,129 +0,0 @@
-package help
-
-// Take returns a specified number of contiguous elements from the start of a
-// collection.
-func (q Query) Take(count int) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			n := count
-
-			return func() (item interface{}, ok bool) {
-				if n <= 0 {
-					return
-				}
-
-				n--
-				return next()
-			}
-		},
-	}
-}
-
-// TakeWhile returns elements from a collection as long as a specified condition
-// is true, and then skips the remaining elements.
-func (q Query) TakeWhile(predicate func(interface{}) bool) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			done := false
-
-			return func() (item interface{}, ok bool) {
-				if done {
-					return
-				}
-
-				item, ok = next()
-				if !ok {
-					done = true
-					return
-				}
-
-				if predicate(item) {
-					return
-				}
-
-				done = true
-				return nil, false
-			}
-		},
-	}
-}
-
-// TakeWhileT is the typed version of TakeWhile.
-//
-//   - predicateFn is of type "func(TSource)bool"
-//
-// NOTE: TakeWhile has better performance than TakeWhileT.
-func (q Query) TakeWhileT(predicateFn interface{}) Query {
-
-	predicateGenericFunc, err := newGenericFunc(
-		"TakeWhileT", "predicateFn", predicateFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(bool))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	predicateFunc := func(item interface{}) bool {
-		return predicateGenericFunc.Call(item).(bool)
-	}
-
-	return q.TakeWhile(predicateFunc)
-}
-
-// TakeWhileIndexed returns elements from a collection as long as a specified
-// condition is true. The element's index is used in the logic of the predicate
-// function. The first argument of predicate represents the zero-based index of
-// the element within collection. The second argument represents the element to
-// test.
-func (q Query) TakeWhileIndexed(predicate func(int, interface{}) bool) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			done := false
-			index := 0
-
-			return func() (item interface{}, ok bool) {
-				if done {
-					return
-				}
-
-				item, ok = next()
-				if !ok {
-					done = true
-					return
-				}
-
-				if predicate(index, item) {
-					index++
-					return
-				}
-
-				done = true
-				return nil, false
-			}
-		},
-	}
-}
-
-// TakeWhileIndexedT is the typed version of TakeWhileIndexed.
-//
-//   - predicateFn is of type "func(int,TSource)bool"
-//
-// NOTE: TakeWhileIndexed has better performance than TakeWhileIndexedT.
-func (q Query) TakeWhileIndexedT(predicateFn interface{}) Query {
-	whereFunc, err := newGenericFunc(
-		"TakeWhileIndexedT", "predicateFn", predicateFn,
-		simpleParamValidator(newElemTypeSlice(new(int), new(genericType)), newElemTypeSlice(new(bool))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	predicateFunc := func(index int, item interface{}) bool {
-		return whereFunc.Call(index, item).(bool)
-	}
-
-	return q.TakeWhileIndexed(predicateFunc)
-}

+ 0 - 80
tool/help/take_test.go

@@ -1,80 +0,0 @@
-package help
-
-import "testing"
-
-func TestTake(t *testing.T) {
-	tests := []struct {
-		input  interface{}
-		output []interface{}
-	}{
-		{[]int{1, 2, 2, 3, 1}, []interface{}{1, 2, 2}},
-		{[9]int{1, 1, 1, 2, 1, 2, 3, 4, 2}, []interface{}{1, 1, 1}},
-		{"sstr", []interface{}{'s', 's', 't'}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).Take(3); !validateQuery(q, test.output) {
-			t.Errorf("From(%v).Take(3)=%v expected %v", test.input, toSlice(q), test.output)
-		}
-	}
-}
-
-func TestTakeWhile(t *testing.T) {
-	tests := []struct {
-		input     interface{}
-		predicate func(interface{}) bool
-		output    []interface{}
-	}{
-		{[]int{1, 1, 1, 2, 1, 2}, func(i interface{}) bool {
-			return i.(int) < 3
-		}, []interface{}{1, 1, 1, 2, 1, 2}},
-		{[9]int{1, 1, 1, 2, 1, 2, 3, 4, 2}, func(i interface{}) bool {
-			return i.(int) < 3
-		}, []interface{}{1, 1, 1, 2, 1, 2}},
-		{"sstr", func(i interface{}) bool {
-			return i.(rune) == 's'
-		}, []interface{}{'s', 's'}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).TakeWhile(test.predicate); !validateQuery(q, test.output) {
-			t.Errorf("From(%v).TakeWhile()=%v expected %v", test.input, toSlice(q), test.output)
-		}
-	}
-}
-
-func TestTakeWhileT_PanicWhenPredicateFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "TakeWhileT: parameter [predicateFn] has a invalid function signature. Expected: 'func(T)bool', actual: 'func(int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).TakeWhileT(func(item int) int { return item + 2 })
-	})
-}
-
-func TestTakeWhileIndexed(t *testing.T) {
-	tests := []struct {
-		input     interface{}
-		predicate func(int, interface{}) bool
-		output    []interface{}
-	}{
-		{[]int{1, 1, 1, 2}, func(i int, x interface{}) bool {
-			return x.(int) < 2 || i < 5
-		}, []interface{}{1, 1, 1, 2}},
-		{[9]int{1, 1, 1, 2, 1, 2, 3, 4, 2}, func(i int, x interface{}) bool {
-			return x.(int) < 2 || i < 5
-		}, []interface{}{1, 1, 1, 2, 1}},
-		{"sstr", func(i int, x interface{}) bool {
-			return x.(rune) == 's' && i < 1
-		}, []interface{}{'s'}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).TakeWhileIndexed(test.predicate); !validateQuery(q, test.output) {
-			t.Errorf("From(%v).TakeWhileIndexed()=%v expected %v", test.input, toSlice(q), test.output)
-		}
-	}
-}
-
-func TestTakeWhileIndexedT_PanicWhenPredicateFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "TakeWhileIndexedT: parameter [predicateFn] has a invalid function signature. Expected: 'func(int,T)bool', actual: 'func(int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).TakeWhileIndexedT(func(item int) int { return item + 2 })
-	})
-}

+ 0 - 40
tool/help/union.go

@@ -1,40 +0,0 @@
-package help
-
-// Union produces the set union of two collections.
-//
-// This method excludes duplicates from the return set. This is different
-// behavior to the Concat method, which returns all the elements in the input
-// collection including duplicates.
-func (q Query) Union(q2 Query) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			next2 := q2.Iterate()
-
-			set := make(map[interface{}]bool)
-			use1 := true
-
-			return func() (item interface{}, ok bool) {
-				if use1 {
-					for item, ok = next(); ok; item, ok = next() {
-						if _, has := set[item]; !has {
-							set[item] = true
-							return
-						}
-					}
-
-					use1 = false
-				}
-
-				for item, ok = next2(); ok; item, ok = next2() {
-					if _, has := set[item]; !has {
-						set[item] = true
-						return
-					}
-				}
-
-				return
-			}
-		},
-	}
-}

+ 0 - 13
tool/help/union_test.go

@@ -1,13 +0,0 @@
-package help
-
-import "testing"
-
-func TestUnion(t *testing.T) {
-	input1 := []int{1, 2, 3}
-	input2 := []int{2, 4, 5, 1}
-	want := []interface{}{1, 2, 3, 4, 5}
-
-	if q := From(input1).Union(From(input2)); !validateQuery(q, want) {
-		t.Errorf("From(%v).Union(%v)=%v expected %v", input1, input2, toSlice(q), want)
-	}
-}

+ 0 - 90
tool/help/where.go

@@ -1,90 +0,0 @@
-package help
-
-// Where filters a collection of values based on a predicate.
-func (q Query) Where(predicate func(interface{}) bool) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-
-			return func() (item interface{}, ok bool) {
-				for item, ok = next(); ok; item, ok = next() {
-					if predicate(item) {
-						return
-					}
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// WhereT is the typed version of Where.
-//
-//   - predicateFn is of type "func(TSource)bool"
-//
-// NOTE: Where has better performance than WhereT.
-func (q Query) WhereT(predicateFn interface{}) Query {
-
-	predicateGenericFunc, err := newGenericFunc(
-		"WhereT", "predicateFn", predicateFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType)), newElemTypeSlice(new(bool))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	predicateFunc := func(item interface{}) bool {
-		return predicateGenericFunc.Call(item).(bool)
-	}
-
-	return q.Where(predicateFunc)
-}
-
-// WhereIndexed filters a collection of values based on a predicate. Each
-// element's index is used in the logic of the predicate function.
-//
-// The first argument represents the zero-based index of the element within
-// collection. The second argument of predicate represents the element to test.
-func (q Query) WhereIndexed(predicate func(int, interface{}) bool) Query {
-	return Query{
-		Iterate: func() Iterator {
-			next := q.Iterate()
-			index := 0
-
-			return func() (item interface{}, ok bool) {
-				for item, ok = next(); ok; item, ok = next() {
-					if predicate(index, item) {
-						index++
-						return
-					}
-
-					index++
-				}
-
-				return
-			}
-		},
-	}
-}
-
-// WhereIndexedT is the typed version of WhereIndexed.
-//
-//   - predicateFn is of type "func(int,TSource)bool"
-//
-// NOTE: WhereIndexed has better performance than WhereIndexedT.
-func (q Query) WhereIndexedT(predicateFn interface{}) Query {
-	predicateGenericFunc, err := newGenericFunc(
-		"WhereIndexedT", "predicateFn", predicateFn,
-		simpleParamValidator(newElemTypeSlice(new(int), new(genericType)), newElemTypeSlice(new(bool))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	predicateFunc := func(index int, item interface{}) bool {
-		return predicateGenericFunc.Call(index, item).(bool)
-	}
-
-	return q.WhereIndexed(predicateFunc)
-}

+ 0 - 60
tool/help/where_test.go

@@ -1,60 +0,0 @@
-package help
-
-import "testing"
-
-func TestWhere(t *testing.T) {
-	tests := []struct {
-		input     interface{}
-		predicate func(interface{}) bool
-		output    []interface{}
-	}{
-		{[9]int{1, 1, 1, 2, 1, 2, 3, 4, 2}, func(i interface{}) bool {
-			return i.(int) >= 3
-		}, []interface{}{3, 4}},
-		{"sstr", func(i interface{}) bool {
-			return i.(rune) != 's'
-		}, []interface{}{'t', 'r'}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).Where(test.predicate); !validateQuery(q, test.output) {
-			t.Errorf("From(%v).Where()=%v expected %v", test.input, toSlice(q), test.output)
-		}
-	}
-}
-
-func TestWhereT_PanicWhenPredicateFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "WhereT: parameter [predicateFn] has a invalid function signature. Expected: 'func(T)bool', actual: 'func(int)int'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).WhereT(func(item int) int { return item + 2 })
-	})
-}
-
-func TestWhereIndexed(t *testing.T) {
-	tests := []struct {
-		input     interface{}
-		predicate func(int, interface{}) bool
-		output    []interface{}
-	}{
-		{[9]int{1, 1, 1, 2, 1, 2, 3, 4, 2}, func(i int, x interface{}) bool {
-			return x.(int) < 4 && i > 4
-		}, []interface{}{2, 3, 2}},
-		{"sstr", func(i int, x interface{}) bool {
-			return x.(rune) != 's' || i == 1
-		}, []interface{}{'s', 't', 'r'}},
-		{"abcde", func(i int, _ interface{}) bool {
-			return i < 2
-		}, []interface{}{'a', 'b'}},
-	}
-
-	for _, test := range tests {
-		if q := From(test.input).WhereIndexed(test.predicate); !validateQuery(q, test.output) {
-			t.Errorf("From(%v).WhereIndexed()=%v expected %v", test.input, toSlice(q), test.output)
-		}
-	}
-}
-
-func TestWhereIndexedT_PanicWhenPredicateFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "WhereIndexedT: parameter [predicateFn] has a invalid function signature. Expected: 'func(int,T)bool', actual: 'func(string)'", func() {
-		From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).WhereIndexedT(func(item string) {})
-	})
-}

+ 0 - 55
tool/help/zip.go

@@ -1,55 +0,0 @@
-package help
-
-// Zip applies a specified function to the corresponding elements of two
-// collections, producing a collection of the results.
-//
-// The method steps through the two input collections, applying function
-// resultSelector to corresponding elements of the two collections. The method
-// returns a collection of the values that are returned by resultSelector. If
-// the input collections do not have the same number of elements, the method
-// combines elements until it reaches the end of one of the collections. For
-// example, if one collection has three elements and the other one has four, the
-// result collection has only three elements.
-func (q Query) Zip(q2 Query,
-	resultSelector func(interface{}, interface{}) interface{}) Query {
-
-	return Query{
-		Iterate: func() Iterator {
-			next1 := q.Iterate()
-			next2 := q2.Iterate()
-
-			return func() (item interface{}, ok bool) {
-				item1, ok1 := next1()
-				item2, ok2 := next2()
-
-				if ok1 && ok2 {
-					return resultSelector(item1, item2), true
-				}
-
-				return nil, false
-			}
-		},
-	}
-}
-
-// ZipT is the typed version of Zip.
-//
-//   - resultSelectorFn is of type "func(TFirst,TSecond)TResult"
-//
-// NOTE: Zip has better performance than ZipT.
-func (q Query) ZipT(q2 Query,
-	resultSelectorFn interface{}) Query {
-	resultSelectorGenericFunc, err := newGenericFunc(
-		"ZipT", "resultSelectorFn", resultSelectorFn,
-		simpleParamValidator(newElemTypeSlice(new(genericType), new(genericType)), newElemTypeSlice(new(genericType))),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	resultSelectorFunc := func(item1 interface{}, item2 interface{}) interface{} {
-		return resultSelectorGenericFunc.Call(item1, item2)
-	}
-
-	return q.Zip(q2, resultSelectorFunc)
-}

+ 0 - 26
tool/help/zip_test.go

@@ -1,26 +0,0 @@
-package help
-
-import "testing"
-
-func TestZip(t *testing.T) {
-	input1 := []int{1, 2, 3}
-	input2 := []int{2, 4, 5, 1}
-	want := []interface{}{3, 6, 8}
-
-	if q := From(input1).Zip(From(input2), func(i, j interface{}) interface{} {
-		return i.(int) + j.(int)
-	}); !validateQuery(q, want) {
-		t.Errorf("From(%v).Zip(%v)=%v expected %v", input1, input2, toSlice(q), want)
-	}
-}
-
-func TestZipT_PanicWhenResultSelectorFnIsInvalid(t *testing.T) {
-	mustPanicWithError(t, "ZipT: parameter [resultSelectorFn] has a invalid function signature. Expected: 'func(T,T)T', actual: 'func(int,int,int)int'", func() {
-		input1 := []int{1, 2, 3}
-		input2 := []int{2, 4, 5, 1}
-
-		From(input1).ZipT(From(input2), func(i, j, k int) int {
-			return i + j
-		})
-	})
-}

+ 0 - 22
tool/signature_request/request_test.go

@@ -1,22 +0,0 @@
-package signature_request
-
-import (
-	"encoding/json"
-	"testing"
-)
-
-func TestDingTalkAlert(t *testing.T) {
-	var msg DingTalkTextAlert
-	msg.MsgType = "text"
-	msg.Text.Content = "测试"
-
-	js, _ := json.Marshal(msg)
-
-	alert := DingTalkAlert(
-		"xxx",
-		"xxx",
-		js,
-	)
-
-	t.Log(alert)
-}