Categorygithub.com/hirak99/go-sanity
repositorypackage
0.1.7
Repository: https://github.com/hirak99/go-sanity.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

Go Sanity

This is a collection of methods and classes that make it easier to use Golang out of the box.

Installing

From the root of your package, run this to add a dependency -

go get -d github.com/hirak99/go-sanity@latest

Using

Add the module to your project with

go get -d github.com/hirak99/go-sanity@latest

Then use it -

package main

import (
  "fmt"

  . "github.com/hirak99/go-sanity"
)

func main() {
  nums := []int{1, 2, 3, 4, 5, 6, 7, 8}

  odds := Filter(nums, func(n int) bool { return n % 2 == 1 })
  fmt.Println(odds)
}

Content

Methods

FunctionExample
Ternary ifIf(a == b, "yes", "no")
MapMap([]string{"12", "34"}, func(s string) int { return strconv.Atoi(s) })
ReduceReduce([]string{"12", "34"}, "", func(x, y string) string { return x + y })
AnyAny([]int{1, 2, 3}, func(i int) bool { return i > 2})
AllAll([]int{1, 2, 3}, func(i int) bool { return i > 0})
FilterFilter([]int{10, 33, 59, 93}, func(i int) bool { return i > 50 }
SumSum([]float64{1.1, 2.3, 4.8})
ChanToSliceChanToSlice(c)
SaneSortSliceSaneSortSlice(s, func(a, b string) { return a < b})

Collections

FunctionExample
Sets := MakeSet[int](), then use s.Add(...), s.Has(...) etc.

Testing

FunctionExample
AssertAssert(t, something_that_should_be_true())
AssertEqualAssert(t, a, b)
AssertSliceEqualAssertSliceEqual(t, s1, s2)
AssertSliceEqualUnorderedAssertSliceEqualUnordered(t, s1, s2)