ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - twharmon/slices: Pure functions for slices.
Pure functions for slices. Contribute to twharmon/slices development by creating an account on GitHub.
Visit Site

GitHub - twharmon/slices: Pure functions for slices.

GitHub - twharmon/slices: Pure functions for slices.

Slices

Pure functions for slices. Slices are never operated on "in place". Instead, new ones are returned.

codecov

Documentation

For full documentation see pkg.go.dev.

Install

go get github.com/twharmon/slices

Usage

package main

import (
	"fmt"

	"github.com/twharmon/slices"
)

func main() {
	// use plain go slices
	s := []string{"foo", "ba"}

	// append new item to end of slice
	s = slices.Append(s, "b")
	fmt.Println(s) // [foo ba b]
	
	// sort by string length, ascending
	sorted := slices.SortFunc(s, func(a, b string) bool {
		return len(a) < len(b)
	})
	// original slice is not chaged
	fmt.Println(s, sorted) // [foo ba b] [b ba foo]

	// sum the lengths of all the strings    
	totalLen := slices.Reduce(s, func(cnt int, i string) int {
		return cnt + len(i)
	})
	fmt.Println(totalLen) // 6

	// find the first item with length 2
	str := slices.Find(s, func(item string) bool { return len(item) == 2 })    
	fmt.Println(str) // ba

	// map slice to new slice of different type
	ints := slices.Map(s, func(item string) int { return len(s) })    
	fmt.Println(ints) // [3 2 1]
}

Benchmarks

goos: darwin
goarch: arm64
pkg: github.com/twharmon/slices

BenchmarkSortFunc/std_lib-10         	  116497	      9424 ns/op	    4152 B/op	       3 allocs/op
BenchmarkSortFunc/slices-10          	  101791	     11479 ns/op	    4096 B/op	       1 allocs/op
BenchmarkSort/std_lib-10             	  125790	      9441 ns/op	    4120 B/op	       2 allocs/op
BenchmarkSort/slices-10              	  113931	     10162 ns/op	    4096 B/op	       1 allocs/op

BenchmarkReverse-10                  	 1631348	       749.4 ns/op	    4096 B/op	       1 allocs/op
BenchmarkConcat-10                   	  275463	      4259 ns/op	   40960 B/op	       1 allocs/op
BenchmarkFilter-10                   	 1000000	      1018 ns/op	    4096 B/op	       1 allocs/op

BenchmarkUnion/2x20-10               	 3258876	       361.2 ns/op	      32 B/op	       1 allocs/op
BenchmarkUnion/20x2-10               	  502176	      2329 ns/op	    1592 B/op	       3 allocs/op
BenchmarkUnion/20x2000-10            	    1140	   1054108 ns/op	    1590 B/op	       3 allocs/op
BenchmarkUnion/2000x20-10            	     714	   1697117 ns/op	  142481 B/op	      39 allocs/op

BenchmarkIntersection/2x20-10        	 2380771	       498.0 ns/op	      48 B/op	       1 allocs/op
BenchmarkIntersection/20x2-10        	  821226	      1427 ns/op	    1196 B/op	       3 allocs/op
BenchmarkIntersection/20x2000-10     	    1178	   1020620 ns/op	    1282 B/op	       3 allocs/op
BenchmarkIntersection/2000x20-10     	     938	   1276258 ns/op	  203294 B/op	      58 allocs/op

Contribute

Make a pull request.

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory