Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danilovteodoro/Slice-Helper
It's just a convinience to work with slices.
https://github.com/danilovteodoro/Slice-Helper
array generics go golang slice
Last synced: about 2 months ago
JSON representation
It's just a convinience to work with slices.
- Host: GitHub
- URL: https://github.com/danilovteodoro/Slice-Helper
- Owner: danilovteodoro
- Created: 2022-08-25T20:23:51.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-27T13:18:51.000Z (almost 2 years ago)
- Last Synced: 2024-08-03T23:29:26.231Z (5 months ago)
- Topics: array, generics, go, golang, slice
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-golang-repositories - Slice-Helper
README
# Slice-Helper
It's just a convinience to work with slices.
## Examples
Consider these data for the next examples:
```go
var programmingLanguages = []ProgrammingLanguage{
{Id: 1, Name: "JavaScript", ReleasedYear: 1995, GithutRank: 1, PyplRank: 3},
{Id: 3, Name: "Java", ReleasedYear: 1995, GithutRank: 3, PyplRank: 2},
{Id: 2, Name: "Python", ReleasedYear: 1991, GithutRank: 2, PyplRank: 1},
{Id: 4, Name: "TypeScript", ReleasedYear: 2012, GithutRank: 7, PyplRank: 10},
{Id: 5, Name: "C#", ReleasedYear: 2000, GithutRank: 9, PyplRank: 4},
}
```### **Find**
```go
p := collections.Find(programmingLanguages, func(p ProgrammingLanguage) bool {
return p.Id == 4
})
fmt.Println(*p)
```
#### Output
```
{4 TypeScript 2012 7 10}
```### **Filter**
```go
languages := collections.FilterArray(programmingLanguages, func(p ProgrammingLanguage) bool {
return p.GithutRank > 6
})
fmt.Println(languages)
```
#### Output
```
[{4 TypeScript 2012 7 10} {5 C# 2000 9 4}]
```### **Map**
```go
langNames := collections.MapArray(programmingLanguages, func(p ProgrammingLanguage) string {
return p.Name
})
fmt.Println(langNames)
```
#### Output
```
[JavaScript Java Python TypeScript C#]
```### **Some**
```go
shouldBeTrue := collections.Some(programmingLanguages, func(p ProgrammingLanguage) bool {
return p.GithutRank == 7
})shouldBeFalse := collections.Some(programmingLanguages, func(p ProgrammingLanguage) bool {
return p.GithutRank == 4
})
fmt.Println("shouldBeTrue: ", shouldBeTrue, "shouldBeFalse: ", shouldBeFalse)
```
#### Output
```
shouldBeTrue: true shouldBeFalse: false
```### **Every**
```go
shouldBeTrue = collections.Every(programmingLanguages, func(p ProgrammingLanguage) bool {
return p.GithutRank < 10
})shouldBeFalse = collections.Every(programmingLanguages, func(p ProgrammingLanguage) bool {
return p.GithutRank > 4
})
fmt.Println("shouldBeTrue: ", shouldBeTrue, "shouldBeFalse: ", shouldBeFalse)```
#### Output
```
shouldBeTrue: true shouldBeFalse: false
```### **Group**
```go
sumOfRankings := collections.Group(programmingLanguages, func(p ProgrammingLanguage, amount int) int {
return p.GithutRank + amount
})
fmt.Println("Some of Rankings: ", sumOfRankings)
```
#### Output
```
Sum of Rankings: 22
```