Documentation ¶
Index ¶
- Constants
- type HBytes
- func (hbs HBytes) Add(bs HBytes) HBytes
- func (hbs HBytes) AddPrefix(bs HBytes) HBytes
- func (hbs HBytes) Bytes() []byte
- func (hbs HBytes) Clone() HBytes
- func (hbs HBytes) Compare(bs HBytes) HInt
- func (hbs HBytes) Contains(bs HBytes) bool
- func (hbs HBytes) ContainsAll(bss ...HBytes) bool
- func (hbs HBytes) ContainsAny(bss ...HBytes) bool
- func (hbs HBytes) ContainsAnyChars(chars HString) bool
- func (hbs HBytes) ContainsRegexp(pattern *regexp.Regexp) bool
- func (hbs HBytes) ContainsRegexpAll(patterns ...*regexp.Regexp) bool
- func (hbs HBytes) ContainsRegexpAny(patterns ...*regexp.Regexp) bool
- func (hbs HBytes) ContainsRune(r rune) bool
- func (hbs HBytes) Count(bs HBytes) int
- func (hbs HBytes) Empty() bool
- func (hbs HBytes) Eq(bs HBytes) bool
- func (hbs HBytes) EqFold(bs HBytes) bool
- func (hbs HBytes) FindAllRegexp(pattern *regexp.Regexp) HOption[HSlice[HBytes]]
- func (hbs HBytes) FindAllRegexpN(pattern *regexp.Regexp, n HInt) HOption[HSlice[HBytes]]
- func (hbs HBytes) FindAllSubmatchRegexp(pattern *regexp.Regexp) HOption[HSlice[HSlice[HBytes]]]
- func (hbs HBytes) FindAllSubmatchRegexpN(pattern *regexp.Regexp, n HInt) HOption[HSlice[HSlice[HBytes]]]
- func (hbs HBytes) FindRegexp(pattern *regexp.Regexp) HOption[HBytes]
- func (hbs HBytes) FindSubmatchRegexp(pattern *regexp.Regexp) HOption[HSlice[HBytes]]
- func (hbs HBytes) Gt(bs HBytes) bool
- func (hbs HBytes) HString() HString
- func (hbs HBytes) Hash() bhash
- func (hbs HBytes) Index(bs HBytes) int
- func (hbs HBytes) IndexByte(b byte) int
- func (hbs HBytes) IndexRegexp(pattern *regexp.Regexp) HOption[HSlice[HInt]]
- func (hbs HBytes) IndexRune(r rune) int
- func (hbs HBytes) LastIndex(bs HBytes) int
- func (hbs HBytes) LastIndexByte(b byte) int
- func (hbs HBytes) Len() int
- func (hbs HBytes) LenRunes() int
- func (hbs HBytes) Lt(bs HBytes) bool
- func (hbs HBytes) Map(fn func(rune) rune) HBytes
- func (hbs HBytes) Ne(bs HBytes) bool
- func (hbs HBytes) NormalizeNFC() HBytes
- func (hbs HBytes) NotEmpty() bool
- func (hbs HBytes) Print() HBytes
- func (hbs HBytes) Reader() *bytes.Reader
- func (hbs HBytes) Repeat(count int) HBytes
- func (hbs HBytes) Replace(oldB, newB HBytes, n int) HBytes
- func (hbs HBytes) ReplaceAll(oldB, newB HBytes) HBytes
- func (hbs HBytes) ReplaceRegexp(pattern *regexp.Regexp, newB HBytes) HBytes
- func (hbs HBytes) Reverse() HBytes
- func (hbs HBytes) Runes() []rune
- func (hbs HBytes) Split(sep ...HBytes) HSlice[HBytes]
- func (hbs HBytes) String() string
- func (hbs HBytes) ToLower() HBytes
- func (hbs HBytes) ToTitle() HBytes
- func (hbs HBytes) ToUpper() HBytes
- func (hbs HBytes) Trim(cutset HString) HBytes
- func (hbs HBytes) TrimLeft(cutset HString) HBytes
- func (hbs HBytes) TrimPrefix(cutset HBytes) HBytes
- func (hbs HBytes) TrimRight(cutset HString) HBytes
- func (hbs HBytes) TrimSpace() HBytes
- func (hbs HBytes) TrimSuffix(cutset HBytes) HBytes
- type HDir
- func (hd *HDir) CopyDir(dest HString) HResult[*HDir]
- func (hd HDir) Exist() bool
- func (hd *HDir) Glob() HResult[HSlice[*HFile]]
- func (hd HDir) HString() HString
- func (hd *HDir) Join(elem ...HString) HResult[HString]
- func (hd *HDir) Mkdir(mode ...os.FileMode) HResult[*HDir]
- func (hd *HDir) MkdirAll(mode ...os.FileMode) HResult[*HDir]
- func (hd *HDir) Move(newpath HString) HResult[*HDir]
- func (hd *HDir) Path() HResult[HString]
- func (hd *HDir) Print() *HDir
- func (hd *HDir) ReadDir() HResult[HSlice[*HFile]]
- func (hd *HDir) Rename(newpath HString) HResult[*HDir]
- func (hd *HDir) SetPath(path HString) *HDir
- type HFile
- func (hf *HFile) Append(content HString, mode ...os.FileMode) HResult[*HFile]
- func (hf *HFile) Chmod(mode os.FileMode) HResult[*HFile]
- func (hf *HFile) Chown(uid, gid int) HResult[*HFile]
- func (hf *HFile) Close()
- func (hf *HFile) Copy(dest HString, mode ...os.FileMode) HResult[*HFile]
- func (hf HFile) Exist() bool
- func (hf HFile) Ext() HString
- func (hf HFile) File() *os.File
- func (hf HFile) HDir() HResult[*HDir]
- func (hf *HFile) Iterator() HResult[*hfiter]
- func (hf *HFile) MimeType() HResult[HString]
- func (hf *HFile) Move(newpath HString) HResult[*HFile]
- func (hf HFile) Name() HString
- func (hf HFile) Path() HResult[HString]
- func (hf *HFile) Print() *HFile
- func (hf *HFile) Read() HResult[HString]
- func (hf HFile) ReadLines() HResult[HSlice[HString]]
- func (hf *HFile) Remove() HResult[*HFile]
- func (hf *HFile) Rename(newpath HString) HResult[*HFile]
- func (hf *HFile) SeekToLine(position int64, linesRead int) (int64, HString)
- func (hf HFile) Split() (*HDir, *HFile)
- func (hf *HFile) Stat() HResult[fs.FileInfo]
- func (*HFile) TempFile(args ...HString) HResult[*HFile]
- func (hf *HFile) Write(content HString, mode ...os.FileMode) HResult[*HFile]
- func (hf *HFile) WriteFromReader(scr io.Reader, mode ...os.FileMode) HResult[*HFile]
- type HFloat
- func (hf HFloat) Abs() HFloat
- func (hf HFloat) Add(b HFloat) HFloat
- func (hf HFloat) BigFloat() *big.Float
- func (hf HFloat) Bytes() []byte
- func (hf HFloat) Compare(b HFloat) HInt
- func (hf HFloat) Div(b HFloat) HFloat
- func (hf HFloat) Eq(b HFloat) bool
- func (hf HFloat) Float() float64
- func (hf HFloat) Gt(b HFloat) bool
- func (hf HFloat) HInt() HInt
- func (hf HFloat) HString() HString
- func (hf HFloat) Hash() fhash
- func (hf HFloat) Lt(b HFloat) bool
- func (hf HFloat) Max(b ...HFloat) HFloat
- func (hf HFloat) Min(b ...HFloat) HFloat
- func (hf HFloat) Mul(b HFloat) HFloat
- func (hf HFloat) Ne(b HFloat) bool
- func (hf HFloat) Print() HFloat
- func (hf HFloat) Round() HInt
- func (hf HFloat) RoundDecimal(precision int) HFloat
- func (hf HFloat) Sub(b HFloat) HFloat
- func (hf HFloat) UInt64() uint64
- type HInt
- func (hi HInt) Abs() HInt
- func (hi HInt) Add(b HInt) HInt
- func (hi HInt) BigInt() *big.Int
- func (hi HInt) Bytes() []byte
- func (hi HInt) Div(b HInt) HInt
- func (hi HInt) Eq(b HInt) bool
- func (hi HInt) Gt(b HInt) bool
- func (hi HInt) Gte(b HInt) bool
- func (hi HInt) HFloat() HFloat
- func (hi HInt) HString() HString
- func (hi HInt) Hash() ihash
- func (hi HInt) Int() int
- func (hi HInt) Int16() int16
- func (hi HInt) Int32() int32
- func (hi HInt) Int64() int64
- func (hi HInt) Int8() int8
- func (hi HInt) IsNegative() bool
- func (hi HInt) IsPositive() bool
- func (hi HInt) Lt(b HInt) bool
- func (hi HInt) Lte(b HInt) bool
- func (hi HInt) Max(b ...HInt) HInt
- func (hi HInt) Min(b ...HInt) HInt
- func (hi HInt) Mul(b HInt) HInt
- func (hi HInt) Ne(b HInt) bool
- func (hi HInt) Print() HInt
- func (hi HInt) Random() HInt
- func (HInt) RandomRange(from, to HInt) HInt
- func (hi HInt) Rem(b HInt) HInt
- func (hi HInt) Sub(b HInt) HInt
- func (hi HInt) ToBinary() HString
- func (hi HInt) ToHex() HString
- func (hi HInt) ToOctal() HString
- func (hi HInt) UInt() uint
- func (hi HInt) UInt16() uint16
- func (hi HInt) UInt32() uint32
- func (hi HInt) UInt64() uint64
- func (hi HInt) UInt8() uint8
- type HMap
- func (hmap HMap[K, V]) Clear() HMap[K, V]
- func (hmap HMap[K, V]) Clone() HMap[K, V]
- func (hmap HMap[K, V]) Contains(key K) bool
- func (hmap HMap[K, V]) Copy(src HMap[K, V]) HMap[K, V]
- func (hmap HMap[K, V]) Delete(keys ...K) HMap[K, V]
- func (hmap HMap[K, V]) Empty() bool
- func (hmap HMap[K, V]) Eq(other HMap[K, V]) bool
- func (hmap HMap[K, V]) Filter(fn func(K, V) bool) HMap[K, V]
- func (hmap HMap[K, V]) FilterParallel(fn func(K, V) bool) HMap[K, V]
- func (hmap HMap[K, V]) ForEach(fn func(K, V))
- func (hmap HMap[K, V]) Get(k K) V
- func (hmap HMap[K, V]) GetOrDefault(key K, defaultValue V) V
- func (hmap HMap[K, V]) GetOrSet(key K, defaultValue V) V
- func (hmap HMap[K, V]) Invert() HMap[any, K]
- func (hmap HMap[K, V]) Keys() HSlice[K]
- func (hmap HMap[K, V]) Len() int
- func (hmap HMap[K, V]) Map(fn func(K, V) (K, V)) HMap[K, V]
- func (hmap HMap[K, V]) MapAny(fn func(K, V) (K, any)) HMap[K, any]
- func (hmap HMap[K, V]) MapParallel(fn func(K, V) (K, V)) HMap[K, V]
- func (hmap HMap[K, V]) Ne(other HMap[K, V]) bool
- func (hmap HMap[K, V]) NotEmpty() bool
- func (hmap HMap[K, V]) Print() HMap[K, V]
- func (hmap HMap[K, V]) Set(k K, v V) HMap[K, V]
- func (hmap HMap[K, V]) String() string
- func (hmap HMap[K, V]) ToMap() map[K]V
- func (hmap HMap[K, V]) Values() HSlice[V]
- type HMapOrd
- func (hmapo *HMapOrd[K, V]) Clear() *HMapOrd[K, V]
- func (hmapo *HMapOrd[K, V]) Clone() *HMapOrd[K, V]
- func (hmapo *HMapOrd[K, V]) Contains(key K) bool
- func (hmapo *HMapOrd[K, V]) Copy(src *HMapOrd[K, V]) *HMapOrd[K, V]
- func (hmapo *HMapOrd[K, V]) Delete(keys ...K) *HMapOrd[K, V]
- func (hmapo *HMapOrd[K, V]) Empty() bool
- func (hmapo *HMapOrd[K, V]) Eq(other *HMapOrd[K, V]) bool
- func (hmapo *HMapOrd[K, V]) Filter(fn func(K, V) bool) *HMapOrd[K, V]
- func (hmapo *HMapOrd[K, V]) ForEach(fn func(K, V))
- func (hmapo *HMapOrd[K, V]) Get(key K) (V, bool)
- func (hmapo *HMapOrd[K, V]) GetOrDefault(key K, defaultValue V) V
- func (hmapo *HMapOrd[K, V]) GetOrSet(key K, defaultValue V) V
- func (hmapo *HMapOrd[K, V]) Invert() *HMapOrd[any, K]
- func (hmapo *HMapOrd[K, V]) Keys() HSlice[K]
- func (hmapo *HMapOrd[K, V]) Len() int
- func (hmapo *HMapOrd[K, V]) Map(fn func(K, V) (K, V)) *HMapOrd[K, V]
- func (hmapo *HMapOrd[K, V]) MapAny(fn func(K, V) (K, any)) *HMapOrd[K, any]
- func (hmapo *HMapOrd[K, V]) Ne(other *HMapOrd[K, V]) bool
- func (hmapo *HMapOrd[K, V]) NotEmpty() bool
- func (hmapo *HMapOrd[K, V]) Print() *HMapOrd[K, V]
- func (hmapo *HMapOrd[K, V]) Set(key K, value V) *HMapOrd[K, V]
- func (hmapo *HMapOrd[K, V]) SortBy(f func(i, j int) bool) *HMapOrd[K, V]
- func (hmapo *HMapOrd[K, V]) String() string
- func (hmapo *HMapOrd[K, V]) ToHMap() HMap[K, V]
- func (hmapo *HMapOrd[K, V]) Values() HSlice[V]
- type HOption
- type HResult
- func (r HResult[T]) Err() error
- func (r HResult[T]) Expect(msg HString) T
- func (r HResult[T]) IsErr() bool
- func (r HResult[T]) IsOk() bool
- func (r HResult[T]) Must() T
- func (r HResult[T]) MustOr(value T) T
- func (r HResult[T]) MustOrDefault() T
- func (r HResult[T]) Ok() T
- func (r HResult[T]) Result() (T, error)
- type HSet
- func (s HSet[T]) Add(values ...T) HSet[T]
- func (s HSet[T]) Clear() HSet[T]
- func (s HSet[T]) Clone() HSet[T]
- func (s HSet[T]) Contains(v T) bool
- func (s HSet[T]) ContainsAll(other HSet[T]) bool
- func (s HSet[T]) ContainsAny(other HSet[T]) bool
- func (s HSet[T]) Difference(other HSet[T]) HSet[T]
- func (s HSet[T]) Empty() bool
- func (s HSet[T]) Eq(other HSet[T]) bool
- func (s HSet[T]) Filter(fn func(T) bool) HSet[T]
- func (s HSet[T]) ForEach(fn func(T))
- func (s HSet[T]) HSlice() HSlice[T]
- func (s HSet[T]) Intersection(other HSet[T]) HSet[T]
- func (s HSet[T]) Len() int
- func (s HSet[T]) Map(fn func(T) T) HSet[T]
- func (s HSet[T]) MapAny(fn func(T) any) HSet[any]
- func (s HSet[T]) Ne(other HSet[T]) bool
- func (s HSet[T]) Print() HSet[T]
- func (s HSet[T]) Remove(values ...T) HSet[T]
- func (s HSet[T]) String() string
- func (s HSet[T]) Subset(other HSet[T]) bool
- func (s HSet[T]) Superset(other HSet[T]) bool
- func (s HSet[T]) SymmetricDifference(other HSet[T]) HSet[T]
- func (s HSet[T]) ToSlice() []T
- func (s HSet[T]) Union(other HSet[T]) HSet[T]
- type HSlice
- func (hsl HSlice[T]) AddUnique(elems ...T) HSlice[T]
- func (hsl *HSlice[T]) AddUniqueInPlace(elems ...T)
- func (hsl HSlice[T]) All(fn func(T) bool) bool
- func (hsl HSlice[T]) Any(fn func(T) bool) bool
- func (hsl HSlice[T]) Append(elems ...T) HSlice[T]
- func (hsl *HSlice[T]) AppendInPlace(elems ...T)
- func (hsl HSlice[T]) Cap() int
- func (hsl HSlice[T]) Chunks(size int) []HSlice[T]
- func (hsl HSlice[T]) Clear() HSlice[T]
- func (hsl HSlice[T]) Clip() HSlice[T]
- func (hsl HSlice[T]) Clone() HSlice[T]
- func (hsl HSlice[T]) Contains(val T) bool
- func (hsl HSlice[T]) ContainsAll(other HSlice[T]) bool
- func (hsl HSlice[T]) ContainsAny(other HSlice[T]) bool
- func (hsl HSlice[T]) Count(elem T) int
- func (hsl HSlice[T]) Counter() *HMapOrd[any, int]
- func (hsl HSlice[T]) Cut(start, end int) HSlice[T]
- func (hsl HSlice[T]) Delete(i int) HSlice[T]
- func (hsl *HSlice[T]) DeleteInPlace(i int)
- func (hsl HSlice[T]) Empty() bool
- func (hsl HSlice[T]) Enumerate() HMap[int, T]
- func (hsl HSlice[T]) Eq(other HSlice[T]) bool
- func (hsl HSlice[T]) Fill(val T) HSlice[T]
- func (hsl HSlice[T]) Filter(fn func(T) bool) HSlice[T]
- func (hsl *HSlice[T]) FilterInPlace(fn func(T) bool)
- func (hsl HSlice[T]) FilterParallel(fn func(T) bool) HSlice[T]
- func (hsl HSlice[T]) FilterZeroValues() HSlice[T]
- func (hsl *HSlice[T]) FilterZeroValuesInPlace()
- func (hsl HSlice[T]) Flatten() HSlice[any]
- func (hsl HSlice[T]) ForEach(fn func(T))
- func (hsl HSlice[T]) Get(index int) T
- func (hsl HSlice[T]) Grow(n int) HSlice[T]
- func (hsl HSlice[T]) Index(val T) int
- func (hsl HSlice[T]) Insert(i int, values ...T) HSlice[T]
- func (hsl *HSlice[T]) InsertInPlace(i int, values ...T)
- func (hsl HSlice[T]) Join(sep ...T) HString
- func (hsl HSlice[T]) Last() T
- func (hsl HSlice[T]) LastIndex() int
- func (hsl HSlice[T]) Len() int
- func (hsl HSlice[T]) Map(fn func(T) T) HSlice[T]
- func (hsl HSlice[T]) MapAny(fn func(T) any) HSlice[any]
- func (hsl HSlice[T]) MapAnyParallel(fn func(T) any) HSlice[any]
- func (hsl *HSlice[T]) MapInPlace(fn func(T) T)
- func (hsl HSlice[T]) MapParallel(fn func(T) T) HSlice[T]
- func (hsl HSlice[T]) Max() T
- func (hsl HSlice[T]) Min() T
- func (hsl HSlice[T]) Ne(other HSlice[T]) bool
- func (hsl HSlice[T]) NotEmpty() bool
- func (hsl HSlice[T]) Permutations() []HSlice[T]
- func (hsl HSlice[T]) Pop() (T, HSlice[T])
- func (hsl HSlice[T]) Print() HSlice[T]
- func (hsl HSlice[T]) Random() T
- func (hsl HSlice[T]) RandomSample(sequence int) HSlice[T]
- func (hsl HSlice[T]) Range(start int, end ...int) HSlice[T]
- func (hsl HSlice[T]) Reduce(fn func(acc, val T) T, initial T) T
- func (hsl HSlice[T]) ReduceParallel(fn func(T, T) T, initial T) T
- func (hsl HSlice[T]) Replace(i, j int, values ...T) HSlice[T]
- func (hsl *HSlice[T]) ReplaceInPlace(i, j int, values ...T)
- func (hsl HSlice[T]) Reverse() HSlice[T]
- func (hsl HSlice[T]) Set(i int, val T) HSlice[T]
- func (hsl HSlice[T]) Shuffle() HSlice[T]
- func (hsl HSlice[T]) SortBy(f func(i, j int) bool) HSlice[T]
- func (hsl HSlice[T]) String() string
- func (hsl HSlice[T]) Swap(i, j int) HSlice[T]
- func (hsl HSlice[T]) ToHMapHashed() HMap[HString, T]
- func (hsl HSlice[T]) ToSlice() []T
- func (hsl HSlice[T]) ToStringSlice() []string
- func (hsl HSlice[T]) Unique() HSlice[T]
- func (hsl HSlice[T]) Zip(hslices ...HSlice[T]) []HSlice[T]
- type HString
- func (hs HString) Add(hstr HString) HString
- func (hs HString) AddPrefix(hstr HString) HString
- func (hs HString) Bytes() []byte
- func (hs HString) Center(length int, pad HString) HString
- func (hs HString) Chunks(size int) HOption[HSlice[HString]]
- func (hs HString) Compare(hstr HString) HInt
- func (hs HString) Contains(substr HString) bool
- func (hs HString) ContainsAll(substrs ...HString) bool
- func (hs HString) ContainsAny(substrs ...HString) bool
- func (hs HString) ContainsAnyChars(chars HString) bool
- func (hs HString) ContainsRegexp(pattern *regexp.Regexp) bool
- func (hs HString) ContainsRegexpAll(patterns ...*regexp.Regexp) bool
- func (hs HString) ContainsRegexpAny(patterns ...*regexp.Regexp) bool
- func (hs HString) ContainsRune(r rune) bool
- func (hs HString) Count(substr HString) int
- func (hs HString) Cut(start, end HString, rmtags ...bool) (HString, HString)
- func (hs HString) Dec() dec
- func (hs HString) Empty() bool
- func (hs HString) Enc() enc
- func (hs HString) EndsWith(suffixes ...HString) bool
- func (hs HString) Eq(hstr HString) bool
- func (hs HString) EqFold(hstr HString) bool
- func (hs HString) Fields() HSlice[HString]
- func (hs HString) FindAllRegexp(pattern *regexp.Regexp) HOption[HSlice[HString]]
- func (hs HString) FindAllRegexpN(pattern *regexp.Regexp, n HInt) HOption[HSlice[HString]]
- func (hs HString) FindAllSubmatchRegexp(pattern *regexp.Regexp) HOption[HSlice[HSlice[HString]]]
- func (hs HString) FindAllSubmatchRegexpN(pattern *regexp.Regexp, n HInt) HOption[HSlice[HSlice[HString]]]
- func (hs HString) FindRegexp(pattern *regexp.Regexp) HOption[HString]
- func (hs HString) FindSubmatchRegexp(pattern *regexp.Regexp) HOption[HSlice[HString]]
- func (hs HString) Format(format HString) HString
- func (hs HString) Gt(hstr HString) bool
- func (hs HString) HBytes() HBytes
- func (hs HString) HFloat() HResult[HFloat]
- func (hs HString) HInt() HResult[HInt]
- func (hs HString) Hash() shash
- func (hs HString) Index(substr HString) int
- func (hs HString) IndexRegexp(pattern *regexp.Regexp) HOption[HSlice[HInt]]
- func (hs HString) IndexRune(r rune) int
- func (hs HString) IsASCII() bool
- func (hs HString) IsDigit() bool
- func (hs HString) LastIndex(substr HString) int
- func (hs HString) LeftJustify(length int, pad HString) HString
- func (hs HString) Len() int
- func (hs HString) LenRunes() int
- func (hs HString) Lt(hstr HString) bool
- func (hs HString) Map(fn func(rune) rune) HString
- func (hs HString) Max(b ...HString) HString
- func (hs HString) Min(b ...HString) HString
- func (hs HString) Ne(hstr HString) bool
- func (hs HString) NormalizeNFC() HString
- func (hs HString) NotEmpty() bool
- func (hs HString) Print() HString
- func (HString) Random(count int) HString
- func (hs HString) Reader() *strings.Reader
- func (hs HString) Repeat(count int) HString
- func (hs HString) Replace(oldS, newS HString, n int) HString
- func (hs HString) ReplaceAll(oldS, newS HString) HString
- func (hs HString) ReplaceNth(oldS, newS HString, n int) HString
- func (hs HString) ReplaceRegexp(pattern *regexp.Regexp, newS HString) HString
- func (hs HString) Reverse() HString
- func (hs HString) RightJustify(length int, pad HString) HString
- func (hs HString) Runes() []rune
- func (hs HString) Similarity(hstr HString) HFloat
- func (hs HString) Split(sep ...HString) HSlice[HString]
- func (hs HString) SplitN(sep HString, n HInt) HSlice[HString]
- func (hs HString) SplitRegexp(pattern regexp.Regexp) HSlice[HString]
- func (hs HString) SplitRegexpN(pattern regexp.Regexp, n HInt) HOption[HSlice[HString]]
- func (hs HString) StartsWith(prefixes ...HString) bool
- func (hs HString) String() string
- func (hs HString) ToLower() HString
- func (hs HString) ToTitle() HString
- func (hs HString) ToUpper() HString
- func (hs HString) Trim(cutset HString) HString
- func (hs HString) TrimLeft(cutset HString) HString
- func (hs HString) TrimPrefix(cutset HString) HString
- func (hs HString) TrimRight(cutset HString) HString
- func (hs HString) TrimSpace() HString
- func (hs HString) TrimSuffix(cutset HString) HString
Constants ¶
const ( ASCII_LETTERS = ASCII_LOWERCASE + ASCII_UPPERCASE ASCII_LOWERCASE = "abcdefghijklmnopqrstuvwxyz" ASCII_UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" DIGITS = "0123456789" HEXDIGITS = "0123456789abcdefABCDEF" OCTDIGITS = "01234567" PUNCTUATION = `!"#$%&'()*+,-./:;<=>?@[\]^{|}~` + "`" FileDefault os.FileMode = 0o644 DirDefault os.FileMode = 0o755 FullAccess os.FileMode = 0o777 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HBytes ¶
type HBytes []byte
HBytes is an alias for the []byte type.
func (HBytes) Add ¶
func (hbs HBytes) Add(bs HBytes) HBytes
Add appends the given HBytes to the current HBytes.
func (HBytes) AddPrefix ¶
func (hbs HBytes) AddPrefix(bs HBytes) HBytes
AddPrefix prepends the given HBytes to the current HBytes.
func (HBytes) Clone ¶
func (hbs HBytes) Clone() HBytes
Clone creates a new HBytes instance with the same content as the current HBytes.
func (HBytes) Compare ¶
func (hbs HBytes) Compare(bs HBytes) HInt
Compare compares the HBytes with another HBytes and returns an HInt.
func (HBytes) Contains ¶
func (hbs HBytes) Contains(bs HBytes) bool
Contains checks if the HBytes contains the specified HBytes.
func (HBytes) ContainsAll ¶ added in v1.0.7
func (hbs HBytes) ContainsAll(bss ...HBytes) bool
ContainsAll checks if the HBytes contains all of the specified HBytes.
func (HBytes) ContainsAny ¶
func (hbs HBytes) ContainsAny(bss ...HBytes) bool
ContainsAny checks if the HBytes contains any of the specified HBytes.
func (HBytes) ContainsAnyChars ¶ added in v1.0.7
func (hbs HBytes) ContainsAnyChars(chars HString) bool
ContainsAnyChars checks if the given HBytes contains any characters from the input HString.
func (HBytes) ContainsRegexp ¶ added in v1.0.21
ContainsRegexp checks if the HBytes contains a match for the specified regular expression pattern.
func (HBytes) ContainsRegexpAll ¶ added in v1.0.66
ContainsRegexpAll checks if the HBytes contains a match for all of the specified regular expression patterns.
func (HBytes) ContainsRegexpAny ¶ added in v1.0.66
ContainsRegexpAny checks if the HBytes contains a match for any of the specified regular expression patterns.
func (HBytes) ContainsRune ¶
ContainsRune checks if the HBytes contains the specified rune.
func (HBytes) Count ¶
func (hbs HBytes) Count(bs HBytes) int
Count counts the number of occurrences of the specified HBytes in the HBytes.
func (HBytes) Eq ¶
func (hbs HBytes) Eq(bs HBytes) bool
Eq checks if the HBytes is equal to another HBytes.
func (HBytes) EqFold ¶ added in v1.0.19
func (hbs HBytes) EqFold(bs HBytes) bool
EqFold compares two HBytes slices case-insensitively.
func (HBytes) FindAllRegexp ¶ added in v1.0.74
FindAllRegexp searches the HBytes for all occurrences of the regular expression pattern and returns an HOption[HSlice[HBytes]] containing a slice of matched substrings. If no matches are found, the HOption[HSlice[HBytes]] will be None.
func (HBytes) FindAllRegexpN ¶ added in v1.0.74
FindAllRegexpN searches the HBytes for up to n occurrences of the regular expression pattern and returns an HOption[HSlice[HBytes]] containing a slice of matched substrings. If no matches are found, the HOption[HSlice[HBytes]] will be None. If n is negative, all occurrences will be returned.
func (HBytes) FindAllSubmatchRegexp ¶ added in v1.0.74
FindAllSubmatchRegexp searches the HBytes for all occurrences of the regular expression pattern and returns an HOption[HSlice[HSlice[HBytes]]] containing the matched substrings and submatches. The HOption[HSlice[HSlice[HBytes]]] will contain an HSlice[HBytes] for each match, where each HSlice[HBytes] will contain the full match at index 0, followed by any captured submatches. If no match is found, the HOption[HSlice[HSlice[HBytes]]] will be None. This method is equivalent to calling SubmatchAllRegexpN with n = -1, which means it finds all occurrences.
func (HBytes) FindAllSubmatchRegexpN ¶ added in v1.0.74
func (hbs HBytes) FindAllSubmatchRegexpN(pattern *regexp.Regexp, n HInt) HOption[HSlice[HSlice[HBytes]]]
FindAllSubmatchRegexpN searches the HBytes for occurrences of the regular expression pattern and returns an HOption[HSlice[HSlice[HBytes]]] containing the matched substrings and submatches. The HOption[HSlice[HSlice[HBytes]]] will contain an HSlice[HBytes] for each match, where each HSlice[HBytes] will contain the full match at index 0, followed by any captured submatches. If no match is found, the HOption[HSlice[HSlice[HBytes]]] will be None. The 'n' parameter specifies the maximum number of matches to find. If n is negative, it finds all occurrences.
func (HBytes) FindRegexp ¶ added in v1.0.74
FindRegexp searches the HBytes for the first occurrence of the regular expression pattern and returns an HOption[HBytes] containing the matched substring. If no match is found, the HOption[HBytes] will be None.
func (HBytes) FindSubmatchRegexp ¶ added in v1.0.74
FindSubmatchRegexp searches the HBytes for the first occurrence of the regular expression pattern and returns an HOption[HSlice[HBytes]] containing the matched substrings and submatches. The HOption[HSlice[HBytes]] will contain an HSlice[HBytes] for each match, where each HSlice[HBytes] will contain the full match at index 0, followed by any captured submatches. If no match is found, the HOption[HSlice[HBytes]] will be None.
func (HBytes) Gt ¶
func (hbs HBytes) Gt(bs HBytes) bool
Gt checks if the HBytes is greater than another HBytes.
func (HBytes) HString ¶
func (hbs HBytes) HString() HString
HString returns the HBytes as an HString.
func (HBytes) Hash ¶
func (hbs HBytes) Hash() bhash
Hash returns a bhash struct wrapping the given HBytes.
func (HBytes) Index ¶ added in v1.0.19
func (hbs HBytes) Index(bs HBytes) int
Index returns the index of the first instance of bs in hbs, or -1 if bs is not present in hbs.
func (HBytes) IndexByte ¶ added in v1.0.19
IndexByte returns the index of the first instance of the byte b in hbs, or -1 if b is not present in hbs.
func (HBytes) IndexRegexp ¶ added in v1.0.74
IndexRegexp searches for the first occurrence of the regular expression pattern in the HBytes. If a match is found, it returns an Option containing an HSlice with the start and end indices of the match. If no match is found, it returns None.
func (HBytes) IndexRune ¶ added in v1.0.19
IndexRune returns the index of the first instance of the rune r in hbs, or -1 if r is not present in hbs.
func (HBytes) LastIndex ¶ added in v1.0.73
func (hbs HBytes) LastIndex(bs HBytes) int
LastIndex returns the index of the last instance of bs in hbs, or -1 if bs is not present in hbs.
func (HBytes) LastIndexByte ¶ added in v1.0.73
LastIndexByte returns the index of the last instance of the byte b in hbs, or -1 if c is not present in hbs.
func (HBytes) LenRunes ¶
func (hbs HBytes) LenRunes() int
LenRunes returns the number of runes in the HBytes.
func (HBytes) Lt ¶
func (hbs HBytes) Lt(bs HBytes) bool
Lt checks if the HBytes is less than another HBytes.
func (HBytes) Map ¶
Map applies a function to each rune in the HBytes and returns the modified HBytes.
func (HBytes) Ne ¶
func (hbs HBytes) Ne(bs HBytes) bool
Ne checks if the HBytes is not equal to another HBytes.
func (HBytes) NormalizeNFC ¶
func (hbs HBytes) NormalizeNFC() HBytes
NormalizeNFC returns a new HBytes with its Unicode characters normalized using the NFC form.
func (HBytes) NotEmpty ¶
func (hbs HBytes) NotEmpty() bool
NotEmpty checks if the HBytes is not empty.
func (HBytes) Print ¶ added in v1.0.72
func (hbs HBytes) Print() HBytes
Print prints the content of the HBytes to the standard output (console) and returns the HBytes unchanged.
func (HBytes) Repeat ¶
func (hbs HBytes) Repeat(count int) HBytes
Repeat returns a new HBytes consisting of the current HBytes repeated 'count' times.
func (HBytes) Replace ¶
func (hbs HBytes) Replace(oldB, newB HBytes, n int) HBytes
Replace replaces the first 'n' occurrences of 'oldB' with 'newB' in the HBytes.
func (HBytes) ReplaceAll ¶
func (hbs HBytes) ReplaceAll(oldB, newB HBytes) HBytes
ReplaceAll replaces all occurrences of 'oldB' with 'newB' in the HBytes.
func (HBytes) ReplaceRegexp ¶ added in v1.0.73
ReplaceRegexp replaces all occurrences of the regular expression matches in the HBytes with the provided newB and returns the resulting HBytes after the replacement.
func (HBytes) Reverse ¶
func (hbs HBytes) Reverse() HBytes
Reverse returns a new HBytes with the order of its runes reversed.
func (HBytes) Runes ¶
func (hbs HBytes) Runes() []rune
Runes returns the HBytes as a slice of runes.
func (HBytes) Split ¶
func (hbs HBytes) Split(sep ...HBytes) HSlice[HBytes]
Split splits the HBytes at each occurrence of the specified HBytes separator.
func (HBytes) ToLower ¶
func (hbs HBytes) ToLower() HBytes
ToLower converts the HBytes to lowercase.
func (HBytes) ToTitle ¶
func (hbs HBytes) ToTitle() HBytes
ToTitle converts the HBytes to title case.
func (HBytes) ToUpper ¶
func (hbs HBytes) ToUpper() HBytes
ToUpper converts the HBytes to uppercase.
func (HBytes) Trim ¶
func (hbs HBytes) Trim(cutset HString) HBytes
Trim trims the specified characters from the beginning and end of the HBytes.
func (HBytes) TrimLeft ¶
func (hbs HBytes) TrimLeft(cutset HString) HBytes
TrimLeft trims the specified characters from the beginning of the HBytes.
func (HBytes) TrimPrefix ¶
func (hbs HBytes) TrimPrefix(cutset HBytes) HBytes
TrimPrefix trims the specified HBytes prefix from the HBytes.
func (HBytes) TrimRight ¶
func (hbs HBytes) TrimRight(cutset HString) HBytes
TrimRight trims the specified characters from the end of the HBytes.
func (HBytes) TrimSpace ¶
func (hbs HBytes) TrimSpace() HBytes
TrimSpace trims white space characters from the beginning and end of the HBytes.
func (HBytes) TrimSuffix ¶
func (hbs HBytes) TrimSuffix(cutset HBytes) HBytes
TrimSuffix trims the specified HBytes suffix from the HBytes.
type HDir ¶
type HDir struct {
// contains filtered or unexported fields
}
HDir is a struct representing a directory path.
func NewHDir ¶
func NewHDir(path HString) *HDir
NewHDir returns a new HDir instance with the given path.
func (*HDir) CopyDir ¶
func (hd *HDir) CopyDir(dest HString) HResult[*HDir]
CopyDir copies the contents of the current directory to the destination directory.
Parameters:
- dest (HString): The destination directory where the contents of the current directory should be copied.
Returns:
- *HDir: A pointer to a new HDir instance representing the destination directory.
Example usage:
sourceDir := hg.NewHDir("path/to/source") destinationDir := sourceDir.CopyDir("path/to/destination")
func (HDir) Exist ¶
func (hd HDir) Exist() bool
Exist checks if the current directory exists.
Returns:
- bool: true if the current directory exists, false otherwise.
Example usage:
dir := hg.NewHDir("path/to/directory") exists := dir.Exist()
func (*HDir) Glob ¶
func (hd *HDir) Glob() HResult[HSlice[*HFile]]
Glob matches files in the current directory using the path pattern and returns a slice of HFile instances.
Returns:
- []*HFile: A slice of HFile instances representing the files that match the provided pattern in the current directory.
Example usage:
dir := hg.NewHDir("path/to/directory/*.txt") files := dir.Glob()
func (HDir) HString ¶
func (hd HDir) HString() HString
HString returns the HString representation of the current directory's path.
func (*HDir) Join ¶
func (hd *HDir) Join(elem ...HString) HResult[HString]
Join joins the current directory path with the given path elements, returning the joined path.
Parameters:
- elem (...HString): One or more HString values representing path elements to be joined with the current directory path.
Returns:
- HString: The resulting joined path as an HString.
Example usage:
dir := hg.NewHDir("path/to/directory") joinedPath := dir.Join("subdir", "file.txt")
func (*HDir) Mkdir ¶
Mkdir creates a new directory with the specified mode (optional).
Parameters:
- mode (os.FileMode, optional): The file mode for the new directory. If not provided, it defaults to DirDefault (0755).
Returns:
- *HDir: A pointer to the HDir instance on which the method was called.
Example usage:
dir := hg.NewHDir("path/to/directory") createdDir := dir.Mkdir(0755) // Optional mode argument
func (*HDir) MkdirAll ¶
MkdirAll creates all directories along the given path, with the specified mode (optional).
Parameters:
- mode ...os.FileMode (optional): The file mode to be used when creating the directories. If not provided, it defaults to the value of DirDefault constant (0755).
Returns:
- *HDir: A pointer to the HDir instance representing the created directories.
Example usage:
dir := hg.NewHDir("path/to/directory") dir.MkdirAll() dir.MkdirAll(0755)
func (*HDir) Move ¶ added in v1.0.108
func (hd *HDir) Move(newpath HString) HResult[*HDir]
Move function simply calls HDir.Rename
func (*HDir) Path ¶
func (hd *HDir) Path() HResult[HString]
Path returns the absolute path of the current directory.
Returns:
- HString: The absolute path of the current directory as an HString. If an error occurs while converting the path to an absolute path, the error is stored in hd.err, which can be checked using the Error() method.
Example usage:
dir := hg.NewHDir("path/to/directory") absPath := dir.Path()
func (*HDir) Print ¶ added in v1.0.72
func (hd *HDir) Print() *HDir
Print prints the content of the HDir to the standard output (console) and returns the HDir unchanged.
func (*HDir) ReadDir ¶
func (hd *HDir) ReadDir() HResult[HSlice[*HFile]]
ReadDir reads the content of the current directory and returns a slice of HFile instances.
Returns:
- []*HFile: A slice of HFile instances representing the files and directories in the current directory.
Example usage:
dir := hg.NewHDir("path/to/directory") files := dir.ReadDir()
func (*HDir) Rename ¶
func (hd *HDir) Rename(newpath HString) HResult[*HDir]
Rename renames the current directory to the new path.
Parameters:
- newpath HString: The new path for the directory.
Returns:
- *HDir: A pointer to the HDir instance representing the renamed directory. If an error occurs, the original HDir instance is returned with the error stored in hd.err, which can be checked using the Error() method.
Example usage:
dir := hg.NewHDir("path/to/directory") dir.Rename("path/to/new_directory")
func (*HDir) SetPath ¶
func (hd *HDir) SetPath(path HString) *HDir
SetPath sets the path of the current directory.
Parameters:
- path (HString): The new path to be set for the current directory.
Returns:
- *HDir: A pointer to the updated HDir instance with the new path.
Example usage:
dir := hg.NewHDir("path/to/directory") dir.SetPath("new/path/to/directory")
type HFile ¶
type HFile struct {
// contains filtered or unexported fields
}
HFile is a struct that represents a file along with an iterator for reading lines.
func NewHFile ¶
func NewHFile(name HString) *HFile
NewHFile returns a new HFile instance with the given name.
func (*HFile) Append ¶
Append appends the given content to the file, with the specified mode (optional). If no FileMode is provided, the default FileMode (0644) is used.
func (*HFile) Close ¶
func (hf *HFile) Close()
Close closes the HFile's underlying file, if it is not already closed.
func (*HFile) Copy ¶
Copy copies the file to the specified destination, with the specified mode (optional). If no mode is provided, the default FileMode (0644) is used.
func (HFile) HDir ¶
func (hf HFile) HDir() HResult[*HDir]
HDir returns the directory the file is in as an HDir instance.
func (*HFile) Iterator ¶
func (hf *HFile) Iterator() HResult[*hfiter]
Iterator returns a new hfiter instance that can be used to read the file line by line, word by word, rune by rune, or byte by byte.
Returns:
- *hfiter: A pointer to the new hfiter instance.
Example usage:
hf := hg.NewHFile("file.txt") iterator := hf.Iterator() // Returns a new hfiter instance for the file
func (*HFile) MimeType ¶
func (hf *HFile) MimeType() HResult[HString]
MimeType returns the MIME type of the file as an HString.
func (*HFile) Move ¶ added in v1.0.108
func (hf *HFile) Move(newpath HString) HResult[*HFile]
Move function simply calls HFile.Rename
func (HFile) Path ¶
func (hf HFile) Path() HResult[HString]
Path returns the absolute path of the file.
func (*HFile) Print ¶ added in v1.0.72
func (hf *HFile) Print() *HFile
Print prints the content of the HFile to the standard output (console) and returns the HFile unchanged.
func (*HFile) Read ¶
func (hf *HFile) Read() HResult[HString]
Read reads the content of the file and returns it as an HString.
func (HFile) ReadLines ¶
func (hf HFile) ReadLines() HResult[HSlice[HString]]
ReadLines reads the file and returns its content as a slice of lines.
func (*HFile) Rename ¶
func (hf *HFile) Rename(newpath HString) HResult[*HFile]
Rename renames the file to the specified new path.
func (*HFile) SeekToLine ¶
SeekToLine moves the file pointer to the specified line number and reads the specified number of lines from that position. The function returns the new position and a concatenation of the lines read as an HString.
Parameters:
- position int64: The starting position in the file to read from
- linesRead int: The number of lines to read.
Returns:
- int64: The new file position after reading the specified number of lines
- HString: A concatenation of the lines read as an HString.
Example usage:
hf := hg.NewHFile("file.txt") position, content := hf.SeekToLine(0, 5) // Read 5 lines from the beginning of the file
func (HFile) Split ¶
func (hf HFile) Split() (*HDir, *HFile)
Split splits the file path into its directory and file components.
func (*HFile) Stat ¶ added in v1.0.69
Stat returns the fs.FileInfo of the file. It calls the file's Stat method if the file is open, or os.Stat otherwise.
func (*HFile) TempFile ¶
func (*HFile) TempFile(args ...HString) HResult[*HFile]
TempFile creates a new temporary file in the specified directory with the specified name pattern, and returns a pointer to the HFile. If no directory is specified, the default directory for temporary files is used. If no name pattern is specified, the default pattern "*" is used.
Parameters:
- args ...HString: A variadic parameter specifying the directory and/or name pattern for the temporary file.
Returns:
- *HFile: A pointer to the HFile representing the temporary file.
Example usage:
hf := hg.NewHFile("") tmpfile := hf.TempFile() // Creates a temporary file with default settings tmpfileWithDir := hf.TempFile("mydir") // Creates a temporary file in "mydir" directory tmpfileWithPattern := hf.TempFile("", "tmp") // Creates a temporary file with "tmp" pattern
type HFloat ¶
type HFloat float64
HFloat is an alias for the float64 type.
func NewHFloat ¶
func NewHFloat(floats ...float64) HFloat
NewHFloat creates a new HFloat with the provided float64 value.
func (HFloat) Add ¶
func (hf HFloat) Add(b HFloat) HFloat
Add adds two HFloats and returns the result.
func (HFloat) Compare ¶
func (hf HFloat) Compare(b HFloat) HInt
Compare compares two HFloats and returns an HInt.
func (HFloat) Div ¶
func (hf HFloat) Div(b HFloat) HFloat
Div divides two HFloats and returns the result.
func (HFloat) Gt ¶
func (hf HFloat) Gt(b HFloat) bool
Gt checks if the HFloat is greater than the specified HFloat.
func (HFloat) HString ¶
func (hf HFloat) HString() HString
HString returns the HFloat as an HString.
func (HFloat) Hash ¶
func (hf HFloat) Hash() fhash
Hash returns a fhash struct wrapping the given HFloat.
func (HFloat) Lt ¶
func (hf HFloat) Lt(b HFloat) bool
Lt checks if the HFloat is less than the specified HFloat.
func (HFloat) Max ¶ added in v1.0.102
func (hf HFloat) Max(b ...HFloat) HFloat
Max returns the maximum of two HFloats.
func (HFloat) Min ¶ added in v1.0.102
func (hf HFloat) Min(b ...HFloat) HFloat
Min returns the minimum of two HFloats.
func (HFloat) Mul ¶
func (hf HFloat) Mul(b HFloat) HFloat
Mul multiplies two HFloats and returns the result.
func (HFloat) Print ¶ added in v1.0.72
func (hf HFloat) Print() HFloat
Print prints the value of the HFloat to the standard output (console) and returns the HFloat unchanged.
func (HFloat) Round ¶
func (hf HFloat) Round() HInt
Round rounds the HFloat to the nearest integer and returns the result as an HInt.
func (HFloat) RoundDecimal ¶
func (hf HFloat) RoundDecimal(precision int) HFloat
RoundDecimal rounds the HFloat value to the specified number of decimal places.
The function takes the number of decimal places (precision) as an argument and returns a new HFloat value rounded to that number of decimals. This is achieved by multiplying the HFloat value by a power of 10 equal to the desired precision, rounding the result, and then dividing the rounded result by the same power of 10.
Parameters:
- precision (int): The number of decimal places to round the HFloat value to.
Returns:
- HFloat: A new HFloat value rounded to the specified number of decimal places.
Example usage:
hf := hg.HFloat(3.14159) rounded := hf.RoundDecimal(2) // rounded will be 3.14
type HInt ¶
type HInt int
HInt is an alias for the int type.
func NewHInt ¶
func NewHInt(ints ...int) HInt
NewHInt creates a new HInt with the provided int value.
func (HInt) Abs ¶ added in v1.0.77
func (hi HInt) Abs() HInt
Abs returns the absolute value of the HInt.
func (HInt) Gt ¶
func (hi HInt) Gt(b HInt) bool
Gt checks if the HInt is greater than the specified HInt.
func (HInt) Gte ¶
func (hi HInt) Gte(b HInt) bool
Gte checks if the HInt is greater than or equal to the specified HInt.
func (HInt) IsNegative ¶
func (hi HInt) IsNegative() bool
IsNegative checks if the HInt is negative.
func (HInt) IsPositive ¶
func (hi HInt) IsPositive() bool
IsPositive checks if the HInt is positive.
func (HInt) Lt ¶
func (hi HInt) Lt(b HInt) bool
Lt checks if the HInt is less than the specified HInt.
func (HInt) Lte ¶
func (hi HInt) Lte(b HInt) bool
Lte checks if the HInt is less than or equal to the specified HInt.
func (HInt) Print ¶ added in v1.0.72
func (hi HInt) Print() HInt
Print prints the value of the HInt to the standard output (console) and returns the HInt unchanged.
func (HInt) Random ¶
func (hi HInt) Random() HInt
Random returns a random HInt in the range [0, hi].
func (HInt) RandomRange ¶
func (HInt) RandomRange(from, to HInt) HInt
RandomRange returns a random HInt in the range [from, to].
func (HInt) Rem ¶ added in v1.0.11
func (hi HInt) Rem(b HInt) HInt
Rem returns the remainder of the division between the receiver and the input value.
type HMap ¶
type HMap[K comparable, V any] map[K]V
HMap is a generic alias for a map.
func HMapFromMap ¶
func HMapFromMap[K comparable, V any](m map[K]V) HMap[K, V]
HMapFromMap creates an HMap from a given Go map.
func HMapOf ¶
func HMapOf[K comparable, V any](entries ...any) HMap[K, V]
HMapOf creates an HMap from a list of alternating keys and values. The function takes a variadic parameter representing a list of alternating keys and values. The keys must be of a comparable type, while the values can be of any type. The function returns a newly created HMap containing the provided key-value pairs.
Parameters:
- entries ...any: A variadic parameter representing a list of alternating keys and values. The number of elements in this list must be even, as it should contain pairs of keys and values.
Returns:
- HMap[K, V]: A new HMap containing the provided key-value pairs.
Panics:
- If the number of elements in 'entries' is not even, as it must contain pairs of keys and values. If the provided keys and values are not of the correct types (K and V, respectively).
Example usage:
hmap := hg.HMapOf["string", int]("key1", 1, "key2", 2, "key3", 3)
func NewHMap ¶
func NewHMap[K comparable, V any](size ...int) HMap[K, V]
NewHMap creates a new HMap of the specified size or an empty HMap if no size is provided.
func (HMap[K, V]) Clear ¶
func (hmap HMap[K, V]) Clear() HMap[K, V]
Clear removes all key-value pairs from the HMap.
func (HMap[K, V]) Clone ¶
func (hmap HMap[K, V]) Clone() HMap[K, V]
Clone creates a new HMap that is a copy of the original HMap.
func (HMap[K, V]) Contains ¶
func (hmap HMap[K, V]) Contains(key K) bool
Contains checks if the HMap contains the specified key.
func (HMap[K, V]) Copy ¶
func (hmap HMap[K, V]) Copy(src HMap[K, V]) HMap[K, V]
Copy copies the source HMap's key-value pairs to the target HMap.
func (HMap[K, V]) Delete ¶
func (hmap HMap[K, V]) Delete(keys ...K) HMap[K, V]
Delete removes the specified keys from the HMap.
func (HMap[K, V]) Eq ¶
func (hmap HMap[K, V]) Eq(other HMap[K, V]) bool
Eq checks if two HMaps are equal.
func (HMap[K, V]) Filter ¶
func (hmap HMap[K, V]) Filter(fn func(K, V) bool) HMap[K, V]
Filter filters the HMap based on a given function and returns a new HMap containing the matching key-value pairs. The provided function 'fn' should take a key and a value as input parameters and return a boolean value. If the function returns true, the key-value pair will be included in the resulting HMap.
Parameters:
- fn func(K, V) bool: A function that takes a key and a value as input parameters and returns a boolean value.
Returns:
- HMap[K, V]: A new HMap containing the key-value pairs for which the provided function returned true.
Example usage:
filteredHMap := originalHMap.Filter(func(key K, value V) bool { return value >= 10 })
func (HMap[K, V]) FilterParallel ¶
func (hmap HMap[K, V]) FilterParallel(fn func(K, V) bool) HMap[K, V]
FilterParallel filters the HMap based on a given function in parallel and returns a new HMap containing the matching key-value pairs. The provided function 'fn' should take a key and a value as input parameters and return a boolean value. If the function returns true, the key-value pair will be included in the resulting HMap. This function is designed for better performance on large HMaps by utilizing parallel processing.
Parameters:
- fn func(K, V) bool: A function that takes a key and a value as input parameters and returns a boolean value.
Returns:
- HMap[K, V]: A new HMap containing the key-value pairs for which the provided function returned true.
Example usage:
filteredHMap := originalHMap.FilterParallel(func(key K, value V) bool { return value >= 10 })
TODO: написать тесты.
func (HMap[K, V]) ForEach ¶
func (hmap HMap[K, V]) ForEach(fn func(K, V))
ForEach applies a function to each key-value pair in the HMap. The provided function 'fn' should take a key and a value as input parameters and perform an operation. This function is useful for side effects, as it does not return a new HMap.
Parameters:
- fn func(K, V): A function that takes a key and a value as input parameters and performs an operation.
Example usage:
originalHMap.ForEach(func(key K, value V) { fmt.Printf("Key: %v, Value: %v\n", key, value) })
func (HMap[K, V]) Get ¶
func (hmap HMap[K, V]) Get(k K) V
Get retrieves the value associated with the given key.
func (HMap[K, V]) GetOrDefault ¶
func (hmap HMap[K, V]) GetOrDefault(key K, defaultValue V) V
GetOrDefault returns the value for a key. If the key does not exist, returns the default value instead. This function is useful when you want to provide a fallback value for keys that may not be present in the HMap.
Parameters:
- key K: The key for which to retrieve the value.
- defaultValue V: The default value to return if the key does not exist in the HMap.
Returns:
- V: The value associated with the key if it exists in the HMap, or the default value if the key is not found.
Example usage:
value := hmap.GetOrDefault("someKey", "defaultValue")
func (HMap[K, V]) GetOrSet ¶ added in v1.0.108
func (hmap HMap[K, V]) GetOrSet(key K, defaultValue V) V
GetOrSet returns the value for a key. If the key exists in the HMap, it returns the associated value. If the key does not exist, it sets the key to the provided default value and returns that value. This function is useful when you want to both retrieve and potentially set a default value for keys that may or may not be present in the HMap.
Parameters:
- key K: The key for which to retrieve the value.
- defaultValue V: The default value to return if the key does not exist in the HMap. If the key is not found, this default value will also be set for the key in the HMap.
Returns:
- V: The value associated with the key if it exists in the HMap, or the default value if the key is not found.
Eaxmple usage:
// Create a new ordered HMap called "gos" with string keys and integer pointers as values gos := hg.NewHMap[string, *int]() // Use GetOrSet to set the value for the key "root" to 3 if it doesn't exist, // and then print whether the value is equal to 3. gos.GetOrSet("root", ref.Of(3)) fmt.Println(*gos.Get("root") == 3) // Should print "true" // Use GetOrSet to retrieve the value for the key "root" (which is 3), multiply it by 2, // and then print whether the value is equal to 6. *gos.GetOrSet("root", ref.Of(3)) *= 2 fmt.Println(*gos.Get("root") == 6) // Should print "true"
In this example, you first create an ordered HMap "gos" with string keys and integer pointers as values. Then, you use GetOrSet to set and retrieve values for the key "root" with default values of 3 and perform multiplication operations, demonstrating the behavior of GetOrSet.
func (HMap[K, V]) Invert ¶
func (hmap HMap[K, V]) Invert() HMap[any, K]
Invert inverts the keys and values of the HMap, returning a new HMap with values as keys and keys as values. Note that the inverted HMap will have 'any' as the key type, since not all value types are guaranteed to be comparable.
func (HMap[K, V]) Keys ¶
func (hmap HMap[K, V]) Keys() HSlice[K]
Keys returns a slice of the HMap's keys.
func (HMap[K, V]) Len ¶
func (hmap HMap[K, V]) Len() int
Len returns the number of key-value pairs in the HMap.
func (HMap[K, V]) Map ¶
func (hmap HMap[K, V]) Map(fn func(K, V) (K, V)) HMap[K, V]
Map applies a function to each key-value pair in the HMap and returns a new HMap with the results. The provided function 'fn' should take a key and a value as input parameters and return a new key-value pair.
Parameters:
- fn func(K, V) (K, V): A function that takes a key and a value as input parameters and returns a new key-value pair.
Returns:
- HMap[K, V]: A new HMap containing the key-value pairs resulting from applying the provided function to each key-value pair in the original HMap.
Example usage:
mappedHMap := originalHMap.Map(func(key K, value V) (K, V) { return key, value * 2 })
func (HMap[K, V]) MapAny ¶ added in v1.0.105
MapAny applies a function to each key-value pair in the HMap and returns a new HMap with the results. The provided function 'fn' should take a key and a value as input parameters and return a new key-value pair, where the value can be of any type ('any').
Parameters:
- fn func(K, V) (K, any): A function that takes a key and a value as input parameters and returns a new key-value pair, where the value can be of any type ('any').
Returns:
- HMap[K, any]: A new HMap containing the key-value pairs resulting from applying the provided function to each key-value pair in the original HMap. The value type in the resulting HMap is 'any'.
Example usage:
mappedHMap := originalHMap.MapAny(func(key K, value V) (K, any) { // You can transform the value to any type here. // For example, you can convert it to a different data type. // In this example, we are converting the value to a string. return key, strconv.Itoa(value) })
func (HMap[K, V]) MapParallel ¶
func (hmap HMap[K, V]) MapParallel(fn func(K, V) (K, V)) HMap[K, V]
MapParallel applies a function to each key-value pair in the HMap in parallel and returns a new HMap with the results. The provided function 'fn' should take a key and a value as input parameters and return a new key-value pair. This function is designed for better performance on large HMaps by utilizing parallel processing.
Parameters:
- fn func(K, V) (K, V): A function that takes a key and a value as input parameters and returns a new key-value pair.
Returns:
- HMap[K, V]: A new HMap containing the key-value pairs resulting from applying the provided function to each key-value pair in the original HMap.
Example usage:
mappedHMap := originalHMap.MapParallel(func(key K, value V) (K, V) { return key, value * 2 })
func (HMap[K, V]) Ne ¶
func (hmap HMap[K, V]) Ne(other HMap[K, V]) bool
Ne checks if two HMaps are not equal.
func (HMap[K, V]) NotEmpty ¶
func (hmap HMap[K, V]) NotEmpty() bool
NotEmpty checks if the HMap is not empty.
func (HMap[K, V]) Print ¶ added in v1.0.72
func (hmap HMap[K, V]) Print() HMap[K, V]
Print prints the key-value pairs of the HMap to the standard output (console) and returns the HMap unchanged.
func (HMap[K, V]) Set ¶
func (hmap HMap[K, V]) Set(k K, v V) HMap[K, V]
Set sets the value for the given key in the HMap.
func (HMap[K, V]) String ¶
func (hmap HMap[K, V]) String() string
String returns a string representation of the HMap.
type HMapOrd ¶ added in v1.0.18
type HMapOrd[K comparable, V any] HSlice[hMapPair[K, V]]
HMapOrd is a generic alias for a slice of ordered key-value pairs.
func HMapOrdFromHMap ¶
func HMapOrdFromHMap[K comparable, V any](hmap HMap[K, V]) *HMapOrd[K, V]
HMapOrdFromHMap converts a standard HMap to an ordered HMap. The resulting ordered HMap will maintain the order of its key-value pairs based on the order of insertion. This function is useful when you want to create an ordered HMap from an existing HMap.
Parameters:
- hmap HMap[K, V]: The input HMap to be converted to an ordered HMap.
Returns:
- *hMapOrd[K, V]: A pointer to a new ordered HMap containing the same key-value pairs as the input HMap.
Example usage:
hmapOrd := hg.HMapOrdFromHMap[string, int](hmap)
Converts the standard HMap 'hmap' to an ordered HMap.
func HMapOrdFromMap ¶
func HMapOrdFromMap[K comparable, V any](m map[K]V) *HMapOrd[K, V]
HMapOrdFromMap converts a standard Go map to an ordered HMap. The resulting ordered HMap will maintain the order of its key-value pairs based on the order of insertion. This function is useful when you want to create an ordered HMap from an existing Go map.
Parameters:
- m map[K]V: The input Go map to be converted to an ordered HMap.
Returns:
- *hMapOrd[K, V]: A pointer to a new ordered HMap containing the same key-value pairs as the input Go map.
Example usage:
hmapOrd := hg.HMapOrdFromMap[string, int](goMap)
Converts the standard Go map 'map[K]V' to an ordered HMap.
func NewHMapOrd ¶
func NewHMapOrd[K comparable, V any](size ...int) *HMapOrd[K, V]
NewHMapOrd creates a new ordered HMap with the specified size (if provided). An ordered HMap is an HMap that maintains the order of its key-value pairs based on the insertion order. If no size is provided, the default size will be used.
Parameters:
- size ...int: (Optional) The initial size of the ordered HMap. If not provided, a default size will be used.
Returns:
- *hMapOrd[K, V]: A pointer to a new ordered HMap with the specified initial size (or default size if not provided).
Example usage:
hmapOrd := hg.NewHMapOrd[string, int](10)
Creates a new ordered HMap with an initial size of 10.
func (*HMapOrd[K, V]) Clear ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) Clear() *HMapOrd[K, V]
Clear removes all key-value pairs from the ordered HMap.
func (*HMapOrd[K, V]) Clone ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) Clone() *HMapOrd[K, V]
Clone creates a new ordered HMap with the same key-value pairs.
func (*HMapOrd[K, V]) Contains ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) Contains(key K) bool
Contains checks if the ordered HMap contains the specified key.
func (*HMapOrd[K, V]) Copy ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) Copy(src *HMapOrd[K, V]) *HMapOrd[K, V]
Copy copies key-value pairs from the source ordered HMap to the current ordered HMap.
func (*HMapOrd[K, V]) Delete ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) Delete(keys ...K) *HMapOrd[K, V]
Delete removes the specified keys from the ordered HMap.
func (*HMapOrd[K, V]) Empty ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) Empty() bool
Empty checks if the ordered HMap is empty.
func (*HMapOrd[K, V]) Eq ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) Eq(other *HMapOrd[K, V]) bool
Eq compares the current ordered HMap to another ordered HMap and returns true if they are equal.
func (*HMapOrd[K, V]) Filter ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) Filter(fn func(K, V) bool) *HMapOrd[K, V]
Filter filters the ordered HMap based on a provided predicate function, returning a new ordered HMap with only the key-value pairs that satisfy the predicate. The predicate function should take the key and value as input and return a boolean value. This function is useful when you want to create a new ordered HMap containing only the key-value pairs that meet certain criteria.
Parameters:
- fn func(K, V) bool: The predicate function that takes the key and value as input and returns a boolean value.
Returns:
- *hMapOrd[K, V]: A pointer to a new ordered HMap containing only the key-value pairs that satisfy the predicate.
Example usage:
hmapo.Filter(func(k string, v int) bool { return v > 10 })
Filters the ordered HMap to include only the key-value pairs where the value is greater than 10.
func (*HMapOrd[K, V]) ForEach ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) ForEach(fn func(K, V))
ForEach executes a provided function for each key-value pair in the ordered HMap. This function is useful when you want to perform an operation or side effect for each key-value pair in the ordered HMap.
Parameters:
- fn func(K, V): The function to execute for each key-value pair in the ordered HMap. It takes a key (K) and a value (V) as arguments.
Example usage:
hmapo.ForEach(func(key K, value V) { fmt.Printf("Key: %v, Value: %v\n", key, value) }).
Prints each key-value pair in the ordered HMap.
func (*HMapOrd[K, V]) Get ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) Get(key K) (V, bool)
Get retrieves the value for the specified key, along with a boolean indicating whether the key was found in the ordered HMap. This function is useful when you want to access the value associated with a key in the ordered HMap, and also check if the key exists in the map.
Parameters:
- key K: The key to search for in the ordered HMap.
Returns:
- V: The value associated with the specified key if found, or the zero value for the value type if the key is not found.
- bool: A boolean value indicating whether the key was found in the ordered HMap.
Example usage:
value, found := hmapo.Get("some_key")
Retrieves the value associated with the key "some_key" and checks if the key exists in the ordered HMap.
func (*HMapOrd[K, V]) GetOrDefault ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) GetOrDefault(key K, defaultValue V) V
GetOrDefault returns the value for a key. If the key does not exist, returns the default value instead. This function is useful when you want to access the value associated with a key in the ordered HMap, but if the key does not exist, you want to return a specified default value.
Parameters:
- key K: The key to search for in the ordered HMap.
- defaultValue V: The default value to return if the key is not found in the ordered HMap.
Returns:
- V: The value associated with the specified key if found, or the provided default value if the key is not found.
Example usage:
value := hmapo.GetOrDefault("some_key", "default_value")
Retrieves the value associated with the key "some_key" or returns "default_value" if the key is not found.
func (*HMapOrd[K, V]) GetOrSet ¶ added in v1.0.108
func (hmapo *HMapOrd[K, V]) GetOrSet(key K, defaultValue V) V
GetOrSet returns the value for a key. If the key does not exist, it returns the default value instead and also sets the default value for the key in the ordered HMap. This function is useful when you want to access the value associated with a key in the ordered HMap, and if the key does not exist, you want to return a specified default value and set that default value for the key.
Parameters:
- key K: The key to search for in the ordered HMap.
- defaultValue V: The default value to return if the key is not found in the ordered HMap. If the key is not found, this default value will also be set for the key in the ordered HMap.
Returns:
- V: The value associated with the specified key if found, or the provided default value if the key is not found.
Example usage:
value := hmapo.GetOrSet("some_key", "default_value")
Retrieves the value associated with the key "some_key" or returns "default_value" if the key is not found, and sets "default_value" as the value for "some_key" in the ordered HMap if it's not present.
func (*HMapOrd[K, V]) Invert ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) Invert() *HMapOrd[any, K]
Invert inverts the key-value pairs in the ordered HMap, creating a new ordered HMap with the values as keys and the original keys as values.
func (*HMapOrd[K, V]) Keys ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) Keys() HSlice[K]
Keys returns an HSlice containing all the keys in the ordered HMap.
func (*HMapOrd[K, V]) Len ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) Len() int
Len returns the number of key-value pairs in the ordered HMap.
func (*HMapOrd[K, V]) Map ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) Map(fn func(K, V) (K, V)) *HMapOrd[K, V]
Map applies a provided function to all key-value pairs in the ordered HMap and returns a new ordered HMap with the results. The provided function should take the key and value as input and return a new key-value pair as output. This function is useful when you want to transform the key-value pairs of an ordered HMap using a custom function.
Parameters:
- fn func(K, V) (K, V): The custom function that takes the key and value as input and returns a new key-value pair.
Returns:
- *hMapOrd[K, V]: A pointer to a new ordered HMap containing the key-value pairs after applying the custom function.
Example usage:
hmapo.Map(func(k string, v int) (string, int) { return strings.ToUpper(k), v * 2 }) // Transforms the keys to uppercase and doubles the values in the ordered HMap.
func (*HMapOrd[K, V]) MapAny ¶ added in v1.0.105
MapAny applies a provided function to all key-value pairs in the ordered HMap and returns a new ordered HMap with the results. The provided function should take the key and value as input and return a new key-value pair as output. This function is useful when you want to transform the key-value pairs of an ordered HMap using a custom function, where the value can be of any type ('any').
Parameters:
- fn func(K, V) (K, any): The custom function that takes the key and value as input and returns a new key-value pair, where the value can be of any type ('any').
Returns:
- *HMapOrd[K, any]: A pointer to a new ordered HMap containing the key-value pairs after applying the custom function. The value type in the resulting HMap is 'any'.
Example usage:
hmapo.MapAny(func(k string, v int) (string, any) { // You can transform the value to any type here. // For example, you can convert it to a different data type. // In this example, we are converting the value to a string. return strings.ToUpper(k), strconv.Itoa(v) }) // Transforms the keys to uppercase and converts the values to strings in the ordered HMap.
func (*HMapOrd[K, V]) Ne ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) Ne(other *HMapOrd[K, V]) bool
Ne compares the current ordered HMap to another ordered HMap and returns true if they are not equal.
func (*HMapOrd[K, V]) NotEmpty ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) NotEmpty() bool
NotEmpty checks if the ordered HMap is not empty.
func (*HMapOrd[K, V]) Print ¶ added in v1.0.72
func (hmapo *HMapOrd[K, V]) Print() *HMapOrd[K, V]
Print prints the key-value pairs of the HMapOrd to the standard output (console) and returns the HMapOrd pointer unchanged.
func (*HMapOrd[K, V]) Set ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) Set(key K, value V) *HMapOrd[K, V]
Set sets the value for the specified key in the ordered HMap.
func (*HMapOrd[K, V]) SortBy ¶ added in v1.0.18
SortBy sorts the ordered HMap by a custom comparison function. The comparison function should return true if the element at index i should be sorted before the element at index j. This function is useful when you want to sort the key-value pairs in an ordered HMap based on a custom comparison logic.
Parameters:
- f func(i, j int) bool: The custom comparison function used for sorting the ordered HMap.
Returns:
- *hMapOrd[K, V]: A pointer to the same ordered HMap, sorted according to the custom comparison function.
Example usage:
hmapo.SortBy(func(i, j int) bool { return (*hmapo)[i].Key < (*hmapo)[j].Key }) hmapo.SortBy(func(i, j int) bool { return (*hmapo)[i].Value < (*hmapo)[j].Value })
func (*HMapOrd[K, V]) String ¶ added in v1.0.18
func (hmapo *HMapOrd[K, V]) String() string
String returns a string representation of the ordered HMap.
type HOption ¶ added in v1.0.73
type HOption[T any] struct { // contains filtered or unexported fields }
HOption is a generic struct for representing an optional value.
func None ¶ added in v1.0.73
func None[T any]() HOption[T]
None creates an Option containing a nil value.
func Some ¶ added in v1.0.73
func Some[T any](value T) HOption[T]
Some creates an Option containing a non-nil value.
func (HOption[T]) Expect ¶ added in v1.0.73
func (o HOption[T]) Expect(msg HString) T
Expect returns the value held in the Option. If the Option contains a nil value, it panics with the provided message.
func (HOption[T]) IsNone ¶ added in v1.0.73
func (o HOption[T]) IsNone() bool
IsNone returns true if the Option contains a nil value.
func (HOption[T]) IsSome ¶ added in v1.0.73
func (o HOption[T]) IsSome() bool
IsSome returns true if the Option contains a non-nil value.
func (HOption[T]) Must ¶ added in v1.0.104
func (o HOption[T]) Must() T
Must returns the value held in the Option. If the Option contains a nil value, it panics.
func (HOption[T]) MustOr ¶ added in v1.0.104
func (o HOption[T]) MustOr(value T) T
MustOr returns the value held in the Option. If the Option contains a nil value, it returns the provided default value.
func (HOption[T]) MustOrDefault ¶ added in v1.0.104
func (o HOption[T]) MustOrDefault() T
MustOrDefault returns the value held in the HOption. If the HOption contains a value, it returns the value. If the HOption is None, it returns the default value for type T.
type HResult ¶ added in v1.0.67
type HResult[T any] struct { // contains filtered or unexported fields }
HResult is a generic struct for representing a result value along with an error.
func Result ¶ added in v1.0.67
Result returns a new HResult[T] based on the provided value and error. If err is not nil, it returns an HResult containing the error. Otherwise, it returns an HResult containing the value.
func (HResult[T]) Expect ¶ added in v1.0.67
func (r HResult[T]) Expect(msg HString) T
Expect returns the value held in the HResult. If the HResult contains an error, it panics with the provided message.
func (HResult[T]) IsOk ¶ added in v1.0.67
IsOk returns true if the HResult contains a value (no error).
func (HResult[T]) Must ¶ added in v1.0.104
func (r HResult[T]) Must() T
Must returns the value held in the HResult. If the HResult contains an error, it panics.
func (HResult[T]) MustOr ¶ added in v1.0.104
func (r HResult[T]) MustOr(value T) T
MustOr returns the value held in the HResult. If the HResult contains an error, it returns the provided default value.
func (HResult[T]) MustOrDefault ¶ added in v1.0.104
func (r HResult[T]) MustOrDefault() T
MustOrDefault returns the value held in the HResult. If the HResult contains an error, it returns the default value for type T. Otherwise, it returns the value held in the HResult.
type HSet ¶ added in v1.0.36
type HSet[T comparable] map[T]struct{}
HSet is a generic alias for a set implemented using a map.
func HSetOf ¶ added in v1.0.36
func HSetOf[T comparable](values ...T) HSet[T]
HSetOf creates a new generic set containing the provided elements.
func NewHSet ¶ added in v1.0.36
func NewHSet[T comparable](size ...int) HSet[T]
NewHSet creates a new HSet of the specified size or an empty HSet if no size is provided.
func (HSet[T]) Add ¶ added in v1.0.36
func (s HSet[T]) Add(values ...T) HSet[T]
Add adds the provided elements to the set and returns the modified set.
func (HSet[T]) Clear ¶ added in v1.0.36
func (s HSet[T]) Clear() HSet[T]
Clear removes all values from the HSet.
func (HSet[T]) Clone ¶ added in v1.0.36
func (s HSet[T]) Clone() HSet[T]
Clone creates a new HSet that is a copy of the original HSet.
func (HSet[T]) Contains ¶ added in v1.0.36
func (s HSet[T]) Contains(v T) bool
Contains checks if the HSet contains the specified value.
func (HSet[T]) ContainsAll ¶ added in v1.0.36
func (s HSet[T]) ContainsAll(other HSet[T]) bool
ContainsAll checks if the HSet contains all elements from another HSet.
func (HSet[T]) ContainsAny ¶ added in v1.0.36
func (s HSet[T]) ContainsAny(other HSet[T]) bool
ContainsAny checks if the HSet contains any element from another HSet.
func (HSet[T]) Difference ¶ added in v1.0.36
func (s HSet[T]) Difference(other HSet[T]) HSet[T]
Difference returns the difference between the current set and another set, i.e., elements present in the current set but not in the other set.
Parameters:
- other HSet[T]: The other set to calculate the difference with.
Returns:
- HSet[T]: A new HSet containing the difference between the two sets.
Example usage:
s1 := hg.HSetOf(1, 2, 3, 4, 5) s2 := hg.HSetOf(4, 5, 6, 7, 8) diff := s1.Difference(s2)
The resulting diff will be: [1, 2, 3].
func (HSet[T]) Empty ¶ added in v1.0.36
func (s HSet[T]) Empty() bool
Empty checks if the HSet is empty.
func (HSet[T]) Eq ¶ added in v1.0.36
func (s HSet[T]) Eq(other HSet[T]) bool
Eq checks if two HSets are equal.
func (HSet[T]) Filter ¶ added in v1.0.36
func (s HSet[T]) Filter(fn func(T) bool) HSet[T]
Filter returns a new set containing elements that satisfy a given condition.
The function takes one parameter of type T (the same type as the elements of the set) and returns a boolean value. If the returned value is true, the element is added to a new set, which is then returned as the result.
Parameters:
- fn (func(T) bool): The function to be applied to each element of the set to determine if it should be included in the result.
Returns:
- HSet[T]: A new set containing the elements that satisfy the given condition.
Example usage:
s := hg.HSetOf(1, 2, 3, 4, 5) even := s.Filter(func(val int) bool { return val%2 == 0 }) fmt.Println(even)
Output: [2 4].
func (HSet[T]) ForEach ¶ added in v1.0.36
func (s HSet[T]) ForEach(fn func(T))
ForEach applies a function to each value in the HSet. The provided function 'fn' should take a value as input parameter and perform an operation. This function is useful for side effects, as it does not return a new HSet.
Parameters:
- fn func(T): A function that takes a value as input parameter and performs an operation.
Example usage:
originalHSet.ForEach(func(value T) { fmt.Printf("Value: %v\n", value) })
func (HSet[T]) HSlice ¶ added in v1.0.36
func (s HSet[T]) HSlice() HSlice[T]
HSlice returns a new HSlice with the same elements as the HSet[T].
func (HSet[T]) Intersection ¶ added in v1.0.36
func (s HSet[T]) Intersection(other HSet[T]) HSet[T]
Intersection returns the intersection of the current set and another set, i.e., elements present in both sets.
Parameters:
- other HSet[T]: The other set to calculate the intersection with.
Returns:
- HSet[T]: A new HSet containing the intersection of the two sets.
Example usage:
s1 := hg.HSetOf(1, 2, 3, 4, 5) s2 := hg.HSetOf(4, 5, 6, 7, 8) intersection := s1.Intersection(s2)
The resulting intersection will be: [4, 5].
func (HSet[T]) Len ¶ added in v1.0.36
func (s HSet[T]) Len() int
Len returns the number of values in the HSet.
func (HSet[T]) Map ¶ added in v1.0.36
func (s HSet[T]) Map(fn func(T) T) HSet[T]
Map returns a new set by applying a given function to each element in the current set.
The function takes one parameter of type T (the same type as the elements of the set) and returns a value of type T. The returned value is added to a new set, which is then returned as the result.
Parameters:
- fn (func(T) T): The function to be applied to each element of the set.
Returns:
- HSet[T]: A new set containing the results of applying the function to each element of the current set.
Example usage:
s := hg.HSetOf(1, 2, 3) doubled := s.Map(func(val int) int { return val * 2 }) fmt.Println(doubled)
Output: [2 4 6].
func (HSet[T]) MapAny ¶ added in v1.0.101
MapAny returns a new set with transformed elements by applying a given function.
The function takes one parameter of type T (the same type as the elements of the set) and returns a value of any type (interface{}). The returned value is added to a new set, which is then returned as the result.
Parameters:
- fn (func(T) any): The function to be applied to each element of the set.
Returns:
- HSet[any]: A new set containing the results of applying the function to each element of the current set.
Example usage:
s := hg.HSetOf(1, 2, 3) setOfStrings := s.MapAny(func(i int) any { return "str: " + strconv.Itoa(i) }) fmt.Println(setOfStrings)
Output: HSet{str: 3, str: 1, str: 2}.
func (HSet[T]) Ne ¶ added in v1.0.36
func (s HSet[T]) Ne(other HSet[T]) bool
Ne checks if two HSets are not equal.
func (HSet[T]) Print ¶ added in v1.0.72
func (s HSet[T]) Print() HSet[T]
Print prints the elements of the HSet to the standard output (console) and returns the HSet unchanged.
func (HSet[T]) Remove ¶ added in v1.0.36
func (s HSet[T]) Remove(values ...T) HSet[T]
Remove removes the specified values from the HSet.
func (HSet[T]) String ¶ added in v1.0.36
func (s HSet[T]) String() string
String returns a string representation of the HSet.
func (HSet[T]) Subset ¶ added in v1.0.37
func (s HSet[T]) Subset(other HSet[T]) bool
Subset checks if the current set 's' is a subset of the provided 'other' set. A set 's' is a subset of 'other' if all elements of 's' are also elements of 'other'.
Parameters:
- other HSet[T]: The other set to compare with.
Returns:
- bool: true if 's' is a subset of 'other', false otherwise.
Example usage:
s1 := hg.HSetOf(1, 2, 3) s2 := hg.HSetOf(1, 2, 3, 4, 5) isSubset := s1.Subset(s2) // Returns true
func (HSet[T]) Superset ¶ added in v1.0.37
func (s HSet[T]) Superset(other HSet[T]) bool
Superset checks if the current set 's' is a superset of the provided 'other' set. A set 's' is a superset of 'other' if all elements of 'other' are also elements of 's'.
Parameters:
- other HSet[T]: The other set to compare with.
Returns:
- bool: true if 's' is a superset of 'other', false otherwise.
Example usage:
s1 := hg.HSetOf(1, 2, 3, 4, 5) s2 := hg.HSetOf(1, 2, 3) isSuperset := s1.Superset(s2) // Returns true
func (HSet[T]) SymmetricDifference ¶ added in v1.0.36
func (s HSet[T]) SymmetricDifference(other HSet[T]) HSet[T]
SymmetricDifference returns the symmetric difference between the current set and another set, i.e., elements present in either the current set or the other set but not in both.
Parameters:
- other HSet[T]: The other set to calculate the symmetric difference with.
Returns:
- HSet[T]: A new HSet containing the symmetric difference between the two sets.
Example usage:
s1 := hg.HSetOf(1, 2, 3, 4, 5) s2 := hg.HSetOf(4, 5, 6, 7, 8) symDiff := s1.SymmetricDifference(s2)
The resulting symDiff will be: [1, 2, 3, 6, 7, 8].
func (HSet[T]) ToSlice ¶ added in v1.0.37
func (s HSet[T]) ToSlice() []T
ToSlice returns a new slice with the same elements as the HSet[T].
func (HSet[T]) Union ¶ added in v1.0.36
func (s HSet[T]) Union(other HSet[T]) HSet[T]
Union returns a new set containing the unique elements of the current set and the provided other set.
Parameters:
- other HSet[T]: The other set to create the union with.
Returns:
- HSet[T]: A new HSet containing the unique elements of the current set and the provided other set.
Example usage:
s1 := hg.HSetOf(1, 2, 3) s2 := hg.HSetOf(3, 4, 5) union := s1.Union(s2)
The resulting union set will be: [1, 2, 3, 4, 5].
type HSlice ¶
type HSlice[T any] []T
HSlice is a generic alias for a slice.
func HSliceHFloatFromSlice ¶ added in v1.0.66
func HSliceHFloatFromSlice(fs []float64) HSlice[HFloat]
HSliceHFloatFromSlice converts a float64 slice to an HSlice of HFloat.
func HSliceHIntFromSlice ¶ added in v1.0.66
func HSliceHIntFromSlice(is []int) HSlice[HInt]
HSliceHIntFromSlice converts an int slice to an HSlice of HInt.
func HSliceHStringFromSlice ¶ added in v1.0.66
func HSliceHStringFromSlice(ss []string) HSlice[HString]
HSliceHStringFromSlice converts a string slice to an HSlice of HString.
func HSliceOf ¶
func HSliceOf[T any](slice ...T) HSlice[T]
HSliceOf creates a new generic slice containing the provided elements.
func NewHSlice ¶
NewHSlice creates a new HSlice of the given generic type T with the specified length and capacity. The size variadic parameter can have zero, one, or two integer values. If no values are provided, an empty HSlice with a length and capacity of 0 is returned. If one value is provided, it sets both the length and capacity of the HSlice. If two values are provided, the first value sets the length and the second value sets the capacity.
Parameters:
- size ...int: A variadic parameter specifying the length and/or capacity of the HSlice
Returns:
- HSlice[T]: A new HSlice of the specified generic type T with the given length and capacity
Example usage:
s1 := hg.NewHSlice[int]() // Creates an empty HSlice of type int s2 := hg.NewHSlice[int](5) // Creates an HSlice with length and capacity of 5 s3 := hg.NewHSlice[int](3, 10) // Creates an HSlice with length of 3 and capacity of 10
func (HSlice[T]) AddUnique ¶
func (hsl HSlice[T]) AddUnique(elems ...T) HSlice[T]
AddUnique appends unique elements from the provided arguments to the current slice.
The function iterates over the provided elements and checks if they are already present in the slice. If an element is not already present, it is appended to the slice. The resulting slice is returned, containing the unique elements from both the original slice and the provided elements.
Parameters:
- elems (...T): A variadic list of elements to be appended to the slice.
Returns:
- HSlice[T]: A new slice containing the unique elements from both the original slice and the provided elements.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5} slice = slice.AddUnique(3, 4, 5, 6, 7) fmt.Println(slice)
Output: [1 2 3 4 5 6 7].
func (*HSlice[T]) AddUniqueInPlace ¶ added in v1.0.19
func (hsl *HSlice[T]) AddUniqueInPlace(elems ...T)
AddUniqueInPlace appends unique elements from the provided arguments to the current slice.
The function iterates over the provided elements and checks if they are already present in the slice. If an element is not already present, it is appended to the slice.
Parameters:
- elems (...T): A variadic list of elements to be appended to the slice.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5} slice.AddUniqueInPlace(3, 4, 5, 6, 7) fmt.Println(slice)
Output: [1 2 3 4 5 6 7].
func (HSlice[T]) All ¶
All returns true if all elements in the slice satisfy the provided condition. This function is useful when you want to check if all elements in an HSlice meet a certain criteria.
Parameters:
- fn func(T) bool: A function that returns a boolean indicating whether the element satisfies the condition.
Returns:
- bool: True if all elements in the HSlice satisfy the condition, false otherwise.
Example usage:
slice := hg.HSlice[int]{2, 4, 6, 8, 10} isEven := func(num int) bool { return num%2 == 0 } allEven := slice.All(isEven)
The resulting allEven will be true since all elements in the slice are even.
func (HSlice[T]) Any ¶
Any returns true if any element in the slice satisfies the provided condition. This function is useful when you want to check if at least one element in an HSlice meets a certain criteria.
Parameters:
- fn func(T) bool: A function that returns a boolean indicating whether the element satisfies the condition.
Returns:
- bool: True if at least one element in the HSlice satisfies the condition, false otherwise.
Example usage:
slice := hg.HSlice[int]{1, 3, 5, 7, 9} isEven := func(num int) bool { return num%2 == 0 } anyEven := slice.Any(isEven)
The resulting anyEven will be false since none of the elements in the slice are even.
func (HSlice[T]) Append ¶
func (hsl HSlice[T]) Append(elems ...T) HSlice[T]
Append appends the provided elements to the slice and returns the modified slice.
func (*HSlice[T]) AppendInPlace ¶ added in v1.0.19
func (hsl *HSlice[T]) AppendInPlace(elems ...T)
AppendInPlace appends the provided elements to the slice and modifies the original slice.
func (HSlice[T]) Cap ¶ added in v1.0.1
func (hsl HSlice[T]) Cap() int
Cap returns the capacity of the HSlice.
func (HSlice[T]) Chunks ¶
func (hsl HSlice[T]) Chunks(size int) []HSlice[T]
Chunks splits the HSlice into smaller chunks of the specified size. The function iterates through the HSlice, creating new HSlice[T] chunks of the specified size. If size is less than or equal to 0 or the HSlice is empty, it returns an empty slice of HSlice[T]. If size is greater than or equal to the length of the HSlice, it returns a slice of HSlice[T] containing the original HSlice.
Parameters:
- size int: The size of each chunk.
Returns:
- []HSlice[T]: A slice of HSlice[T] containing the chunks of the original HSlice.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5, 6} chunks := slice.Chunks(2)
The resulting chunks will be: [{1, 2}, {3, 4}, {5, 6}].
func (HSlice[T]) Clear ¶ added in v1.0.66
func (hsl HSlice[T]) Clear() HSlice[T]
Clear removes all elements from the HSlice and sets its length to 0.
func (HSlice[T]) Clip ¶ added in v1.0.36
func (hsl HSlice[T]) Clip() HSlice[T]
Clip removes unused capacity from the slice.
func (HSlice[T]) Contains ¶
func (hsl HSlice[T]) Contains(val T) bool
Contains returns true if the slice contains the provided value.
func (HSlice[T]) ContainsAll ¶ added in v1.0.32
func (hsl HSlice[T]) ContainsAll(other HSlice[T]) bool
ContainsAll checks if the HSlice contains all elements from another HSlice.
func (HSlice[T]) ContainsAny ¶ added in v1.0.32
func (hsl HSlice[T]) ContainsAny(other HSlice[T]) bool
ContainsAny checks if the HSlice contains any element from another HSlice.
func (HSlice[T]) Count ¶
func (hsl HSlice[T]) Count(elem T) int
Count returns the count of the given element in the slice.
func (HSlice[T]) Counter ¶
Counter returns an ordered map with the counts of each unique element in the slice. This function is useful when you want to count the occurrences of each unique element in an HSlice.
Returns:
- *hMapOrd[any, int]: An ordered HMap with keys representing the unique elements in the HSlice and values representing the counts of those elements.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 1, 2, 1} counts := slice.Counter() // The counts ordered HMap will contain: // 1 -> 3 (since 1 appears three times) // 2 -> 2 (since 2 appears two times) // 3 -> 1 (since 3 appears once)
func (HSlice[T]) Cut ¶
func (hsl HSlice[T]) Cut(start, end int) HSlice[T]
Cut removes a range of elements from the HSlice and returns a new HSlice. It creates two slices: one from the beginning of the original slice up to the specified start index (exclusive), and another from the specified end index (inclusive) to the end of the original slice. These two slices are then concatenated to form the resulting HSlice.
Parameters:
- start (int): The start index of the range to be removed.
- end (int): The end index of the range to be removed.
Note:
The function also supports negative indices. Negative indices are counted from the end of the slice. For example, -1 means the last element, -2 means the second-to-last element, and so on.
Returns:
HSlice[T]: A new slice containing elements from the current slice with the specified range removed.
Example:
slice := hg.HSlice[int]{1, 2, 3, 4, 5} newSlice := slice.Cut(1, 3) // newSlice is [1 4 5]
func (HSlice[T]) Delete ¶
func (hsl HSlice[T]) Delete(i int) HSlice[T]
Delete removes the element at the specified index from the slice and returns the modified slice.
func (*HSlice[T]) DeleteInPlace ¶ added in v1.0.19
func (hsl *HSlice[T]) DeleteInPlace(i int)
DeleteInPlace removes the element at the specified index from the slice and modifies the original slice.
func (HSlice[T]) Empty ¶
func (hsl HSlice[T]) Empty() bool
Empty returns true if the slice is empty.
func (HSlice[T]) Enumerate ¶
func (hsl HSlice[T]) Enumerate() HMap[int, T]
Enumerate returns a map with the index of each element as the key. This function is useful when you want to create an HMap where the keys are the indices of the elements in an HSlice, and the values are the corresponding elements.
Returns:
- HMap[int, T]: An HMap with keys representing the indices of the elements in the HSlice and values representing the corresponding elements.
Example usage:
slice := hg.HSlice[int]{10, 20, 30} indexedMap := slice.Enumerate() // The indexedMap HMap will contain: // 0 -> 10 (since 10 is at index 0) // 1 -> 20 (since 20 is at index 1) // 2 -> 30 (since 30 is at index 2)
func (HSlice[T]) Eq ¶
func (hsl HSlice[T]) Eq(other HSlice[T]) bool
Eq returns true if the slice is equal to the provided other slice.
func (HSlice[T]) Fill ¶
func (hsl HSlice[T]) Fill(val T) HSlice[T]
Fill fills the slice with the specified value. This function is useful when you want to create an HSlice with all elements having the same value. This method can be used in place, as it modifies the original slice.
Parameters:
- val T: The value to fill the HSlice with.
Returns:
- HSlice[T]: A reference to the original HSlice filled with the specified value.
Example usage:
slice := hg.HSlice[int]{0, 0, 0} slice.Fill(5)
The modified slice will now contain: 5, 5, 5.
func (HSlice[T]) Filter ¶
func (hsl HSlice[T]) Filter(fn func(T) bool) HSlice[T]
Filter returns a new slice containing elements that satisfy a given condition.
The function takes one parameter of type T (the same type as the elements of the slice) and returns a boolean value. If the returned value is true, the element is added to a new slice, which is then returned as the result.
Parameters:
- fn (func(T) bool): The function to be applied to each element of the slice to determine if it should be included in the result.
Returns:
- HSlice[T]: A new slice containing the elements that satisfy the given condition.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5} even := slice.Filter(func(val int) bool { return val%2 == 0 }) fmt.Println(even)
Output: [2 4].
func (*HSlice[T]) FilterInPlace ¶ added in v1.0.19
func (hsl *HSlice[T]) FilterInPlace(fn func(T) bool)
FilterInPlace removes elements from the current slice that do not satisfy a given condition.
The function takes one parameter of type T (the same type as the elements of the slice) and returns a boolean value. If the returned value is false, the element is removed from the slice.
Parameters:
- fn (func(T) bool): The function to be applied to each element of the slice to determine if it should be kept in the slice.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5} slice.FilterInPlace(func(val int) bool { return val%2 == 0 }) fmt.Println(slice)
Output: [2 4].
func (HSlice[T]) FilterParallel ¶
func (hsl HSlice[T]) FilterParallel(fn func(T) bool) HSlice[T]
FilterParallel returns a new slice containing elements that satisfy a given condition, computed in parallel.
The function iterates over the elements of the slice and applies the provided predicate function to each element. If the length of the slice is less than a predefined threshold (max), it falls back to the sequential Filter function. Otherwise, the slice is divided into two halves and the predicate function is applied to each half in parallel using goroutines. The resulting slices are then combined to form the final output slice.
Note: The order of the elements in the output slice may not be the same as the input slice due to parallel processing.
Parameters:
- fn (func(T) bool): The predicate function to be applied to each element of the slice.
Returns:
- HSlice[T]: A new slice containing the elements that satisfy the given condition.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5} even := slice.FilterParallel(func(val int) bool { return val % 2 == 0 }) fmt.Println(even)
Output: {2 4}.
func (HSlice[T]) FilterZeroValues ¶
func (hsl HSlice[T]) FilterZeroValues() HSlice[T]
FilterZeroValues returns a new slice with all zero values removed.
The function iterates over the elements in the slice and checks if they are zero values using the reflect.DeepEqual function. If an element is not a zero value, it is added to the resulting slice. The new slice, containing only non-zero values, is returned.
Returns:
- HSlice[T]: A new slice containing only non-zero values from the original slice.
Example usage:
slice := hg.HSlice[int]{1, 2, 0, 4, 0} nonZeroSlice := slice.FilterZeroValues() fmt.Println(nonZeroSlice)
Output: [1 2 4].
func (*HSlice[T]) FilterZeroValuesInPlace ¶ added in v1.0.19
func (hsl *HSlice[T]) FilterZeroValuesInPlace()
FilterZeroValuesInPlace removes all zero values from the current slice.
The function iterates over the elements in the slice and checks if they are zero values using the reflect.DeepEqual function. If an element is a zero value, it is removed from the slice.
Example usage:
slice := hg.HSlice[int]{1, 2, 0, 4, 0} slice.FilterZeroValuesInPlace() fmt.Println(slice)
Output: [1 2 4].
func (HSlice[T]) Flatten ¶
func (hsl HSlice[T]) Flatten() HSlice[any]
Flatten flattens the nested slice structure into a single-level HSlice[any].
It recursively traverses the nested slice structure and appends all non-slice elements to a new HSlice[any].
Returns:
- HSlice[any]: A new HSlice[any] containing the flattened elements.
Example usage:
nested := hg.HSlice[any]{1, 2, hg.HSlice[int]{3, 4, 5}, []any{6, 7, []int{8, 9}}} flattened := nested.Flatten() fmt.Println(flattened)
Output: [1 2 3 4 5 6 7 8 9].
func (HSlice[T]) ForEach ¶
func (hsl HSlice[T]) ForEach(fn func(T))
ForEach applies a given function to each element in the slice.
The function takes one parameter of type T (the same type as the elements of the slice). The function is applied to each element in the order they appear in the slice.
Parameters:
- fn (func(T)): The function to be applied to each element of the slice.
Example usage:
slice := hg.HSlice[int]{1, 2, 3} slice.ForEach(func(val int) { fmt.Println(val * 2) }) // Output: // 2 // 4 // 6
func (HSlice[T]) Get ¶
func (hsl HSlice[T]) Get(index int) T
Get returns the element at the given index, handling negative indices as counting from the end of the slice.
func (HSlice[T]) Grow ¶ added in v1.0.66
func (hsl HSlice[T]) Grow(n int) HSlice[T]
Grow increases the slice's capacity, if necessary, to guarantee space for another n elements. After Grow(n), at least n elements can be appended to the slice without another allocation. If n is negative or too large to allocate the memory, Grow panics.
func (HSlice[T]) Index ¶
func (hsl HSlice[T]) Index(val T) int
Index returns the index of the first occurrence of the specified value in the slice, or -1 if not found.
func (HSlice[T]) Insert ¶
func (hsl HSlice[T]) Insert(i int, values ...T) HSlice[T]
Insert inserts values at the specified index in the slice and returns the resulting slice. The original slice remains unchanged.
Parameters:
- i int: The index at which to insert the new values.
- values ...T: A variadic list of values to insert at the specified index.
Returns:
- HSlice[T]: A new HSlice containing the original elements and the inserted values.
Example usage:
slice := hg.HSlice[string]{"a", "b", "c", "d"} newSlice := slice.Insert(2, "e", "f")
The resulting newSlice will be: ["a", "b", "e", "f", "c", "d"].
func (*HSlice[T]) InsertInPlace ¶ added in v1.0.19
func (hsl *HSlice[T]) InsertInPlace(i int, values ...T)
InsertInPlace inserts values at the specified index in the slice and modifies the original slice.
Parameters:
- i int: The index at which to insert the new values.
- values ...T: A variadic list of values to insert at the specified index.
Example usage:
slice := hg.HSlice[string]{"a", "b", "c", "d"} slice.InsertInPlace(2, "e", "f")
The resulting slice will be: ["a", "b", "e", "f", "c", "d"].
func (HSlice[T]) Join ¶
func (hsl HSlice[T]) Join(sep ...T) HString
Join joins the elements in the slice into a single HString, separated by the provided separator (if any).
func (HSlice[T]) LastIndex ¶
func (hsl HSlice[T]) LastIndex() int
LastIndex returns the last index of the slice.
func (HSlice[T]) Map ¶
func (hsl HSlice[T]) Map(fn func(T) T) HSlice[T]
Map returns a new slice by applying a given function to each element in the current slice.
The function takes one parameter of type T (the same type as the elements of the slice) and returns a value of type T. The returned value is added to a new slice, which is then returned as the result.
Parameters:
- fn (func(T) T): The function to be applied to each element of the slice.
Returns:
- HSlice[T]: A new slice containing the results of applying the function to each element of the current slice.
Example usage:
slice := hg.HSlice[int]{1, 2, 3} doubled := slice.Map(func(val int) int { return val * 2 }) fmt.Println(doubled)
Output: [2 4 6].
func (HSlice[T]) MapAnyParallel ¶ added in v1.0.101
MapAnyParallel applies a given function to each element in the slice in parallel and returns a new slice.
The function iterates over the elements of the slice and applies the provided function to each element. If the length of the slice is less than a predefined threshold (max), it falls back to the sequential MapAny function. Otherwise, the slice is divided into two halves and the function is applied to each half in parallel using goroutines. The resulting slices are then combined to form the final output slice.
Note: The order of the elements in the output slice may not be the same as the input slice due to parallel processing.
Parameters:
- fn (func(T) any): The function to be applied to each element of the slice.
Returns:
- HSlice[any]: A new slice with the results of applying the given function to each element of the original slice.
Example usage:
slice := NewHSlice[int](0, 5) slice = slice.Append(1, 2, 3, 4, 5) squared := slice.MapAnyParallel(func(val int) any { return val * val }) fmt.Println(squared) // Output: [1 4 9 16 25]
func (*HSlice[T]) MapInPlace ¶ added in v1.0.19
func (hsl *HSlice[T]) MapInPlace(fn func(T) T)
MapInPlace applies a given function to each element in the current slice, modifying the elements in place.
The function takes one parameter of type T (the same type as the elements of the slice) and returns a value of type T. The returned value replaces the original element in the slice.
Parameters:
- fn (func(T) T): The function to be applied to each element of the slice.
Example usage:
slice := hg.HSlice[int]{1, 2, 3} slice.MapInPlace(func(val int) int { return val * 2 }) fmt.Println(slice)
Output: [2 4 6].
func (HSlice[T]) MapParallel ¶
func (hsl HSlice[T]) MapParallel(fn func(T) T) HSlice[T]
MapParallel applies a given function to each element in the slice in parallel and returns a new slice.
The function iterates over the elements of the slice and applies the provided function to each element. If the length of the slice is less than a predefined threshold (max), it falls back to the sequential Map function. Otherwise, the slice is divided into two halves and the function is applied to each half in parallel using goroutines. The resulting slices are then combined to form the final output slice.
Note: The order of the elements in the output slice may not be the same as the input slice due to parallel processing.
Parameters:
- fn (func(T) T): The function to be applied to each element of the slice.
Returns:
- HSlice[T]: A new slice with the results of applying the given function to each element of the original slice.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5} squared := slice.MapParallel(func(val int) int { return val * val }) fmt.Println(squared)
Output: {1 4 9 16 25}.
func (HSlice[T]) Max ¶
func (hsl HSlice[T]) Max() T
Max returns the maximum element in the slice, assuming elements are comparable.
func (HSlice[T]) Min ¶
func (hsl HSlice[T]) Min() T
Min returns the minimum element in the slice, assuming elements are comparable.
func (HSlice[T]) Ne ¶
func (hsl HSlice[T]) Ne(other HSlice[T]) bool
Ne returns true if the slice is not equal to the provided other slice.
func (HSlice[T]) NotEmpty ¶
func (hsl HSlice[T]) NotEmpty() bool
NotEmpty returns true if the slice is not empty.
func (HSlice[T]) Permutations ¶
func (hsl HSlice[T]) Permutations() []HSlice[T]
Permutations returns all possible permutations of the elements in the slice.
The function uses a recursive approach to generate all the permutations of the elements. If the slice has a length of 0 or 1, it returns the slice itself wrapped in a single-element slice.
Returns:
- []HSlice[T]: A slice of HSlice[T] containing all possible permutations of the elements in the slice.
Example usage:
slice := hg.HSlice[int]{1, 2, 3} perms := slice.Permutations() for _, perm := range perms { fmt.Println(perm) } // Output: // [1 2 3] // [1 3 2] // [2 1 3] // [2 3 1] // [3 1 2] // [3 2 1]
func (HSlice[T]) Pop ¶
func (hsl HSlice[T]) Pop() (T, HSlice[T])
Pop returns the last element of the slice and a new slice without the last element.
func (HSlice[T]) Print ¶ added in v1.0.72
func (hsl HSlice[T]) Print() HSlice[T]
Print prints the elements of the HSlice to the standard output (console) and returns the HSlice unchanged.
func (HSlice[T]) Random ¶
func (hsl HSlice[T]) Random() T
Random returns a random element from the slice.
The function uses the crypto/rand package to generate a random index within the bounds of the slice. If the slice is empty, the zero value of type T is returned.
Returns:
- T: A random element from the slice.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5} randomElement := slice.Random() fmt.Println(randomElement)
Output: <any random element from the slice>.
func (HSlice[T]) RandomSample ¶
func (hsl HSlice[T]) RandomSample(sequence int) HSlice[T]
RandomSample returns a new slice containing a random sample of elements from the original slice. The sampling is done without replacement, meaning that each element can only appear once in the result.
Parameters:
- sequence int: The number of elements to include in the random sample.
Returns:
- HSlice[T]: A new HSlice containing the random sample of elements.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5, 6, 7, 8, 9} sample := slice.RandomSample(3)
The resulting sample will contain 3 unique elements randomly selected from the original slice.
func (HSlice[T]) Range ¶
Range returns a new slice containing elements from the current slice between the specified start and end indices. The function checks if the start and end indices are within the bounds of the original slice. If the end index is negative, it represents the position from the end of the slice. If the start index is negative, it represents the position from the end of the slice counted from the start index. If the start index is greater than or equal to the end index, an empty slice is returned. If the end index is greater than the length of the slice, it is set to the length of the slice.
Parameters:
- start (int): The start index of the range.
- end (int, optional): The end index of the range. If not provided, the end index will be the length of the slice.
Returns:
- HSlice[T]: A new slice containing elements from the current slice between the start and end indices.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5} subSlice := slice.Range(1, 4) fmt.Println(subSlice)
Output: [2 3 4].
func (HSlice[T]) Reduce ¶
func (hsl HSlice[T]) Reduce(fn func(acc, val T) T, initial T) T
Reduce reduces the slice to a single value using a given function and an initial value.
The function takes two parameters of type T (the same type as the elements of the slice): an accumulator and a value from the slice. The accumulator is initialized with the provided initial value, and the function is called for each element in the slice. The returned value from the function becomes the new accumulator value for the next iteration. After processing all the elements in the slice, the final accumulator value is returned as the result.
Parameters:
- fn (func(acc, val T) T): The function to be applied to each element of the slice and the accumulator. This function should return a new value for the accumulator.
- initial (T): The initial value for the accumulator.
Returns:
- T: The final accumulator value after processing all the elements in the slice.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5} sum := slice.Reduce(func(acc, val int) int { return acc + val }, 0) fmt.Println(sum)
Output: 15.
func (HSlice[T]) ReduceParallel ¶
func (hsl HSlice[T]) ReduceParallel(fn func(T, T) T, initial T) T
ReduceParallel reduces the slice to a single value using a given function and an initial value, computed in parallel.
The function iterates over the elements of the slice and applies the provided reducer function to each element in a pairwise manner. If the length of the slice is less than a predefined threshold (max), it falls back to the sequential Reduce function. Otherwise, the slice is divided into two halves and the reducer function is applied to each half in parallel using goroutines. The resulting values are combined using the reducer function to produce the final output value.
Note: Due to parallel processing, the order in which the reducer function is applied to the elements may not be the same as the input slice.
Parameters:
- fn (func(T, T) T): The reducer function to be applied to each element of the slice.
- initial (T): The initial value to be used as the starting point for the reduction.
Returns:
- T: A single value obtained by applying the reducer function to the elements of the slice.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5} sum := slice.ReduceParallel(func(acc, val int) int { return acc + val }, 0) fmt.Println(sum)
Output: 15.
func (HSlice[T]) Replace ¶ added in v1.0.31
func (hsl HSlice[T]) Replace(i, j int, values ...T) HSlice[T]
Replace replaces the elements of hsl[i:j] with the given values, and returns a new slice with the modifications. The original slice remains unchanged. Replace panics if hsl[i:j] is not a valid slice of hsl.
Parameters:
- i int: The starting index of the slice to be replaced.
- j int: The ending index of the slice to be replaced.
- values ...T: A variadic list of values to replace the existing slice.
Returns:
- HSlice[T]: A new HSlice containing the original elements with the specified elements replaced.
Example usage:
slice := hg.HSlice[string]{"a", "b", "c", "d"} newSlice := slice.Replace(1, 3, "e", "f")
The original slice remains ["a", "b", "c", "d"], and the newSlice will be: ["a", "e", "f", "d"].
func (*HSlice[T]) ReplaceInPlace ¶ added in v1.0.31
func (hsl *HSlice[T]) ReplaceInPlace(i, j int, values ...T)
ReplaceInPlace replaces the elements of hsl[i:j] with the given values, and modifies the original slice in place. ReplaceInPlace panics if hsl[i:j] is not a valid slice of hsl.
Parameters:
- i int: The starting index of the slice to be replaced.
- j int: The ending index of the slice to be replaced.
- values ...T: A variadic list of values to replace the existing slice.
Example usage:
slice := hg.HSlice[string]{"a", "b", "c", "d"} slice.ReplaceInPlace(1, 3, "e", "f")
After the ReplaceInPlace operation, the resulting slice will be: ["a", "e", "f", "d"].
func (HSlice[T]) Reverse ¶
func (hsl HSlice[T]) Reverse() HSlice[T]
Reverse reverses the order of the elements in the slice. This method can be used in place, as it modifies the original slice.
Returns:
- HSlice[T]: The modified slice with the elements reversed.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5} reversed := slice.Reverse() fmt.Println(reversed)
Output: [5 4 3 2 1].
func (HSlice[T]) Set ¶
func (hsl HSlice[T]) Set(i int, val T) HSlice[T]
Set sets the value at the specified index in the slice and returns the modified slice. This method can be used in place, as it modifies the original slice.
Parameters:
- i (int): The index at which to set the new value.
- val (T): The new value to be set at the specified index.
Returns:
- HSlice[T]: The modified slice with the new value set at the specified index.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5} slice.Set(2, 99) fmt.Println(slice)
Output: [1 2 99 4 5].
func (HSlice[T]) Shuffle ¶
func (hsl HSlice[T]) Shuffle() HSlice[T]
Shuffle shuffles the elements in the slice randomly. This method can be used in place, as it modifies the original slice.
The function uses the crypto/rand package to generate random indices.
Returns:
- HSlice[T]: The modified slice with the elements shuffled randomly.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5} shuffled := slice.Shuffle() fmt.Println(shuffled)
Output: A randomly shuffled version of the original slice, e.g., [4 1 5 2 3].
func (HSlice[T]) SortBy ¶
SortBy sorts the elements in the slice using the provided comparison function. This method can be used in place, as it modifies the original slice.
The function takes a custom comparison function as an argument and sorts the elements of the slice using the provided logic. The comparison function should return true if the element at index i should come before the element at index j, and false otherwise.
Parameters:
- f func(i, j int) bool: A comparison function that takes two indices i and j.
Returns:
- HSlice[T]: The sorted HSlice.
Example usage:
hsl := NewHSlice[int](1, 5, 3, 2, 4) hsl.SortBy(func(i, j int) bool { return hsl[i] < hsl[j] }) // sorts in ascending order.
func (HSlice[T]) String ¶
func (hsl HSlice[T]) String() string
String returns a string representation of the slice.
func (HSlice[T]) Swap ¶
func (hsl HSlice[T]) Swap(i, j int) HSlice[T]
Swap swaps the elements at the specified indices in the slice and returns the modified slice. This method can be used in place, as it modifies the original slice.
Parameters:
- i (int): The index of the first element to be swapped.
- j (int): The index of the second element to be swapped.
Returns:
- HSlice[T]: The modified slice with the elements at the specified indices swapped.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 4, 5} slice.Swap(1, 3) fmt.Println(slice)
Output: [1 4 3 2 5].
func (HSlice[T]) ToHMapHashed ¶
func (hsl HSlice[T]) ToHMapHashed() HMap[HString, T]
ToHMapHashed returns a map with the hashed version of each element as the key.
func (HSlice[T]) ToSlice ¶
func (hsl HSlice[T]) ToSlice() []T
ToSlice returns a new slice with the same elements as the HSlice[T].
func (HSlice[T]) ToStringSlice ¶
func (hsl HSlice[T]) ToStringSlice() []string
ToStringSlice converts the slice into a slice of strings.
func (HSlice[T]) Unique ¶
func (hsl HSlice[T]) Unique() HSlice[T]
Unique returns a new slice containing unique elements from the current slice.
The order of elements in the returned slice is the same as the order in the original slice.
Returns:
- HSlice[T]: A new HSlice containing unique elements from the current slice.
Example usage:
slice := hg.HSlice[int]{1, 2, 3, 2, 4, 5, 3} unique := slice.Unique()
The resulting unique slice will be: [1, 2, 3, 4, 5].
func (HSlice[T]) Zip ¶
func (hsl HSlice[T]) Zip(hslices ...HSlice[T]) []HSlice[T]
Zip zips the elements of the given slices with the current slice into a new slice of HSlice[T] elements.
The function combines the elements of the current slice with the elements of the given slices by index. The length of the resulting slice of HSlice[T] elements is determined by the shortest input slice.
Params:
- slices: The slices to be zipped with the current slice.
Returns:
- []HSlice[T]: A new slice of HSlice[T] elements containing the zipped elements of the input slices.
Example usage:
slice1 := hg.HSlice[int]{1, 2, 3} slice2 := hg.HSlice[int]{4, 5, 6} slice3 := hg.HSlice[int]{7, 8, 9} zipped := slice1.Zip(slice2, slice3) for _, group := range zipped { fmt.Println(group) } // Output: // [1 4 7] // [2 5 8] // [3 6 9]
type HString ¶
type HString string
HString is an alias for the string type.
func NewHString ¶
func NewHString(strs ...string) HString
NewHString creates a new HString from the provided string (optional).
func (HString) Add ¶
func (hs HString) Add(hstr HString) HString
Add appends the specified HString to the current HString.
func (HString) AddPrefix ¶
func (hs HString) AddPrefix(hstr HString) HString
AddPrefix prepends the specified HString to the current HString.
func (HString) Center ¶ added in v1.0.62
func (hs HString) Center(length int, pad HString) HString
Center justifies the HString by adding padding on both sides, up to the specified length. If the length of the HString is already greater than or equal to the specified length, or the pad is empty, the original HString is returned.
The padding HString is repeated as necessary to evenly distribute the remaining length on both sides. The padding is added to the left and right of the HString.
Parameters:
- length: The desired length of the resulting justified HString.
- pad: The HString used as padding.
Example usage:
hs := hg.HString("Hello") result := hs.Center(10, "...") // result: "..Hello..."
func (HString) Chunks ¶
func (hs HString) Chunks(size int) HOption[HSlice[HString]]
Chunks splits the HString into chunks of the specified size.
This function iterates through the HString, creating new HString chunks of the specified size. If size is less than or equal to 0 or the HString is empty, it returns an empty HSlice[HString]. If size is greater than or equal to the length of the HString, it returns an HSlice[HString] containing the original HString.
Parameters:
- size (int): The size of the chunks to split the HString into.
Returns:
- HSlice[HString]: A slice of HString chunks of the specified size.
Example usage:
text := hg.HString("Hello, World!") chunks := text.Chunks(4).Some()
chunks contains {"Hell", "o, W", "orld", "!"}.
func (HString) Compare ¶
func (hs HString) Compare(hstr HString) HInt
Compare compares two HStrings and returns an HInt indicating their relative order. The result will be 0 if hs==hstr, -1 if hs < hstr, and +1 if hs > hstr.
func (HString) Contains ¶
func (hs HString) Contains(substr HString) bool
Contains checks if the HString contains the specified substring.
func (HString) ContainsAll ¶ added in v1.0.4
func (hs HString) ContainsAll(substrs ...HString) bool
ContainsAll checks if the given HString contains all the specified substrings.
func (HString) ContainsAny ¶
func (hs HString) ContainsAny(substrs ...HString) bool
ContainsAny checks if the HString contains any of the specified substrings.
func (HString) ContainsAnyChars ¶ added in v1.0.4
func (hs HString) ContainsAnyChars(chars HString) bool
ContainsAnyChars checks if the HString contains any characters from the specified HString.
func (HString) ContainsRegexp ¶ added in v1.0.21
ContainsRegexp checks if the HString contains a match for the specified regular expression pattern.
func (HString) ContainsRegexpAll ¶ added in v1.0.66
ContainsRegexpAll checks if the HString contains a match for all of the specified regular expression patterns.
func (HString) ContainsRegexpAny ¶ added in v1.0.66
ContainsRegexpAny checks if the HString contains a match for any of the specified regular expression patterns.
func (HString) ContainsRune ¶
ContainsRune checks if the HString contains the specified rune.
func (HString) Count ¶
func (hs HString) Count(substr HString) int
Count returns the number of non-overlapping instances of the substring in the HString.
func (HString) Cut ¶
func (hs HString) Cut(start, end HString, rmtags ...bool) (HString, HString)
Cut returns two HString values. The first HString contains the remainder of the original HString after the cut. The second HString contains the text between the first occurrences of the 'start' and 'end' strings, with tags removed if specified.
The function searches for the 'start' and 'end' strings within the HString. If both are found, it returns the first HString containing the remainder of the original HString after the cut, followed by the second HString containing the text between the first occurrences of 'start' and 'end' with tags removed if specified.
If either 'start' or 'end' is empty or not found in the HString, it returns the original HString as the second HString, and an empty HString as the first.
Parameters:
- start (HString): The HString marking the beginning of the text to be cut.
- end (HString): The HString marking the end of the text to be cut.
- rmtags (bool, optional): An optional boolean parameter indicating whether to remove 'start' and 'end' tags from the cut text. Defaults to false.
Returns:
HString: The first HString containing the remainder of the original HString after the cut, with tags removed if specified, or an empty HString if 'start' or 'end' is empty or not found.
HString: The second HString containing the text between the first occurrences of 'start' and 'end', or the original HString if 'start' or 'end' is empty or not found.
Example usage:
hs := hg.HString("Hello, [world]! How are you?") remainder, cut := hs.Cut("[", "]") // remainder: "Hello, ! How are you?" // cut: "world"
func (HString) Dec ¶ added in v1.0.65
func (hs HString) Dec() dec
Dec returns a dec struct wrapping the given HString.
func (HString) Enc ¶ added in v1.0.65
func (hs HString) Enc() enc
Enc returns an enc struct wrapping the given HString.
func (HString) EndsWith ¶ added in v1.0.60
func (hs HString) EndsWith(suffixes ...HString) bool
EndsWith checks if the HString ends with any of the provided suffixes. The method accepts a variable number of arguments, allowing for checking against multiple suffixes at once. It iterates over the provided suffixes and uses the HasSuffix function from the strings package to check if the HString ends with each suffix. The function returns true if the HString ends with any of the suffixes, and false otherwise.
Usage:
hs := hg.HString("example.com") if hs.EndsWith(".com", ".net") { // do something }
func (HString) EqFold ¶ added in v1.0.19
func (hs HString) EqFold(hstr HString) bool
EqFold compares two HString strings case-insensitively.
func (HString) Fields ¶
func (hs HString) Fields() HSlice[HString]
Fields splits the HString into a slice of substrings, removing any whitespace.
func (HString) FindAllRegexp ¶ added in v1.0.74
FindAllRegexp searches the HString for all occurrences of the regular expression pattern and returns an HOption[HSlice[HString]] containing a slice of matched substrings. If no matches are found, the HOption[HSlice[HString]] will be None.
func (HString) FindAllRegexpN ¶ added in v1.0.74
FindAllRegexpN searches the HString for up to n occurrences of the regular expression pattern and returns an HOption[HSlice[HString]] containing a slice of matched substrings. If no matches are found, the HOption[HSlice[HString]] will be None. If n is negative, all occurrences will be returned.
func (HString) FindAllSubmatchRegexp ¶ added in v1.0.74
FindAllSubmatchRegexp searches the HString for all occurrences of the regular expression pattern and returns an HOption[HSlice[HSlice[HString]]] containing the matched substrings and submatches. The HOption[HSlice[HSlice[HString]]] will contain an HSlice[HString] for each match, where each HSlice[HString] will contain the full match at index 0, followed by any captured submatches. If no match is found, the HOption[HSlice[HSlice[HString]]] will be None. This method is equivalent to calling SubmatchAllRegexpN with n = -1, which means it finds all occurrences.
func (HString) FindAllSubmatchRegexpN ¶ added in v1.0.74
func (hs HString) FindAllSubmatchRegexpN(pattern *regexp.Regexp, n HInt) HOption[HSlice[HSlice[HString]]]
FindAllSubmatchRegexpN searches the HString for occurrences of the regular expression pattern and returns an HOption[HSlice[HSlice[HString]]] containing the matched substrings and submatches. The HOption[HSlice[HSlice[HString]]] will contain an HSlice[HString] for each match, where each HSlice[HString] will contain the full match at index 0, followed by any captured submatches. If no match is found, the HOption[HSlice[HSlice[HString]]] will be None. The 'n' parameter specifies the maximum number of matches to find. If n is negative, it finds all occurrences.
func (HString) FindRegexp ¶ added in v1.0.74
FindRegexp searches the HString for the first occurrence of the regulare xpression pattern and returns an HOption[HString] containing the matched substring. If no match is found, it returns None.
func (HString) FindSubmatchRegexp ¶ added in v1.0.74
FindSubmatchRegexp searches the HString for the first occurrence of the regular expression pattern and returns an HOption[HSlice[HString]] containing the matched substrings and submatches. The HOption will contain an HSlice[HString] with the full match at index 0, followed by any captured submatches. If no match is found, it returns None.
func (HString) Format ¶ added in v1.0.61
func (hs HString) Format(format HString) HString
Format applies a specified format to the HString object.
func (HString) Gt ¶
func (hs HString) Gt(hstr HString) bool
Gt checks if the HString is greater than the specified HString.
func (HString) HFloat ¶
func (hs HString) HFloat() HResult[HFloat]
HFloat tries to parse the HString as a float64 and returns an HFloat.
func (HString) HInt ¶
func (hs HString) HInt() HResult[HInt]
HInt tries to parse the HString as an int and returns an HInt.
func (HString) Hash ¶
func (hs HString) Hash() shash
Hash returns a shash struct wrapping the given HString.
func (HString) Index ¶
func (hs HString) Index(substr HString) int
Index returns the index of the first instance of the specified substring in the HString, or -1 if substr is not present in hs.
func (HString) IndexRegexp ¶ added in v1.0.74
IndexRegexp searches for the first occurrence of the regular expression pattern in the HString. If a match is found, it returns an Option containing an HSlice with the start and end indices of the match. If no match is found, it returns None.
func (HString) IndexRune ¶
IndexRune returns the index of the first instance of the specified rune in the HString.
func (HString) IsASCII ¶ added in v1.0.15
func (hs HString) IsASCII() bool
IsASCII checks if all characters in the HString are ASCII bytes.
func (HString) IsDigit ¶
func (hs HString) IsDigit() bool
IsDigit checks if all characters in the HString are digits.
func (HString) LastIndex ¶ added in v1.0.73
func (hs HString) LastIndex(substr HString) int
LastIndex returns the index of the last instance of the specified substring in the HString, or -1 if substr is not present in hs.
func (HString) LeftJustify ¶ added in v1.0.62
func (hs HString) LeftJustify(length int, pad HString) HString
LeftJustify justifies the HString to the left by adding padding to the right, up to the specified length. If the length of the HString is already greater than or equal to the specified length, or the pad is empty, the original HString is returned.
The padding HString is repeated as necessary to fill the remaining length. The padding is added to the right of the HString.
Parameters:
- length: The desired length of the resulting justified HString.
- pad: The HString used as padding.
Example usage:
hs := hg.HString("Hello") result := hs.LeftJustify(10, "...") // result: "Hello....."
func (HString) LenRunes ¶
func (hs HString) LenRunes() int
LenRunes returns the number of runes in the HString.
func (HString) Lt ¶
func (hs HString) Lt(hstr HString) bool
Lt checks if the HString is less than the specified HString.
func (HString) Map ¶
Map applies the provided function to all runes in the HString and returns the resulting HString.
func (HString) Max ¶ added in v1.0.103
func (hs HString) Max(b ...HString) HString
Max returns the maximum of HStrings.
func (HString) Min ¶ added in v1.0.103
func (hs HString) Min(b ...HString) HString
Min returns the minimum of HStrings.
func (HString) Ne ¶
func (hs HString) Ne(hstr HString) bool
Ne checks if two HStrings are not equal.
func (HString) NormalizeNFC ¶
func (hs HString) NormalizeNFC() HString
NormalizeNFC returns a new HString with its Unicode characters normalized using the NFC form.
func (HString) NotEmpty ¶
func (hs HString) NotEmpty() bool
NotEmpty checks if the HString is not empty.
func (HString) Print ¶ added in v1.0.72
func (hs HString) Print() HString
Print prints the content of the HString to the standard output (console) and returns the HString unchanged.
func (HString) Random ¶
func (HString) Random(count int) HString
Random generates a random HString with the specified length.
This function uses a predefined set of characters (ASCII_LETTERS and DIGITS) and iterates 'count' times, appending a random character from the set to the result HString.
Parameters:
- count (int): The length of the random HString to be generated.
Returns:
- HString: A random HString with the specified length.
Example usage:
randomString := hg.HString.Random(10)
randomString contains a random HString with 10 characters.
func (HString) Repeat ¶
func (hs HString) Repeat(count int) HString
Repeat returns a new HString consisting of the specified count of the original HString.
func (HString) Replace ¶
func (hs HString) Replace(oldS, newS HString, n int) HString
Replace replaces the 'oldS' HString with the 'newS' HString for the specified number of occurrences.
func (HString) ReplaceAll ¶
func (hs HString) ReplaceAll(oldS, newS HString) HString
ReplaceAll replaces all occurrences of the 'oldS' HString with the 'newS' HString.
func (HString) ReplaceNth ¶ added in v1.0.5
func (hs HString) ReplaceNth(oldS, newS HString, n int) HString
ReplaceNth returns a new HString instance with the nth occurrence of oldS replaced with newS. If there aren't enough occurrences of oldS, the original HString is returned. If n is less than -1, the original HString is also returned. If n is -1, the last occurrence of oldS is replaced with newS.
Returns:
- A new HString instance with the nth occurrence of oldS replaced with newS.
Example usage:
hs := hg.HString("The quick brown dog jumped over the lazy dog.") result := hs.ReplaceNth("dog", "fox", 2) fmt.Println(result)
Output: "The quick brown dog jumped over the lazy fox.".
func (HString) ReplaceRegexp ¶ added in v1.0.73
ReplaceRegexp replaces all occurrences of the regular expression matches in the HString with the provided newS (as a HString) and returns the resulting HString after the replacement.
func (HString) RightJustify ¶ added in v1.0.62
func (hs HString) RightJustify(length int, pad HString) HString
RightJustify justifies the HString to the right by adding padding to the left, up to the specified length. If the length of the HString is already greater than or equal to the specified length, or the pad is empty, the original HString is returned.
The padding HString is repeated as necessary to fill the remaining length. The padding is added to the left of the HString.
Parameters:
- length: The desired length of the resulting justified HString.
- pad: The HString used as padding.
Example usage:
hs := hg.HString("Hello") result := hs.RightJustify(10, "...") // result: ".....Hello"
func (HString) Runes ¶
func (hs HString) Runes() []rune
Runes returns the HString as a slice of runes.
func (HString) Similarity ¶
func (hs HString) Similarity(hstr HString) HFloat
Similarity calculates the similarity between two HStrings using the Levenshtein distance algorithm and returns the similarity percentage as an HFloat.
The function compares two HStrings using the Levenshtein distance, which measures the difference between two sequences by counting the number of single-character edits required to change one sequence into the other. The similarity is then calculated by normalizing the distance by the maximum length of the two input HStrings.
Parameters:
- hstr (HString): The HString to compare with hs.
Returns:
- HFloat: The similarity percentage between the two HStrings as a value between 0 and 100.
Example usage:
hs1 := hg.HString("kitten") hs2 := hg.HString("sitting") similarity := hs1.Similarity(hs2) // 57.14285714285714
func (HString) Split ¶
func (hs HString) Split(sep ...HString) HSlice[HString]
Split splits the HString by the specified separator.
func (HString) SplitN ¶ added in v1.0.74
func (hs HString) SplitN(sep HString, n HInt) HSlice[HString]
SplitN splits the HString into substrings using the provided separator and returns an HSlice[HString] of the results. The n parameter controls the number of substrings to return: - If n is negative, there is no limit on the number of substrings returned. - If n is zero, an empty HSlice[HString] is returned. - If n is positive, at most n substrings are returned.
func (HString) SplitRegexp ¶ added in v1.0.74
SplitRegexp splits the HString into substrings using the provided regular expression pattern and returns an HSlice[HString] of the results. The regular expression pattern is provided as a regexp.Regexp parameter.
func (HString) SplitRegexpN ¶ added in v1.0.74
SplitRegexpN splits the HString into substrings using the provided regular expression pattern and returns an HSlice[HString] of the results. The regular expression pattern is provided as a regexp.Regexp parameter. The n parameter controls the number of substrings to return: - If n is negative, there is no limit on the number of substrings returned. - If n is zero, an empty HSlice[HString] is returned. - If n is positive, at most n substrings are returned.
func (HString) StartsWith ¶ added in v1.0.60
func (hs HString) StartsWith(prefixes ...HString) bool
StartsWith checks if the HString starts with any of the provided prefixes. The method accepts a variable number of arguments, allowing for checking against multiple prefixes at once. It iterates over the provided prefixes and uses the HasPrefix function from the strings package to check if the HString starts with each prefix. The function returns true if the HString starts with any of the prefixes, and false otherwise.
Usage:
hs := hg.HString("http://example.com") if hs.StartsWith("http://", "https://") { // do something }
func (HString) ToLower ¶
func (hs HString) ToLower() HString
ToLower returns the HString in lowercase.
func (HString) ToTitle ¶
func (hs HString) ToTitle() HString
ToTitle converts the HString to title case.
func (HString) ToUpper ¶
func (hs HString) ToUpper() HString
ToUpper returns the HString in uppercase.
func (HString) Trim ¶
func (hs HString) Trim(cutset HString) HString
Trim trims characters in the cutset from the beginning and end of the HString.
func (HString) TrimLeft ¶
func (hs HString) TrimLeft(cutset HString) HString
TrimLeft trims characters in the cutset from the beginning of the HString.
func (HString) TrimPrefix ¶
func (hs HString) TrimPrefix(cutset HString) HString
TrimPrefix trims the specified prefix from the HString.
func (HString) TrimRight ¶
func (hs HString) TrimRight(cutset HString) HString
TrimRight trims characters in the cutset from the end of the HString.
func (HString) TrimSpace ¶
func (hs HString) TrimSpace() HString
TrimSpace trims whitespace from the beginning and end of the HString.
func (HString) TrimSuffix ¶
func (hs HString) TrimSuffix(cutset HString) HString
TrimSuffix trims the specified suffix from the HString.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
pkg
|
|
deref
Package deref provides a utility function to dereference a pointer.
|
Package deref provides a utility function to dereference a pointer. |
iter
Package iter provides a utility function for creating a range of integers.
|
Package iter provides a utility function for creating a range of integers. |
minmax
Package minmax provides functions for finding the maximum and minimum values.
|
Package minmax provides functions for finding the maximum and minimum values. |
ref
Package ref provides a utility function for creating a pointer to a value.
|
Package ref provides a utility function for creating a pointer to a value. |