los

package
v1.0.19 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 2 Imported by: 13

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EveryNil added in v1.0.11

func EveryNil(elems ...any) bool
Example

ExampleEveryNil is an example function.

package main

import (
	"fmt"

	"github.com/xuender/kit/los"
)

func main() {
	fmt.Println(los.EveryNil(nil, nil))
	fmt.Println(los.EveryNil(nil, 1))

}
Output:

true
false

func Pull

func Pull[V comparable](collection []V, elements ...V) []V

Pull 删除切片指定成员.

Example

ExamplePull is an example function.

package main

import (
	"fmt"

	"github.com/xuender/kit/los"
)

func main() {
	fmt.Println(los.Pull([]int{1, 2, 2, 3}, 0, 2))

}
Output:

[1 3]

func PullAt

func PullAt[V any](collection []V, indices ...int) []V

PullAt 删除切片指定位置.

Example

ExamplePullAt is an example function.

package main

import (
	"fmt"

	"github.com/xuender/kit/los"
)

func main() {
	fmt.Println(los.PullAt([]rune{'1', '2', '2', '3'}, 2, 3))

}
Output:

[49 50]

func Remove

func Remove[V comparable](collection []V, predicate func(V, int) bool) []V

Remove 根据断言删除.

Example

ExampleRemove is an example function.

package main

import (
	"fmt"

	"github.com/xuender/kit/los"
)

func main() {
	fmt.Println(los.Remove([]int{1, 2, 2, 3, 4}, func(item, _ int) bool { return item%2 == 0 }))

}
Output:

[1 3]

func SomeNil added in v1.0.11

func SomeNil(elems ...any) bool
Example

ExampleSomeNil is an example function.

package main

import (
	"fmt"

	"github.com/xuender/kit/los"
)

func main() {
	fmt.Println(los.SomeNil(nil, 1))
	fmt.Println(los.SomeNil(1, 2))

}
Output:

true
false

func Split

func Split[T comparable](collection []T, isSeparator func(T, int) bool) [][]T

Split 切片分解.

Example

ExampleSplit is an example function.

package main

import (
	"fmt"

	"github.com/xuender/kit/los"
)

func main() {
	fmt.Println(los.Split(
		[]int{1, 0, 2, 3, 0, 4, 0, 5},
		func(num, _ int) bool { return num == 0 },
	))

}
Output:

[[1] [2 3] [4] [5]]

func SplitStr

func SplitStr(str string, separators ...rune) []string

SplitStr 字符串根据分隔符分解.

Example

ExampleSplitStr is an example function.

package main

import (
	"fmt"

	"github.com/xuender/kit/los"
)

func main() {
	fmt.Println(los.SplitStr("123,456", ','))
	fmt.Println(los.SplitStr("a-b_c", '-', '_'))

}
Output:

[123 456]
[a b c]

Types

This section is empty.

Jump to

Keyboard shortcuts

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