sliceutil

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MIT Imports: 3 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Back

func Back[T any](srcs []T) (T, []T)

配列の後尾を切り取る

func Chunk

func Chunk[T any](srcs []T, size int) [][]T

配列の分割

func Contains

func Contains[T comparable](srcs []T, e T) bool

配列の値の存在確認

func ContainsFunc added in v1.5.0

func ContainsFunc[T any](srcs []T, fn func(src T) bool) bool

func Delete

func Delete[T any](srcs []T, i int) []T

配列の任意の値を削除する

func Excludes

func Excludes[T comparable](base []T, target []T) []T

配列で指定したbaseの中でtargetに含まれない値の配列を取得

func Filter added in v1.5.0

func Filter[T any](srcs []T, fn func(src T) bool) []T

func Insert

func Insert[T any](srcs []T, v T, i int) []T

配列の任意の場所に挿入する

func Map added in v1.5.0

func Map[T, E any](srcs []T, fn func(src T) E) []E

func Reduce added in v1.5.0

func Reduce[T, E any](srcs []T, fn func(dst E, src T) E) E

func Shift

func Shift[T any](srcs []T) (T, []T)

配列の先頭を切り取る

func Shuffle

func Shuffle[T any](srcs []T) []T

配列をシャッフルする

func Uniq

func Uniq[T comparable](srcs []T) []T

配列の重複を排除する

Types

type Stream

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

func StreamOf

func StreamOf(slice any) *Stream

func (*Stream) Contains

func (s *Stream) Contains(fn any) bool

dst := StreamOf(hoges).

    Contains(func(hoge *Hoge) bool {
		return hoge.ID == "abc"
	})

要素の存在確認

func (*Stream) Count

func (s *Stream) Count() int

dst := StreamOf(hoges).Count()

要素数を取得

func (*Stream) Filter

func (s *Stream) Filter(fn any) *Stream

dst := StreamOf(hoges).

Filter(func(hoge *Hoge) bool {
	return hoge.Num > 3
}).Out().([]*Hoge)

要素のフィルタリング

func (*Stream) ForEach

func (s *Stream) ForEach(fn any) *Stream

dst := StreamOf(hoges).

    ForEach(func(hoge *Hoge, i int) {
		hoge.ID = "abc"
	})

要素のループ

func (*Stream) Map

func (s *Stream) Map(fn any) *Stream

dst := StreamOf(hoges).

Map(func(hoge *Hoge) string {
	return hoge.ID
}).Out().([]string)

要素の変換

func (*Stream) Out

func (s *Stream) Out() any

結果を出力する

func (*Stream) Reduce

func (s *Stream) Reduce(fn any) any

dst := StreamOf(hoges).

Reduce(func(dst int, num int) int {
	return dst + num
}).(int)

要素の集計

func (*Stream) Sort

func (s *Stream) Sort(fn any) *Stream

dst := StreamOf(hoges).

Sort(func(prev, next *Hoge) bool {
	return prev.SortNum < next.SortNum
}).Out().([]*Hoge)

ソート

Jump to

Keyboard shortcuts

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