hg

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2023 License: MIT Imports: 37 Imported by: 2

README

🤪 Humango: Go Crazy, Go Human, Go Nuts!

Introducing Humango, the wackiest Go package on the planet, created to make your coding experience an absolute riot! With Humango, you can forget about dull and monotonous code; we're all about turning the mundane into the insanely hilarious. It's not just a bicycle; it's almost a motorcycle 🤣!

🎉 What's in the box?

  1. 📖 Readable syntax: Boring code is so yesterday! Humango turns your code into a party by blending seamlessly with Go and making it super clean and laughably maintainable.
  2. 🔀 Encoding and decoding: Juggling data formats? No problemo! Humango's got your back with Base64, URL, Gzip, and Rot13 support. Encode and decode like a pro!
  3. 🔒 Hashing extravaganza: Safety first, right? Hash your data with MD5, SHA1, SHA256, or SHA512, and enjoy peace of mind while Humango watches over your bytes.
  4. 📁 File and directory shenanigans: Create, read, write, and dance through files and directories with Humango's fun-tastic functions. Trust us, managing files has never been this entertaining.
  5. 🌈 Data type compatibility: Strings, integers, floats, bytes, slices, maps, you name it! Humango is the life of the party, mingling with all your favorite data types.
  6. 🔧 Customize and extend: Need something extra? Humango is your best buddy, ready to be extended or modified to suit any project.
  7. 📚 Docs & examples: We're not just about fun and games, we've got detailed documentation and examples that'll have you smiling from ear to ear as you learn the Humango way.

Take your Go projects to a whole new level of excitement with Humango! It's time to stop coding like it's a chore and start coding like it's a celebration! 🥳

Documentation

Index

Constants

View Source
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

func HMapOrdFromHMap

func HMapOrdFromHMap[K comparable, V any](hmap HMap[K, V]) *hMapOrd[K, V]

HMapOrdFromHMap converts a standard HMap to an ordered HMap.

func HMapOrdFromMap

func HMapOrdFromMap[K comparable, V any](m map[K]V) *hMapOrd[K, V]

HMapOrdFromHMap converts a standard HMap 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).

Types

type HBytes

type HBytes []byte

func NewHBytes

func NewHBytes(bs ...[]byte) HBytes

NewHBytes creates a new HBytes value. Takes a variadic byte slice as input and returns an HBytes instance.

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) Bytes

func (hbs HBytes) Bytes() []byte

Bytes returns the HBytes as a byte slice.

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) ContainsAny

func (hbs HBytes) ContainsAny(chars HString) bool

ContainsAny checks if the given HBytes contains any characters from the input HString.

func (HBytes) ContainsRune

func (hbs HBytes) ContainsRune(r rune) bool

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) Empty

func (hbs HBytes) Empty() bool

Empty checks if the HBytes is empty.

func (HBytes) Eq

func (hbs HBytes) Eq(bs HBytes) bool

Eq checks if the HBytes is equal to another HBytes.

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) Len

func (hbs HBytes) Len() int

Len returns the length of the HBytes.

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

func (hbs HBytes) Map(fn func(rune) rune) HBytes

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) Reader

func (hbs HBytes) Reader() *bytes.Reader

Reader returns a *bytes.Reader initialized with the content of HBytes.

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) 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) String

func (hbs HBytes) String() string

String returns the HBytes as a string.

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
}

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) *HDir

CopyDir copies the contents of the current directory to the destination directory.

func (HDir) Error

func (hd HDir) Error() error

Error returns the latest error that occurred during an operation.

func (HDir) Exist

func (hd HDir) Exist() bool

Exist checks if the current directory exists.

func (*HDir) Glob

func (hd *HDir) Glob() []*HFile

Glob matches files in the current directory using the path pattern and returns a slice of HFile instances.

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) HString

Join joins the current directory path with the given path elements, returning the joined path.

func (*HDir) Mkdir

func (hd *HDir) Mkdir(mode ...os.FileMode) *HDir

Mkdir creates a new directory with the specified mode (optional).

func (*HDir) MkdirAll

func (hd *HDir) MkdirAll(mode ...os.FileMode) *HDir

MkdirAll creates all directories along the given path, with the specified mode (optional).

func (*HDir) Path

func (hd *HDir) Path() HString

Path returns the absolute path of the current directory.

func (*HDir) ReadDir

func (hd *HDir) ReadDir() []*HFile

