Documentation ¶
Overview ¶
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
SPDX-License-Identifier: 0BSD
Index ¶
- Constants
- func Catch(handler ...func(error))
- func ContainsValue[K comparable, V comparable](m Map[K, V], value V) bool
- func Debug(values ...string)
- func DebugAny(values ...any)
- func DebugIsActive() bool
- func DebugPop()
- func DebugPushOff()
- func DebugPushOn()
- func DebugSetOff()
- func DebugSetOn()
- func FileBaseName(fileNameOrPath string) string
- func FileExtension(fileNameOrPath string) string
- func FileWithoutExtension(fileNameOrPath string) string
- func Print(values ...string)
- func PrintAny(values ...any)
- func PrintAnyLn(values ...any)
- func PrintAnyStdErr(values ...any)
- func PrintAnyStdErrLn(values ...any)
- func PrintLn(values ...string)
- func PrintStdErr(values ...string)
- func PrintStdErrLn(values ...string)
- func ReflectFunctionName(optFuncLevel ...int) (functionName string)
- func ReflectType[T any](instances ...T) reflect.Type
- func ReflectTypeName[T any](instance ...T) string
- func Str(values ...any) string
- func StrCat(stringsToJoin ...string) string
- func StrJoin(separator string, stringsToJoin ...string) string
- func Throw(errorMessages ...string)
- func ThrowIf(condition bool, errorMessages ...string)
- func ThrowIfError(err error)
- type Array
- func FindAll[K comparable, V any](m Map[K, V], condition func(key K, value V) bool) Array[Pair[K, V]]
- func MapValues[K any, V any, TO any](fromIterator Iterator[K, V], mapperFunc func(key K, value V) Optional[TO]) Array[TO]
- func NewArray[V any](capacity ...int) Array[V]
- func NewArrayFrom[V any](items ...V) Array[V]
- func RemoveAll[V any](arr Array[V], condition func(value V) bool) Array[V]
- func TypeCastArray[TO any, FROM any](fromArray Array[FROM]) Array[TO]
- type Container
- type Dir
- func (dir Dir) Cd(folderName string) Result[Dir]
- func (dir Dir) CreateDir(folderName string) Result[Dir]
- func (dir Dir) Exists() bool
- func (dir Dir) HasParent() bool
- func (dir Dir) IsDirectory(fileName string) bool
- func (dir Dir) IsFile(fileName string) bool
- func (dir Dir) IsSymlink(fileName string) bool
- func (dir Dir) NewIterator() Iterator[int, string]
- func (dir Dir) Parent() Result[Dir]
- func (dir Dir) ReadAllBytes(fromFileName string) Result[[]byte]
- func (dir Dir) ReadAllText(fromFileName string) Result[string]
- func (dir Dir) String() string
- func (dir Dir) WriteAllText(toFileName string, text string) error
- type DomVisitor
- type Iterable
- type Iterator
- type Map
- func NewHashMap[K comparable, V any]() Map[K, V]
- func NewHashMapFrom[K comparable, V any](values map[K]V) Map[K, V]
- func NewMap[K comparable, V any]() Map[K, V]
- func NewMapFrom[K comparable, V any](values map[K]V) Map[K, V]
- func NewSet[K comparable]() Map[K, struct{}]
- func NewSetFrom[K comparable](values ...K) Map[K, struct{}]
- type Optional
- type Pair
- type Result
- func DirUserHome() Result[Dir]
- func FromJson[T any](jsonString string) Result[T]
- func FromJsonInterface[T any](jsonString string, object *T) Result[T]
- func MkDirAndPath(fullPathString string) Result[Dir]
- func NewResultError[V any](errorMessageParts ...string) Result[V]
- func NewResultFrom[V any](value V) Result[V]
- func NewResultFromError[V any](err error) Result[V]
- func String2Bool(s string) Result[bool]
- func String2Float(s string) Result[float64]
- func String2Int(s string) Result[int64]
- func ToJson(object any) Result[string]
- func ToJsonPretty(object any, indentationString string) Result[string]
- func TypeCast[T any](it any) Result[T]
- type Set
- type SliceIterator
- type Stack
- type StringBuilder
Constants ¶
const FilePathSeparator = string(os.PathSeparator)
const RunningOnWindows = runtime.GOOS == "windows"
Variables ¶
This section is empty.
Functions ¶
func Catch ¶
func Catch(handler ...func(error))
Catches errors thrown by "Throw" or "ThrowIf", recovers the panic Needs to be called before throwing errors Only handles errors. If you throw/panic something else, you need to provide a custom recover function
func ContainsValue ¶
func ContainsValue[K comparable, V comparable](m Map[K, V], value V) bool
Checks if a sx.Map or sx.Array contains a certain value (for keys we can just use map.Has(key))
func Debug ¶
func Debug(values ...string)
Print debug messages will not print by default, please call "SetDebugOn" first
func DebugAny ¶ added in v1.0.2
func DebugAny(values ...any)
Print debug messages will not print by default, please call "SetDebugOn" first
func DebugIsActive ¶ added in v1.0.2
func DebugIsActive() bool
func DebugPushOff ¶ added in v1.0.2
func DebugPushOff()
func DebugPushOn ¶ added in v1.0.2
func DebugPushOn()
func DebugSetOff ¶ added in v1.0.2
func DebugSetOff()
func DebugSetOn ¶ added in v1.0.2
func DebugSetOn()
func FileBaseName ¶ added in v1.0.2
func FileExtension ¶ added in v1.0.2
func FileWithoutExtension ¶ added in v1.0.2
func PrintAnyLn ¶ added in v1.0.2
func PrintAnyLn(values ...any)
func PrintAnyStdErr ¶ added in v1.0.2
func PrintAnyStdErr(values ...any)
func PrintAnyStdErrLn ¶ added in v1.0.2
func PrintAnyStdErrLn(values ...any)
func PrintStdErr ¶ added in v1.0.2
func PrintStdErr(values ...string)
func PrintStdErrLn ¶ added in v1.0.2
func PrintStdErrLn(values ...string)
func ReflectFunctionName ¶
Shows function name of the caller of the current function
returns empty string when in "main"
optFuncLevel 0 (default) means current Function name
optFuncLevel 1 (default) means caller of current function
optFuncLevel 2+ (default) means caller of caller of current function...
func ReflectType ¶ added in v1.0.2
Returns the reflect.Type for an instance of a type.
Also works without an actual instance by passing 'nil'.
func ReflectTypeName ¶ added in v1.0.2
func StrJoin ¶ added in v1.0.2
Joins strings using a separator, but without adding any extra (white-)spaces
func ThrowIfError ¶ added in v1.0.2
func ThrowIfError(err error)
Types ¶
type Array ¶
type Array[V any] interface { Iterable[int, V] Stack[V] Map[int, V] Compact() // Copies Array and removes excessive memory SubSlice(fromIndexToIndex ...int) []V // Returns a go slice }
func FindAll ¶
func FindAll[K comparable, V any](m Map[K, V], condition func(key K, value V) bool) Array[Pair[K, V]]
Finds all entries in sx.Map or sx.Array where the condition is true and returns a list of key/value pairs
func MapValues ¶ added in v1.0.3
func MapValues[K any, V any, TO any](fromIterator Iterator[K, V], mapperFunc func(key K, value V) Optional[TO]) Array[TO]
Maps the Iterator Values to a new type
Can return
func NewArrayFrom ¶
type Dir ¶ added in v1.0.2
type Dir string
func NewDir ¶ added in v1.0.2
Create a Dir from its parts It is assumed that there are no FilePathSeparators within the parts Directories always end with the FilePathSeparator
func NewDirFromString ¶ added in v1.0.2
Create a Dir from a path/string Directories always end with the FilePathSeparator
func (Dir) IsDirectory ¶ added in v1.0.2
func (Dir) ReadAllBytes ¶ added in v1.0.2
func (Dir) ReadAllText ¶ added in v1.0.2
Reads all the text from a file, newlines are always converted to '\n'
type DomVisitor ¶ added in v1.0.3
type DomVisitor[Context any] struct { Context Context BeforeVisit func(context Context, domTreeNode any) (continueVisit bool) AfterVisit func(context Context, domTreeNode any) }
func NewDomVisitor ¶ added in v1.0.3
func NewDomVisitor[Context any](ctx Context) (visitor DomVisitor[Context])
func (DomVisitor[Context]) VisitRecursively ¶ added in v1.0.3
func (visitor DomVisitor[Context]) VisitRecursively(domTreeNode any)
type Iterator ¶
type Iterator[K any, V any] interface { Ok() bool // Checks if iterator is valid and can return a key or a value. For empty containers, this is false after iterator creation. Key() K // Returns the key of the current item Value() V // Returns the value of the current item Next() // Finds the next item. If it reached the end, Ok() will return false after this call }
func NewMapIterator ¶ added in v1.0.3
func NewMapIterator[K comparable, V any](m map[K]V) Iterator[K, V]
type Map ¶
type Map[K comparable, V any] interface { Set[K, V] Get(K) Result[V] // Returns Value for the key (if present) }
func NewHashMap ¶
func NewHashMap[K comparable, V any]() Map[K, V]
func NewHashMapFrom ¶
func NewHashMapFrom[K comparable, V any](values map[K]V) Map[K, V]
func NewMap ¶
func NewMap[K comparable, V any]() Map[K, V]
func NewMapFrom ¶
func NewMapFrom[K comparable, V any](values map[K]V) Map[K, V]
func NewSet ¶ added in v1.0.3
func NewSet[K comparable]() Map[K, struct{}]
func NewSetFrom ¶
func NewSetFrom[K comparable](values ...K) Map[K, struct{}]
type Optional ¶
type Optional[T any] struct { // contains filtered or unexported fields }
func FindFirstWhere ¶
func FindFirstWhere[K comparable, V any](m Map[K, V], condition func(key K, value V) bool) Optional[Pair[K, V]]
Finds first entry in sx.Map or sx.Array where the condition is true and returns a key/value pair
func NewOptional ¶
func NewOptionalFrom ¶
func (Optional[T]) NewIterator ¶
func (Optional[T]) ValueOrDefault ¶
func (opt Optional[T]) ValueOrDefault() (value T)
type Result ¶
type Result[T any] struct { // contains filtered or unexported fields }
func DirUserHome ¶ added in v1.0.2
func FromJsonInterface ¶ added in v1.0.3
func MkDirAndPath ¶ added in v1.0.2
Returns a Dir from a string, creates a new directory if needed (including all parents)
func NewResultError ¶
func NewResultFrom ¶
func NewResultFromError ¶ added in v1.0.2
func String2Bool ¶
func String2Float ¶
func String2Int ¶
func ToJsonPretty ¶ added in v1.0.3
Tries to convert object to a pretty-printed json string
recommended indentationStrings are "\t" or multiple spaces
func (Result[T]) ValueIsOptional ¶ added in v1.0.2
func (Result[T]) ValueOrInit ¶ added in v1.0.2
func (r Result[T]) ValueOrInit() (value T)
func (Result[T]) ValueOrThrow ¶ added in v1.0.2
type SliceIterator ¶ added in v1.0.3
func NewSliceIterator ¶ added in v1.0.3
func NewSliceIterator[V any](slice []V) SliceIterator[int, V]
func (SliceIterator[int, V]) Key ¶ added in v1.0.3
func (it SliceIterator[int, V]) Key() int
func (*SliceIterator[int, V]) Next ¶ added in v1.0.3
func (it *SliceIterator[int, V]) Next()
func (SliceIterator[int, V]) Ok ¶ added in v1.0.3
func (it SliceIterator[int, V]) Ok() bool
func (SliceIterator[int, V]) SetValue ¶ added in v1.0.3
func (it SliceIterator[int, V]) SetValue(v V)
func (SliceIterator[int, V]) Value ¶ added in v1.0.3
func (it SliceIterator[int, V]) Value() V
type Stack ¶
type StringBuilder ¶ added in v1.0.2
func NewStringBuilder ¶ added in v1.0.2
func NewStringBuilder() *StringBuilder
func (*StringBuilder) WriteAny ¶ added in v1.0.2
func (sb *StringBuilder) WriteAny(values ...any) *StringBuilder
func (*StringBuilder) WriteStrings ¶ added in v1.0.2
func (sb *StringBuilder) WriteStrings(values ...string) *StringBuilder