GithubHelp home page GithubHelp logo

issue9 / sliceutil Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 44 KB

数组和切片的相关功能函数

Home Page: https://pkg.go.dev/github.com/issue9/sliceutil

License: MIT License

Go 100.00%
go golang slice array array-methods array-helper

sliceutil's Introduction

sliceutil Build Status license codecov PkgGoDev Go version

sliceutil 提供了针对数组和切片的功能

  • At 查找符合条件的元素;
  • Index 查找符合条件元素在数组中的位置;
  • Indexes 查找所有符合条件元素在数组中的位置;
  • Reverse 反转数组中的元素;
  • Delete 删除符合条件的切片元素;
  • QuickDelete 删除符合条件的切片元素,性能稍高于 Delete;
  • Count 统计数组或切片中包含指定什的数量;
  • Unique 提取数组中的唯一元素;
  • Dup 查看数组或切片中是否包含重得的值;
  • Contains 判断一个数组或是切片是否包含了另一个的所有元素;
  • Min 查找最小值;
  • Max 查找最大值;
  • Filter 过滤数据;
  • SafeFilter 过滤数据;
  • AnySlice 将 slices 转换为 []any 类型;
  • MapKeys 获取一个 map 的所有 key;
  • MapVals 获取一个 map 的所有值;
intSlice := []int{1, 2, 3, 7, 0, 4, 7}
intArr := [3]int{1, 7, 0}

// index == [3, 7]
index := Dup(intSlice, func(i, j int) bool {
    return intSlice[i] == intSlice[j]
})

// 返回 7 的数量
count := Count(intSlice, func(i, index int) bool {
    return intSlice[i] == 7
})

// 会重新调整切片的内容,将删除后的数据在放最前端,并返回新切片。
slice := Delete(intSlice, func(i, index int) bool {
    return intSlice[i] == 7
})

// ok == true
ok := Contains(intSlice, intArr, func(i, j int) bool {
    return int8(intSlice[i]) == int8Arr[j]
})

安装

go get github.com/issue9/sliceutil

版权

本项目采用 MIT 开源授权许可证,完整的授权说明可在 LICENSE 文件中找到。

sliceutil's People

Contributors

caixw avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ankogo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.