ReadDir reads the content of the current directory and returns a slice of HFile instances.

func (*HDir) Rename

func (hd *HDir) Rename(newpath HString) *HDir

Rename renames the current directory to the new path.

func (*HDir) SetPath

func (hd *HDir) SetPath(path HString) *HDir

SetPath sets the path of the current directory.

type HFile

type HFile struct {
	// contains filtered or unexported fields
}

func NewHFile

func NewHFile(name HString) *HFile

NewHFile returns a new HFile instance with the given name.

func (*HFile) Append

func (hf *HFile) Append(content HString, mode ...os.FileMode) *HFile

Append appends the given content to the file, with the specified mode (optional).

func (*HFile) Chmod

func (hf *HFile) Chmod(mode os.FileMode) *HFile

Chmod changes the mode of the file.

func (*HFile) Chown

func (hf *HFile) Chown(uid, gid int) *HFile

Chown changes the owner of the file.

func (*HFile) Close

func (hf *HFile) Close()

Close closes the HFile's underlying file, if it is not already closed. If an error occurs during closing, it is stored in hf.err and can be checked by the Error() method.

func (*HFile) Copy

func (hf *HFile) Copy(dest HString, mode ...os.FileMode) *HFile

Copy copies the file to the specified destination, with the specified mode (optional).

func (HFile) Error

func (hf HFile) Error() error

Error returns the latest error that occurred during an operation.

func (HFile) Exist

func (hf HFile) Exist() bool

Exist checks if the file exists.

func (HFile) Ext

func (hf HFile) Ext() HString

Ext returns the file extension.

func (HFile) File

func (hf HFile) File() *os.File

File returns the underlying *os.File instance.

func (HFile) HDir

func (hf HFile) HDir() *HDir

HDir returns the directory the file is in as an HDir instance.

func (HFile) IsDir

func (hf HFile) IsDir() bool

IsDir checks if the file is a directory.

func (*HFile) Iterator

func (hf *HFile) Iterator() *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.

func (*HFile) MimeType

func (hf *HFile) MimeType() HString

MimeType returns the MIME type of the file as an HString.

func (HFile) ModTime

func (hf HFile) ModTime() time.Time

ModTime returns the modification time of the file.

func (HFile) Mode

func (hf HFile) Mode() fs.FileMode

Mode returns the file mode.

func (HFile) Name

func (hf HFile) Name() string

Name returns the name of the file.

func (HFile) Path

func (hf HFile) Path() HString

Path returns the absolute path of the file.

func (*HFile) Read

func (hf *HFile) Read() HString

Read reads the content of the file and returns it as an HString.

func (HFile) ReadLines

func (hf HFile) ReadLines() HSlice[HString]

ReadLines reads the file and returns its content as a slice of lines.

func (*HFile) Remove

func (hf *HFile) Remove()

Remove removes the file.

func (*HFile) Rename

func (hf *HFile) Rename(newpath HString) *HFile

Rename renames the file to the specified new path.

func (*HFile) SeekToLine

func (hf *HFile) SeekToLine(position int64, linesRead int) (int64, HString)

SeekToLine seeks to the specified position in the file and reads the specified number of lines from that position.

func (HFile) Size

func (hf HFile) Size() int64

Size returns the size 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) TempFile

func (hf *HFile) TempFile(args ...HString) *HFile

TempFile creates a new temporary file in the given directory (if specified) and with the given pattern (if specified). If dir is the empty string, TempFile uses the default directory for temporary files, as returned by TempDir. If pattern includes a "*", the random string replaces the last "*".

func (*HFile) Write

func (hf *HFile) Write(content HString, mode ...os.FileMode) *HFile

Write writes the given content to the file, with the specified mode (optional).

type HFloat

type HFloat float64

func NewHFloat

func NewHFloat(floats ...float64) HFloat

NewHFloat creates a new HFloat with the provided float64 value.

func (HFloat) Abs

func (hf HFloat) Abs() HFloat

Abs returns the absolute value of the HFloat.

func (HFloat) Add

func (hf HFloat) Add(b HFloat) HFloat

Add adds two HFloats and returns the result.

func (HFloat) BigFloat

func (hf HFloat) BigFloat() *big.Float

BigFloat returns the HFloat as a *big.Float.

func (HFloat) Bytes

func (hf HFloat) Bytes() []byte

Bytes returns the HFloat as a byte slice.

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) Eq

