just

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: MIT Imports: 2 Imported by: 6

README

just

Build Status Go Reference

This project is contains functions that help to do noizy things in every project.

  • Filter slices, maps.
  • Apply functions to collections.
  • Null[any] for optional fields in api an sql.DB requests.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool added in v0.4.0

func Bool[T builtin](v T) bool

Bool returns true if element not equal to default value for this type.

func MapFilter added in v0.3.0

func MapFilter[K comparable, V any](in map[K]V, fn func(k K, v V) bool) map[K]V

MapFilter returns the map which contains elements that `fn(key, value) == true`.

func MapFilterKeys added in v0.3.0

func MapFilterKeys[K comparable, V any](in map[K]V, fn func(k K) bool) map[K]V

MapFilterKeys returns the map which contains elements that `fn(key) == true`. That is a simplified version of MapFilter.

func MapFilterValues added in v0.3.0

func MapFilterValues[K comparable, V any](in map[K]V, fn func(v V) bool) map[K]V

MapFilterValues returns the map which contains elements that `fn(value) == true`. That is a simplified version of MapFilter.

func MapMerge added in v0.3.0

func MapMerge[K comparable, V any](m1, m2 map[K]V, fn func(k K, v1, v2 V) V) map[K]V

MapMerge returns the map which contains all keys from m1, m2 and values from `fn(key, m1Value, m2Value)`.

func Max

func Max[T number](in ...T) T

Max returns the max number from `in`.

func Min

func Min[T number](in ...T) T

Min returns the min number from `in`.

func Pointer added in v0.2.0

func Pointer[T any](v T) *T

func Slice2Map added in v0.9.0

func Slice2Map[T comparable](in []T) map[T]struct{}

Slice2Map make map from slice, which contains all values from `in` as map keys.

func SliceAddNotExists added in v0.7.0

func SliceAddNotExists[T comparable](in []T, elem T) []T

SliceAddNotExists return `in` with `elem` inside when `elem` not exists in `in`.

func SliceAll added in v0.4.0

func SliceAll[T any](in []T, fn func(T) bool) bool

SliceAll returns true when `fn` returns true for all elements from `in`.

func SliceAny added in v0.4.0

func SliceAny[T any](in []T, fn func(T) bool) bool

SliceAny returns true when `fn` returns true for at least one element from `in`.

func SliceContainsElem added in v0.10.0

func SliceContainsElem[T comparable](in []T, elem T) bool

SliceContainsElem returns true when `in` contains elem.

func SliceDifference added in v0.9.0

func SliceDifference[T comparable](oldSlice, newSlice []T) []T

SliceDifference return the difference between `oldSlice` and `newSlice`. Returns only elements which presented in `newSlice` but not presented in `oldSlice`. Example: [1,2,3], [3,4,5] => [4,5]

func SliceFilter added in v0.3.0

func SliceFilter[T any](in []T, fn func(T) bool) []T

SliceFilter returns slice of values from `in` where `fn(elem) == true`.

func SliceMap added in v0.3.0

func SliceMap[T any, V any](in []T, fn func(T) V) []V

SliceMap returns the slice where each element of `in` was handled by `fn`.

func SliceReverse added in v0.4.0

func SliceReverse[T any](in []T) []T

SliceReverse reverse the slice.

func SliceUnion added in v0.8.0

func SliceUnion[T comparable](in ...[]T) []T

SliceUnion returns only uniq items from all slices.

func SliceUniq added in v0.3.0

func SliceUniq[T comparable](in []T) []T

SliceUniq returns only unique values from `in`.

func SliceWithout added in v0.10.0

func SliceWithout[T any](in []T, fn func(T) bool) []T

SliceWithout returns the slice `in` where fn(elem) == true.

func SliceWithoutElem added in v0.10.0

func SliceWithoutElem[T comparable](in []T, elem T) []T

SliceWithoutElem returns the slice `in` that not contains `elem`.

func SliceZip added in v0.10.0

func SliceZip[T any](in ...[]T) [][]T

SliceZip returns merged together the values of each of the arrays with the values at the corresponding position. If the len of `in` is different - will use smaller one.

func Sum

func Sum[T number](in ...T) T

Sum returns the sum of numbers from `in`.

Types

type NullVal added in v0.5.0

type NullVal[T any] struct {
	Val   T
	Valid bool
}

NullVal represent the nullable value for this type.

func Null added in v0.5.0

func Null[T any](val T) NullVal[T]

Null returns NullVal for `val` type, which are `NullVal.Valid == true`.

func NullNull added in v0.5.0

func NullNull[T any]() NullVal[T]

NullNull returns NullVal, which are `NullVal.Valid == false`.

func (*NullVal[T]) Scan added in v0.5.0

func (nv *NullVal[T]) Scan(value any) error

Scan implements the Scanner interface.

func (*NullVal[T]) SetDefault added in v0.5.0

func (nv *NullVal[T]) SetDefault(val T) bool

SetDefault set value `val` if NullVal.Valid == false.

func (NullVal[T]) Value added in v0.5.0

func (nv NullVal[T]) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (NullVal[T]) ValueOk added in v0.5.0

func (nv NullVal[T]) ValueOk() (T, bool)

ValueOk returns the NullVal.Val and NullVal.Valid.

Jump to

Keyboard shortcuts

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