diff --git a/join.go b/join.go index c681015..fdb3208 100644 --- a/join.go +++ b/join.go @@ -1,6 +1,6 @@ package underscore -// Joins two slices together and returns a Tuple of [T, []P], the selectors allow you to pick the +// Join joins two slices together and returns a Tuple of [T, []P], the selectors allow you to pick the // keys you want to use from your struct's to join the sets together func Join[T, P any, S comparable]( left []T, @@ -18,7 +18,7 @@ func Join[T, P any, S comparable]( return results } -// Joins two slices together and returns a []O where O is defined by the output +// JoinProject joins two slices together and returns a []O where O is defined by the output // of your projection function // The selectors allow you to pick the keys from your structure to use as the join keys // While the projection functions allows you to reformat joined datasets diff --git a/orderBy.go b/orderBy.go index 8ee7671..4f666ee 100644 --- a/orderBy.go +++ b/orderBy.go @@ -1,8 +1,9 @@ package underscore -// Orders a slice by a field value within a struct, the predicate allows you +// OrderBy orders a slice by a field value within a struct, the predicate allows you // to pick the fields you want to orderBy. Use > for ASC or < for DESC -// func (left Person, right Person) bool { return left.Age > right.Age } +// +// func (left Person, right Person) bool { return left.Age > right.Age } func OrderBy[T any](list []T, predicate func(T, T) bool) []T { swaps := true var tmp T diff --git a/pointers.go b/pointers.go index dc5c7e2..494f831 100644 --- a/pointers.go +++ b/pointers.go @@ -1,6 +1,6 @@ package underscore -// Convert values to pointers +// ToPointer Convert values to pointers // // Instead of: // v := "value" diff --git a/range.go b/range.go index 204c6b8..5a67175 100644 --- a/range.go +++ b/range.go @@ -1,6 +1,6 @@ package underscore -// Creates a sequence of numbers, i.e. u.Range(0, 3) = [0 1 2 3], while u.Range(3, 0) = [3 2 1 0] +// Range creates a sequence of numbers, i.e. u.Range(0, 3) = [0 1 2 3], while u.Range(3, 0) = [3 2 1 0] func Range(start int, end int) (result []int) { if start < end { for i := start; i <= end; i++ { diff --git a/slices.go b/slices.go index 0101cf6..ad2f462 100644 --- a/slices.go +++ b/slices.go @@ -6,14 +6,14 @@ import ( "golang.org/x/exp/constraints" ) -// sort any slice ASENDING +// SortSliceASC sorts any slice ASCENDING func SortSliceASC[T constraints.Ordered](s []T) { sort.SliceStable(s, func(i, j int) bool { return s[i] < s[j] }) } -// sort any slice DESCENDING +// SortSliceDESC sorts any slice DESCENDING func SortSliceDESC[T constraints.Ordered](s []T) { sort.SliceStable(s, func(i, j int) bool { return s[i] > s[j] diff --git a/sum.go b/sum.go index 0cc9652..bd18a35 100644 --- a/sum.go +++ b/sum.go @@ -10,8 +10,8 @@ func Sum[T constraints.Ordered](values []T) (sum T) { return sum } -// Sums the values you select from your struct, basically a sort cut instead of -// having to perform a u.Map followed by a u.Sum +// SumMap sums the values you select from your struct, basically a sort cut instead of +// having to perform a [Map] followed by a [Sum]. func SumMap[T any, R constraints.Ordered](list []T, selector func(T) R) (sum R) { for _, v := range list { sum += selector(v) diff --git a/ternary.go b/ternary.go index 01d256d..ebe8df2 100644 --- a/ternary.go +++ b/ternary.go @@ -1,5 +1,7 @@ package underscore +// Ternary returns the first argument if the condition is true, otherwise the second argument. +// Ternary is a special form of the if statement. It allows you to write code that is more concise and less verbose. func Ternary[T any](condition bool, pos, neg T) T { if condition { return pos diff --git a/tuple.go b/tuple.go index a229f52..1ab7b5f 100644 --- a/tuple.go +++ b/tuple.go @@ -1,5 +1,7 @@ package underscore +// Tuple is a generic tuple type. +// It is used to return multiple values from a function. type Tuple[L, R any] struct { Left L Right R diff --git a/unique.go b/unique.go index 718ddc8..111e332 100644 --- a/unique.go +++ b/unique.go @@ -1,5 +1,6 @@ package underscore +// Unique returns a slice of unique values from the given slice. func Unique[T comparable](values []T) (uniques []T) { seen := make(map[T]bool, 0) for _, v := range values { diff --git a/zip.go b/zip.go index ca53e62..07e2d8c 100644 --- a/zip.go +++ b/zip.go @@ -1,6 +1,6 @@ package underscore -// Zips two slices togther so all the elements of left slice are attached to the corresponding +// Zip joins two slices together so all the elements of left slice are attached to the corresponding // elements of the right slice, i.e. [one two three] [1 2 3 4] = [{one, 1} {two, 2} {three, 3}] // the returned data will be the size of the smallest slice func Zip[L any, R any](left []L, right []R) []Tuple[L, R] {