func (hf HFloat) Eq(b HFloat) bool

Eq checks if two HFloats are equal.

func (HFloat) Float

func (hf HFloat) Float() float64

Float returns the HFloat as a float64.

func (HFloat) Gt

func (hf HFloat) Gt(b HFloat) bool

Gt checks if the HFloat is greater than the specified HFloat.

func (HFloat) HInt

func (hf HFloat) HInt() HInt

HInt returns the HFloat as an HInt.

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) Mul

func (hf HFloat) Mul(b HFloat) HFloat

Mul multiplies two HFloats and returns the result.

func (HFloat) Ne

func (hf HFloat) Ne(b HFloat) bool

Ne checks if two HFloats are not equal.

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. It takes the number of decimal places (precision) as an argument and returns a new HFloat value rounded to that number of decimals.

func (HFloat) Sub

func (hf HFloat) Sub(b HFloat) HFloat

Sub subtracts two HFloats and returns the result.

func (HFloat) UInt64

func (hf HFloat) UInt64() uint64

UInt64 returns the HFloat as a uint64.

type HInt

type HInt int

func NewHInt

func NewHInt(ints ...int) HInt

NewHInt creates a new HInt with the provided int value.

func (HInt) Add

func (hi HInt) Add(b HInt) HInt

Add adds two HInts and returns the result.

func (HInt) Bytes

func (hi HInt) Bytes() []byte

Bytes returns the HInt as a byte slice.

func (HInt) Div

func (hi HInt) Div(b HInt) HInt

Div divides two HInts and returns the result.

func (HInt) Eq

func (hi HInt) Eq(b HInt) bool

Eq checks if two HInts are equal.

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) HFloat

func (hi HInt) HFloat() HFloat

HFloat returns the HInt as an HFloat.

func (HInt) HString

func (hi HInt) HString() HString

HString returns the HInt as an HString.

func (HInt) Hash

func (hi HInt) Hash() ihash

Hash returns a ihash struct wrapping the given HInt.

func (HInt) Int

func (hi HInt) Int() int

Int returns the HInt as an int.

func (HInt) Int16

func (hi HInt) Int16() int16

Int16 returns the HInt as an int16.

func (HInt) Int32

func (hi HInt) Int32() int32

Int32 returns the HInt as an int32.

func (HInt) Int64

func (hi HInt) Int64() int64

Int64 returns the HInt as an int64.

func (HInt) Int8

func (hi HInt) Int8() int8

Int8 returns the HInt as an int8.

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) Max

func (hi HInt) Max(b HInt) HInt

Max returns the maximum of two HInts.

func (HInt) Min

func (hi HInt) Min(b HInt) HInt

Min returns the minimum of two HInts.

func (HInt) Mul

func (hi HInt) Mul(b HInt) HInt

Mul multiplies two HInts and returns the result.

func (HInt) Ne

func (hi HInt) Ne(b HInt) bool

Ne checks if two HInts are not equal.

func (HInt) Random

func (hi HInt) Random() HInt

Random returns a random HInt in the range [0, hi].

func (HInt) RandomRange

func (HInt) RandomRange(min, max HInt) HInt

RandomRange returns a random HInt in the range [min, max].

func (HInt) Sub

func (hi HInt) Sub(b HInt) HInt

Sub subtracts two HInts and returns the result.

func (HInt) ToBinary

func (hi HInt) ToBinary() HString

ToBinary returns the HInt as a binary string.

func (HInt) ToHex

func (hi HInt) ToHex() HString

ToHex returns the HInt as a hexadecimal string.

func (HInt) ToOctal

func (hi HInt) ToOctal() HString

ToOctal returns the HInt as an octal string.

func (HInt) UInt

func (hi HInt) UInt() uint

UInt returns the HInt as a uint.

func (HInt) UInt16

func (hi HInt) UInt16() uint16

UInt16 returns the HInt as a uint16.

func (HInt) UInt32

func (hi HInt) UInt32() uint32

UInt32 returns the HInt as a uint32.

func (HInt) UInt64

func (hi HInt) UInt64() uint64

UInt64 returns the HInt as a uint64.

func (HInt) UInt8

func (hi HInt) UInt8() uint8

UInt8 returns the HInt as a uint8.

type HMap

type HMap[K comparable, V any] map[K]V

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.

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]) Empty

func (hmap HMap[K, V]) Empty() bool

Empty checks if the HMap is empty.

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.

