Skip to content

Releases: murosan/gollect

v1.4.2

07 Jul 15:57
af5ecb8
Compare
Choose a tag to compare

fix bug #8 (related: #7 )

v1.4.1

16 Jun 03:05
96cde03
Compare
Choose a tag to compare

bug fix #7

v1.4.0

05 Aug 15:22
0a1c1d5
Compare
Choose a tag to compare

Go 1.18

⚠️ This version does not have backward compatibility ⚠️

Features

Generics Support

You can now use generics.

package lib

import "golang.org/x/exp/constraints"

func Max[T constraints.Ordered](a, b T) T {
	if a > b {
		return a
	}
	return b
}

func Min[T constraints.Ordered](a, b T) T {
	if a < b {
		return a
	}
	return b
}

New configuration field (thirdPartyPackagePathPrefixes)

# default values are the libraries that can use at AtCoder Online Judge system
# https://img.atcoder.jp/file/language-update/language-list.html
thirdPartyPackagePathPrefixes:
  - golang.org/x/exp/constraints
  - github.com/emirpasic/gods
  - github.com/liyue201/gostl
  - gonum.org/v1/gonum

Input:

package main

import (
	"fmt"
	"golang.org/x/exp/constraints"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	fmt.Println(Max(a, b))
}

func Min[T constraints.Ordered](a, b T) T {
	if a < b {
		return a
	}
	return b
}

func Max[T constraints.Ordered](a, b T) T {
	if a > b {
		return a
	}
	return b
}

Output:

Configured package golang.org/x/exp/constraints will be left.

package main

import (
	"fmt"
	"golang.org/x/exp/constraints"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	fmt.Println(Max(a, b))
}

func Max[T constraints.Ordered](a, b T) T {
	if a > b {
		return a
	}
	return b
}

Leave Interface Methods embed in Struct field

If Interface types are embedded in struct field, the methods that implements the interfaces will be left.

Input:

package main

import "sort"

type S[T ~int | ~string] struct {
	sort.Interface
	data []T
}

func (s *S[T]) Len() int           { return len(s.data) }
func (s *S[T]) Less(i, j int) bool { return s.data[i] < s.data[j] }
func (s *S[T]) Swap(i, j int)      { s.data[i], s.data[j] = s.data[j], s.data[i] }
func (*S[T]) Unused()              {} // will be removed

func main() {
	var s S[int]
	sort.Sort(&s)
}

Output:

package main

import "sort"

type S[T ~int | ~string] struct {
	sort.Interface
	data []T
}

func (s *S[T]) Len() int           { return len(s.data) }
func (s *S[T]) Less(i, j int) bool { return s.data[i] < s.data[j] }
func (s *S[T]) Swap(i, j int)      { s.data[i], s.data[j] = s.data[j], s.data[i] }

func main() {
	var s S[int]
	sort.Sort(&s)
}

v1.3.0

22 Apr 16:23
Compare
Choose a tag to compare

Go 1.17

breaking changes

  • global declaration named with underscore now will be left

input

package main

var (
	scanner = &Scanner{}
	_ = sc.ReadInt() // drop first input
	s = sc.ReadString()
)

func main() { ... }

type Scanner struct { ... }
func (sc *Scanner) ReadInt() int { ... }
func (sc *Scanner) ReadString() string { ... }

output v1.2.0

package main

var (
	scanner = &Scanner{}
	s = sc.ReadString()
)

func main() { ... }

type Scanner struct { ... }
func (sc *Scanner) ReadString() string { ... }

output v1.3.0

package main

var (
	scanner = &Scanner{}
	_ = sc.ReadInt() // drop first input
	s = sc.ReadString()
)

func main() { ... }

type Scanner struct { ... }
func (sc *Scanner) ReadInt() int { ... }
func (sc *Scanner) ReadString() string { ... }

v1.2.0

12 Mar 11:46
df6283e
Compare
Choose a tag to compare

Go 1.16

v1.1.0

22 Aug 09:48
Compare
Choose a tag to compare

Go 1.15

maintenance release

29 Jun 06:47
4810204
Compare
Choose a tag to compare
  • Fixed: the imports to disappear even if they are necessary. #4