sugar

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 2 Imported by: 0

README

sugar

sugar is a package containing sugar syntax function. Refer to each file for more information.

Available Sugar Syntax

Enumerable
  1. Any
  2. Count
  3. IsAll
  4. IsAny
  5. IsNone
  6. Map
  7. Reverse
  8. Select
  9. Sum
Conditional
  1. If
String
  1. Concat

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any[T any](arr []T, fn func(elem T) bool) T

Any checks arr whether any of the elements satistifed the fn criteria AND then return the first found element. If no fn criteria given, return default value as the function assume that it can't check the criteria.

func Concat

func Concat[T comparable](arr []T, delimiter string) string

Concat creates string containing arr elements with delimiter. E.g: Concat([]int{1, 2, 3}, ",") => "1,2,3"

func Count

func Count[T any](arr []T) int

Count returns arr length

func If

func If[T any](cond bool, trueValue, falseValue T) T

If evaluate cond, and return appropriate value. It is basically shorthand if.

func IsAll

func IsAll[T any](arr []T, fn func(elem T) bool) bool

IsAll checks arr whether all of the elements satisfied the fn criteria If no fn criteria given, return false as the function assume that it can't check the criteria.

func IsAny

func IsAny[T any](arr []T, fn func(elem T) bool) bool

IsAny checks arr whether any of the elements satisfied the fn criteria True if at least 1 element satisfied If no fn criteria given, return false as the function assume that it can't check the criteria.

func IsEmpty

func IsEmpty[T any](arr []T) bool

IsEmpty checks whether arr is empty

func IsNone

func IsNone[T any](arr []T, fn func(elem T) bool) bool

IsNone checks arr whether none of the elements satisfied the fn criteria. True if none satisfied. If no fn criteria given, return default value as the function assume that it can't check the criteria.

func Map

func Map[T any, V any](arr []T, fn func(elem T) V) []V

Map maps new value(s) from arr, you can provide your own map function via fn. E.g: Map(int{1, 2, 3}, func(i int) string { strconv.Itoa(i) }) to produce new array of string

func Reverse

func Reverse[T any](arr []T) []T

Reverse reverse the array

func Select

func Select[T any](arr []T, fn func(elem T) bool) []T

Select filters elements that satisfied the fn criteria If no fn criteria given, return the original arr

func Sum

func Sum[T any, V constraints.Integer | constraints.Float](initialValue V, arr []T, fn func(elem T) V) V

Sum sums value from evaluation fn function you can provide initialValue of the sum if no fn criteria given, return default value of V

Types

This section is empty.

Jump to

Keyboard shortcuts

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