func (HMap[K, V]) FilterParallel

func (hmap HMap[K, V]) FilterParallel(fn func(K, V) bool) HMap[K, V]

TODO: написать тесты. FilterParallel filters the HMap based on a given function in parallel and returns a new HMap containing the matching key-value pairs.

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.

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.

func (HMap[K, V]) Invert

func (hmap HMap[K, V]) Invert() HMap[any, K]

Invert inverts the keys and values of the HMap.

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.

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.

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]) 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.

func (HMap[K, V]) ToMap

func (hmap HMap[K, V]) ToMap() map[K]V

ToMap converts the HMap to a regular Go map.

func (HMap[K, V]) Values

func (hmap HMap[K, V]) Values() HSlice[V]

Values returns a slice of the HMap's values.

type HSlice

type HSlice[T any] []T

func HSliceOf

func HSliceOf[T any](slice ...T) HSlice[T]

HSliceOf creates a new generic slice containing the provided elements.

func NewHSlice

func NewHSlice[T any](size ...int) HSlice[T]

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.

Usage:

s1 := NewHSlice[int]()        // Creates an empty HSlice of type int
s2 := NewHSlice[int](5)       // Creates an HSlice of type int with length and capacity of 5
s3 := NewHSlice[int](3, 10)   // Creates an HSlice of type int with length of 3 and capacity of 10

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

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.

func (HSlice[T]) All

func (hsl HSlice[T]) All(fn func(T) bool) bool

All returns true if all elements in the slice satisfy the provided condition.

func (HSlice[T]) Any

func (hsl HSlice[T]) Any(fn func(T) bool) bool

Any returns true if any element in the slice satisfies the provided condition.

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]) 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 slice into chunks of the specified size.

func (HSlice[T]) Clone

func (hsl HSlice[T]) Clone() HSlice[T]

Clone returns a copy of 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]) Count

func (hsl HSlice[T]) Count(elem T) int

Count returns the count of the given element in the slice.

func (HSlice[T]) Counter

func (hsl HSlice[T]) Counter() *hMapOrd[any, int]

Counter returns an ordered map with the counts of each unique element in the slice.

func (HSlice[T]) Cut

func (hsl HSlice[T]) Cut(start, end int) HSlice[T]

Cut returns a new slice that is the current slice with the elements between the specified start and end indices removed.

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]) Difference

func (hsl HSlice[T]) Difference(other HSlice[T]) HSlice[T]

Difference returns the difference between the current slice and another slice, i.e., elements present in the current slice but not in the other 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.

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.

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.

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.

func (HSlice[T]) FilterZeroValues

func (hsl HSlice[T]) FilterZeroValues() HSlice[T]

FilterZeroValues returns a new slice with all zero values removed.

func (HSlice[T]) Flatten

func (hsl HSlice[T]) Flatten() HSlice[any]

Flatten flattens the nested slice structure into a single-level HSlice[any].

func (HSlice[T]) ForEach

func (hsl HSlice[T]) ForEach(fn func(T))

ForEach applies a given function to each element in the slice.

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]) 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(index int, values ...T) HSlice[T]

Insert inserts values at the specified index in the slice and returns the resulting slice.

func (HSlice[T]) Intersection

func (hsl HSlice[T]) Intersection(other HSlice[T]) HSlice[T]

Intersection returns the intersection of the current slice and another slice, i.e., elements present in both slices.

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]) Last

func (hsl HSlice[T]) Last() T

Last returns the last element of the slice.

func (HSlice[T]) LastIndex

func (hsl HSlice[T]) LastIndex() int

LastIndex returns the last index of the slice.

func (HSlice[T]) Len

func (hsl HSlice[T]) Len() int

Len returns the length 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.

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.

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.

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]) Random

func (hsl HSlice[T]) Random() T

Random returns a 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.

func (HSlice[T]) Range

func (hsl HSlice[T]) Range(start, end int) HSlice[T]

Range returns a new slice containing elements from the current slice between the specified start and end indices.

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.

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.

func (HSlice[T]) Reverse

func (hsl HSlice[T]) Reverse() HSlice[T]

Reverse reverses the order of the elements in the slice.

func (HSlice[T]) Set

func (hsl HSlice[T]) Set(i int, val T)

Set sets the value at the specified index in the slice.

func (HSlice[T]) Shuffle

func (hsl HSlice[T]) Shuffle() HSlice[T]

Shuffle shuffles the elements in the slice randomly.

