sliceutil

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

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

Contains ... 配列に要素が含まれているか

func ContainsFunc added in v1.5.0

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

ContainsFunc ... 配列に要素が含まれているか

func First added in v1.5.1

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

First ... 配列の先頭の要素を取得

func Last added in v1.5.1

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

Last ... 配列の最後の要素を取得

func Reduce added in v1.5.0

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

Reduce ... reduce

func Some added in v1.5.1

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

Some ... ContainsFunc のエイリアス

Types

type Slice added in v1.5.1

type Slice[T any] []T

func Chunk

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

Chunk ... 配列の分割

func Delete

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

Delete ... 配列の任意の値をindex指定で削除する

func Excludes

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

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

func Filter added in v1.5.0

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

Filter ... 条件に合う要素のみを抽出する

func FilterMap added in v1.5.8

func FilterMap[T, E any](srcs []T, fn func(src T) (bool, E)) Slice[E]

FilterMap ... Filter して Map する

func FilterMapWithIndex added in v1.5.8

func FilterMapWithIndex[T, E any](srcs []T, fn func(index int) (bool, E)) Slice[E]

FilterMapWithIndex ... Filter して Map する

func FilterWithIndex added in v1.5.1

func FilterWithIndex[T any](srcs []T, fn func(index int) bool) Slice[T]

FilterWithIndex ... 条件に合う要素のみを抽出する

func ForEach added in v1.5.1

func ForEach[T any](srcs []T, fn func(src T)) Slice[T]

ForEach ... ループ

func Insert

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

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

func Map added in v1.5.0

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

Map ... 配列の要素を変換する

func MapWithIndex added in v1.5.1

func MapWithIndex[T, E any](srcs []T, fn func(index int) E) Slice[E]

MapWithIndex ... 配列の要素を変換する

func NewSlice added in v1.5.1

func NewSlice[T any](srcs []T) Slice[T]

NewSlice ... constructor

func Pop added in v1.5.1

func Pop[T any](srcs []T) (T, Slice[T])

Pop ... 配列の後尾を切り取る (破壊)

func Shift

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

Shift ... 配列の先頭を切り取る (破壊)

func Shuffle

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

Shuffle ... 配列をシャッフルする

func Sort added in v1.5.1

func Sort[T any](srcs []T, fn func(i, j int) bool) Slice[T]

Sort ... ソート

func Uniq

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

Uniq ... 配列の重複を排除する

func (Slice[T]) Chunk added in v1.5.1

func (s Slice[T]) Chunk(size int) []Slice[T]

Chunk ... 配列の分割

func (Slice[T]) ContainsFunc added in v1.5.1

func (s Slice[T]) ContainsFunc(fn func(src T) bool) bool

ContainsFunc ... 配列に要素が含まれているか

func (Slice[T]) Delete added in v1.5.1

func (s Slice[T]) Delete(i int) Slice[T]

Delete ... 配列の任意の値をindex指定で削除する

func (Slice[T]) Filter added in v1.5.1

func (s Slice[T]) Filter(fn func(src T) bool) Slice[T]

Filter ... 条件に合う要素のみを抽出する

func (Slice[T]) FilterWithIndex added in v1.5.1

func (s Slice[T]) FilterWithIndex(fn func(index int) bool) Slice[T]

FilterWithIndex ... 条件に合う要素のみを抽出する

func (Slice[T]) First added in v1.5.1

func (s Slice[T]) First() T

First ... 配列の先頭の要素を取得

func (Slice[T]) ForEach added in v1.5.1

func (s Slice[T]) ForEach(fn func(src T)) Slice[T]

ForEach ... ループ

func (Slice[T]) Insert added in v1.5.1

func (s Slice[T]) Insert(i int, v ...T) Slice[T]

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

func (Slice[T]) Last added in v1.5.1

func (s Slice[T]) Last() T

Last ... 配列の最後の要素を取得

func (Slice[T]) Len added in v1.5.1

func (s Slice[T]) Len() int

Len ... 要素数を取得する

func (Slice[T]) Pop added in v1.5.1

func (s Slice[T]) Pop() (T, Slice[T])

Pop ... 配列の後尾を切り取る

func (Slice[T]) Shift added in v1.5.1

func (s Slice[T]) Shift() (T, Slice[T])

Shift ... 配列の先頭を切り取る

func (Slice[T]) Shuffle added in v1.5.1

func (s Slice[T]) Shuffle() Slice[T]

Shuffle ... 配列をシャッフルする

func (Slice[T]) Some added in v1.5.1

func (s Slice[T]) Some(fn func(src T) bool) bool

Some ... ContainsFunc のエイリアス

func (Slice[T]) Sort added in v1.5.1

func (s Slice[T]) Sort(fn func(i, j int) bool) Slice[T]

Sort ... ソート

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