func (HSlice[T]) SortBy

func (hsl HSlice[T]) SortBy(f func(i, j int) bool) HSlice[T]

SortBy sorts the elements in the slice using the provided comparison function.

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.

func (HSlice[T]) SymmetricDifference

func (hsl HSlice[T]) SymmetricDifference(other HSlice[T]) HSlice[T]

SymmetricDifference returns the symmetric difference between the current slice and another slice, i.e., elements present in either the current slice or the other slice but not in both.

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]) Union

func (hsl HSlice[T]) Union(other HSlice[T]) HSlice[T]

Union returns a new slice containing the unique elements of the current slice and the provided other slice.

func (HSlice[T]) Unique

func (hsl HSlice[T]) Unique() HSlice[T]

Unique returns a new slice containing unique elements from the current slice.

func (HSlice[T]) Zip

func (hsl HSlice[T]) Zip(slices ...HSlice[T]) []HSlice[T]

Zip zips the elements of the given slices with the current slice into a new slice of HSlice[T] elements.

type HString

type HString string

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) Bytes

func (hs HString) Bytes() []byte

Bytes returns the HString as a byte slice.

func (HString) Chunks

func (hs HString) Chunks(size int) HSlice[HString]

Chunks splits the HString into chunks of the specified size.

func (HString) Compare

func (hs HString) Compare(hstr HString) HInt

Compare compares two HStrings and returns an HInt indicating their relative order.

func (HString) Contains

func (hs HString) Contains(substr HString) bool

Contains checks if the HString contains the specified substring.

func (HString) ContainsAny

func (hs HString) ContainsAny(chars HString) bool

ContainsAny checks if the HString contains any character from the specified HString.

func (HString) ContainsRune

func (hs HString) ContainsRune(r rune) bool

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) HString

Cut returns a new HString that contains the text between the first occurrences of the 'start' and 'end' strings.

func (HString) Decode

func (hs HString) Decode() dec

Decode returns a dec struct wrapping the given HString.

func (HString) Empty

func (hs HString) Empty() bool

Empty checks if the HString is empty.

func (HString) Encode

func (hs HString) Encode() enc

Encode returns an enc struct wrapping the given HString.

func (HString) Eq

func (hs HString) Eq(hstr HString) bool

Eq checks if two HStrings are equal.

func (HString) Fields

func (hs HString) Fields() HSlice[HString]

Fields splits the HString into a slice of substrings, removing any whitespace.

func (HString) Gt

func (hs HString) Gt(hstr HString) bool

Gt checks if the HString is greater than the specified HString.

func (HString) HBytes

func (hs HString) HBytes() HBytes

HBytes returns the HString as an HBytes.

func (HString) HFloat

func (hs HString) HFloat() HFloat

HFloat tries to parse the HString as a float64 and returns an HFloat. If the conversion fails, it returns an HFloat with a value of 0.

func (HString) HInt

func (hs HString) HInt() HInt

HInt tries to parse the HString as an int and returns an HInt. If the conversion fails, it returns an HInt with a value of 0.

func (HString) HasPrefix

func (hs HString) HasPrefix(prefix HString) bool

HasPrefix checks if the HString has the specified prefix.

func (HString) HasSuffix

func (hs HString) HasSuffix(suffix HString) bool

HasSuffix checks if the HString has the specified suffix.

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.

func (HString) IndexRune

func (hs HString) IndexRune(r rune) int

IndexRune returns the index of the first instance of the specified rune in the HString.

func (HString) IsDigit

func (hs HString) IsDigit() bool

IsDigit checks if all characters in the HString are digits.

func (HString) Len

func (hs HString) Len() int

Len returns the length of the HString.

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

func (hs HString) Map(fn func(rune) rune) HString

Map applies the provided function to all runes in the HString and returns the resulting HString.

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) Random

func (HString) Random(count int) HString

Random generates a random HString with the specified length.

func (HString) Reader

func (hs HString) Reader() *strings.Reader

Reader returns a *strings.Reader initialized with the content of HString.

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) Reverse

func (hs HString) Reverse() HString

Reverse reverses the HString.

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.

func (HString) Split

func (hs HString) Split(sep ...HString) HSlice[HString]

Split splits the HString by the specified separator.

func (HString) String

func (hs HString) String() string

String returns the HString as a string.

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.

Directories

Path Synopsis
pkg
ref

Jump to

Keyboard shortcuts

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