gost

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 9 Imported by: 0

README

gost

GitHub license

Experience the true taste of Rust in Go

document

Install

go get github.com/myyrakle/gost@{version}

Example

package main

import (
	"math"

	gost "github.com/myyrakle/gost"
)

func CheckedAdd(a, b gost.Int) gost.Option[gost.Int] {
	max := gost.Int(math.MaxInt64)
	if (b > 0 && a > max-b) || (b < 0 && a < max-b) {
		return gost.None[gost.Int]()
	}

	return gost.Some(a + b)
}

func main() {
	a := gost.Int(1)
	b := gost.Int(2)
	result := CheckedAdd(a, b)

	if result.IsSome() {
		gost.Println("result: {}", result.Unwrap())
	} else {
		gost.Println("result: overflow")
	}

	a = gost.Int(math.MaxInt64)
	b = gost.Int(1)
	result = CheckedAdd(a, b)

	if result.IsSome() {
		gost.Println("result: {}", result.Unwrap())
	} else {
		gost.Println("result: overflow")
	}

	vector := gost.Vec[gost.Int]{}
	vector.Push(gost.Int(3))
	vector.Push(gost.Int(1))
	vector.Push(gost.Int(2))
	vector.Push(gost.Int(4))
	vector.Sort()
	gost.Println("sorted Vec: {}", vector)

	newVec := vector.IntoIter().Map(func(x gost.Int) gost.Int { return x * 2 }).CollectToVec()
	gost.Println("mapped Vec: {}", newVec)

	newVec.Push(gost.Int(7))
	foo := newVec.IntoIter().Fold(gost.Int(0), func(a, b gost.Int) gost.Int { return a + b })
	gost.Println("fold value: {}", foo)

	hashMap := gost.HashMapNew[gost.String, gost.Int]()
	hashMap.Insert(gost.String("foo"), gost.Int(1))
	hashMap.Insert(gost.String("bar"), gost.Int(2))
	hashMap.Insert(gost.String("baz"), gost.Int(3))

	gost.Println("hashMap: {}", hashMap)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print(format String, params ...any)

func Println

func Println(format String, params ...any)

Types

type Add

type Add[T any] interface {
	Add(rhs T) T
}

Add is a trait for types that support addition.

type AddAssign

type AddAssign[T any] interface {
	AddAssign(rhs T)
}

The addition assignment operator +=.

type Any

type Any interface{}

type Bool

type Bool bool

func (Bool) Clone

func (self Bool) Clone() Bool

func (Bool) Cmp

func (self Bool) Cmp(rhs Bool) Ordering

func (Bool) Debug

func (self Bool) Debug() String

func (Bool) Display

func (self Bool) Display() String

func (Bool) Eq

func (self Bool) Eq(rhs Bool) Bool

func (Bool) ToString

func (self Bool) ToString() String

type Byte

type Byte byte

func (Byte) Clone

func (self Byte) Clone() Byte

func (Byte) Cmp

func (self Byte) Cmp(rhs Byte) Ordering

func (Byte) Debug

func (self Byte) Debug() String

func (Byte) Display

func (self Byte) Display() String

func (Byte) Eq

func (self Byte) Eq(rhs Byte) Bool

func (Byte) ToString

func (self Byte) ToString() String

type Clone

type Clone[T any] interface {
	Clone() T
}

type Complex128

type Complex128 complex128

func (Complex128) Clone

func (self Complex128) Clone() Complex128

func (Complex128) Debug

func (self Complex128) Debug() String

func (Complex128) Display

func (self Complex128) Display() String

func (Complex128) ToString

func (self Complex128) ToString() String

type Complex64

type Complex64 complex64

func (Complex64) Clone

func (self Complex64) Clone() Complex64

func (Complex64) Debug

func (self Complex64) Debug() String

func (Complex64) Display

func (self Complex64) Display() String

func (Complex64) ToString

func (self Complex64) ToString() String

type Debug

type Debug[T any] interface {
	Debug() string
}

type Default

type Default[T any] interface {
	Default() T
}

A trait for giving a type a useful default value.

type DirEntry

type DirEntry struct {
	FileName String
	Path     String
	FileType FileType
}

type Display

type Display[T any] interface {
	Display() String
}

type Div

type Div[T any] interface {
	Div(rhs T) T
}

Div is a trait for types that support division.

type DivAssign

type DivAssign[T any] interface {
	DivAssign(rhs T)
}

The division assignment operator /=.

type Eq

type Eq[T any] interface {
	Eq(rhs T) Bool
}

type Error

type Error error

type FileType

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

func (FileType) IsDir

func (self FileType) IsDir() bool

func (FileType) IsFile

func (self FileType) IsFile() bool
func (self FileType) IsSymlink() bool

type Float32

type Float32 float32

func (Float32) Clone

func (self Float32) Clone() Float32

func (Float32) Cmp

func (self Float32) Cmp(rhs Float32) Ordering

func (Float32) Debug

func (self Float32) Debug() String

func (Float32) Display

func (self Float32) Display() String

func (Float32) Eq

func (self Float32) Eq(rhs Float32) Bool

func (Float32) ToString

func (self Float32) ToString() String

type Float64

type Float64 float64

func (Float64) Clone

func (self Float64) Clone() Float64

func (Float64) Cmp

func (self Float64) Cmp(rhs Float64) Ordering

func (Float64) Debug

func (self Float64) Debug() String

func (Float64) Display

func (self Float64) Display() String

func (Float64) Eq

func (self Float64) Eq(rhs Float64) Bool

func (Float64) ToString

func (self Float64) ToString() String

type HashMap

type HashMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func HashMapNew

func HashMapNew[K comparable, V any]() HashMap[K, V]

Creates an empty HashMap.

func HashMapWithCapacity

func HashMapWithCapacity[K comparable, V any](capacity Int) HashMap[K, V]

Creates an empty HashMap with at least the specified capacity.

func (HashMap[K, V]) AsMap

func (self HashMap[K, V]) AsMap() map[K]V

As Raw Map

func (*HashMap[K, V]) Clear

func (self *HashMap[K, V]) Clear()

Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.

func (HashMap[K, V]) ContainsKey

func (self HashMap[K, V]) ContainsKey(key K) Bool

Returns true if the map contains a value for the specified key.

func (HashMap[K, V]) Debug

func (self HashMap[K, V]) Debug() String

impl Debug for HashMap

func (HashMap[K, V]) Display

func (self HashMap[K, V]) Display() String

impl Display for HashMap

func (HashMap[K, V]) Get

func (self HashMap[K, V]) Get(key K) Option[V]

Returns a reference to the value corresponding to the key.

func (*HashMap[K, V]) Insert

func (self *HashMap[K, V]) Insert(key K, value V) Option[V]

Inserts a key-value pair into the map. If the map did not have this key present, None is returned.

func (HashMap[K, V]) IntoIter

func (self HashMap[K, V]) IntoIter() Iterator[Pair[K, V]]

into_iter

func (HashMap[K, V]) IsEmpty

func (self HashMap[K, V]) IsEmpty() Bool

Returns true if the map contains no elements.

func (HashMap[K, V]) Keys

func (self HashMap[K, V]) Keys() Iterator[K]

An iterator visiting all keys in arbitrary order. The iterator element type is K.

func (HashMap[K, V]) Len

func (self HashMap[K, V]) Len() Int

Returns the number of elements in the map.

func (*HashMap[K, V]) Remove

func (self *HashMap[K, V]) Remove(key K) Option[V]

Removes a key from the map, returning the value at the key if the key was previously in the map.

func (HashMap[K, V]) Values

func (self HashMap[K, V]) Values() Iterator[V]

An iterator visiting all values in arbitrary order. The iterator element type is V.

type HashMapIter

type HashMapIter[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func (HashMapIter[K, V]) CollectToVec

func (self HashMapIter[K, V]) CollectToVec() Vec[Pair[K, V]]

func (HashMapIter[K, V]) Filter

func (self HashMapIter[K, V]) Filter(f func(Pair[K, V]) Bool) Iterator[Pair[K, V]]

filter

func (HashMapIter[K, V]) Fold

func (self HashMapIter[K, V]) Fold(init Pair[K, V], f func(Pair[K, V], Pair[K, V]) Pair[K, V]) Pair[K, V]

fold

func (HashMapIter[K, V]) Map

func (self HashMapIter[K, V]) Map(f func(Pair[K, V]) Pair[K, V]) Iterator[Pair[K, V]]

map

func (*HashMapIter[K, V]) Next

func (self *HashMapIter[K, V]) Next() Option[Pair[K, V]]

next

func (HashMapIter[K, V]) Rev

func (self HashMapIter[K, V]) Rev() Iterator[Pair[K, V]]

rev

type HashMapKeys

type HashMapKeys[K any] struct {
	// contains filtered or unexported fields
}

func (HashMapKeys[K]) CollectToVec

func (self HashMapKeys[K]) CollectToVec() Vec[K]

func (HashMapKeys[K]) Filter

func (self HashMapKeys[K]) Filter(f func(K) Bool) Iterator[K]

filter

func (HashMapKeys[K]) Fold

func (self HashMapKeys[K]) Fold(init K, f func(K, K) K) K

fold

func (HashMapKeys[K]) Map

func (self HashMapKeys[K]) Map(f func(K) K) Iterator[K]

map

func (*HashMapKeys[K]) Next

func (self *HashMapKeys[K]) Next() Option[K]

next

func (HashMapKeys[K]) Rev

func (self HashMapKeys[K]) Rev() Iterator[K]

rev

type HashMapValues

type HashMapValues[V any] struct {
	// contains filtered or unexported fields
}

func (HashMapValues[V]) CollectToVec

func (self HashMapValues[V]) CollectToVec() Vec[V]

func (HashMapValues[V]) Filter

func (self HashMapValues[V]) Filter(f func(V) Bool) Iterator[V]

filter

func (HashMapValues[V]) Fold

func (self HashMapValues[V]) Fold(init V, f func(V, V) V) V

fold

func (HashMapValues[V]) Map

func (self HashMapValues[V]) Map(f func(V) V) Iterator[V]

map

func (*HashMapValues[V]) Next

func (self *HashMapValues[V]) Next() Option[V]

next

func (HashMapValues[V]) Rev

func (self HashMapValues[V]) Rev() Iterator[V]

rev

type Int

type Int int

func (Int) Clone

func (self Int) Clone() Int

func (Int) Cmp

func (self Int) Cmp(rhs Int) Ordering

func (Int) Debug

func (self Int) Debug() String

func (Int) Display

func (self Int) Display() String

func (Int) Eq

func (self Int) Eq(rhs Int) Bool

func (Int) ToString

func (self Int) ToString() String

type Int16

type Int16 int16

func (Int16) Clone

func (self Int16) Clone() Int16

func (Int16) Cmp

func (self Int16) Cmp(rhs Int16) Ordering

func (Int16) Debug

func (self Int16) Debug() String

func (Int16) Display

func (self Int16) Display() String

func (Int16) Eq

func (self Int16) Eq(rhs Int16) Bool

func (Int16) ToString

func (self Int16) ToString() String

type Int32

type Int32 int32

func (Int32) Clone

func (self Int32) Clone() Int32

func (Int32) Cmp

func (self Int32) Cmp(rhs Int32) Ordering

func (Int32) Debug

func (self Int32) Debug() String

func (Int32) Display

func (self Int32) Display() String

func (Int32) Eq

func (self Int32) Eq(rhs Int32) Bool

func (Int32) ToString

func (self Int32) ToString() String

type Int64

type Int64 int64

func (Int64) Clone

func (self Int64) Clone() Int64

func (Int64) Cmp

func (self Int64) Cmp(rhs Int64) Ordering

func (Int64) Debug

func (self Int64) Debug() String

func (Int64) Display

func (self Int64) Display() String

func (Int64) Eq

func (self Int64) Eq(rhs Int64) Bool

func (Int64) ToString

func (self Int64) ToString() String

type Int8

type Int8 int8

func (Int8) Clone

func (self Int8) Clone() Int8

func (Int8) Cmp

func (self Int8) Cmp(rhs Int8) Ordering

func (Int8) Debug

func (self Int8) Debug() String

func (Int8) Display

func (self Int8) Display() String

func (Int8) Eq

func (self Int8) Eq(rhs Int8) Bool

func (Int8) ToString

func (self Int8) ToString() String

type IntoIterator

type IntoIterator[T any] interface {
	IntoIter() Iterator[T]
}

type Iterator

type Iterator[T any] interface {
	Next() Option[T]
	Map(f func(T) T) Iterator[T]
	Filter(f func(T) Bool) Iterator[T]
	Fold(init T, f func(T, T) T) T
	Rev() Iterator[T]
	CollectToVec() Vec[T]
}

type Mul

type Mul[T any] interface {
	Mul(rhs T) T
}

Mul is a trait for types that support multiplication.

type MulAssign

type MulAssign[T any] interface {
	MulAssign(rhs T)
}

The multiplication assignment operator *=.

type Option

type Option[T any] struct {
	// contains filtered or unexported fields
}

func None

func None[T any]() Option[T]

func Some

func Some[T any](value T) Option[T]

func (Option[T]) And

func (self Option[T]) And(optb Option[any]) Option[any]

Returns None if the option is None, otherwise returns optb. Arguments passed to and are eagerly evaluated; if you are passing the result of a function call, it is recommended to use and_then, which is lazily evaluated.

func (Option[T]) AndThen

func (self Option[T]) AndThen(f func(T) Option[any]) Option[any]

Returns None if the option is None, otherwise calls f with the wrapped value and returns the result. Some languages call this operation flatmap.

func (Option[T]) Debug

func (self Option[T]) Debug() String

impl Debug for Option

func (Option[T]) Display

func (self Option[T]) Display() String

impl Display for Option

func (Option[T]) Expect

func (self Option[T]) Expect(message string) T

Returns the contained Some value, consuming the self value.

func (Option[T]) Filter

func (self Option[T]) Filter(predicate func(T) Bool) Option[T]

Returns None if the option is None, otherwise calls predicate with the wrapped value and returns: 1. Some(t) if predicate returns true (where t is the wrapped value), and 2. None if predicate returns false.

func (*Option[T]) GetOrInsert

func (self *Option[T]) GetOrInsert(value T) *T

Inserts value into the option if it is None, then returns a mutable reference to the contained value. See also Option::insert, which updates the value even if the option already contains Some.

func (*Option[T]) GetOrInsertWith

func (self *Option[T]) GetOrInsertWith(f func() T) *T

Inserts a value computed from f into the option if it is None, then returns a mutable reference to the contained value.

func (*Option[T]) Insert

func (self *Option[T]) Insert(value T) *T

Inserts value into the option, then returns a mutable reference to it. If the option already contains a value, the old value is dropped. See also Option::get_or_insert, which doesn’t update the value if the option already contains Some.

func (*Option[T]) IsNone

func (self *Option[T]) IsNone() Bool

Returns true if the option is a None value.

func (*Option[T]) IsSome

func (self *Option[T]) IsSome() Bool

Returns true if the option is a Some value.

func (*Option[T]) IsSomeAnd

func (self *Option[T]) IsSomeAnd(f func(T) Bool) Bool

Returns true if the option is a Some and the value inside of it matches a predicate.

func (Option[T]) Map

func (self Option[T]) Map(f func(T) T) Option[T]

Maps an Option<T> to other Option<T> by applying a function to a contained value (if Some) or returns None (if None).

func (Option[T]) MapOr

func (self Option[T]) MapOr(defaultValue T, f func(T) T) T

Returns the provided default result (if none), or applies a function to the contained value (if any). Arguments passed to map_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use map_or_else, which is lazily evaluated.

func (Option[T]) MapOrElse

func (self Option[T]) MapOrElse(defaultValue func() T, f func(T) T) T

Computes a default function result (if none), or applies a different function to the contained value (if any).

func (Option[T]) Or

func (self Option[T]) Or(optb Option[T]) Option[T]

Returns the option if it contains a value, otherwise returns optb. Arguments passed to or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use or_else, which is lazily evaluated.

func (Option[T]) OrElse

func (self Option[T]) OrElse(f func() Option[T]) Option[T]

Returns the option if it contains a value, otherwise calls f and returns the result.

func (*Option[T]) Replace

func (self *Option[T]) Replace(value T) Option[T]

Replaces the actual value in the option by the value given in parameter, returning the old value if present, leaving a Some in its place without deinitializing either one.

func (*Option[T]) Take

func (self *Option[T]) Take() Option[T]

Takes the value out of the option, leaving a None in its place.

func (Option[T]) Unwrap

func (self Option[T]) Unwrap() T

Returns the contained Some value, consuming the self value. Because this function may panic, its use is generally discouraged. Instead, prefer to use pattern matching and handle the None case explicitly, or call unwrap_or, unwrap_or_else, or unwrap_or_default.

func (Option[T]) UnwrapOr

func (self Option[T]) UnwrapOr(value T) T

Returns the contained Some value or a provided default. Arguments passed to unwrap_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrap_or_else, which is lazily evaluated.

func (Option[T]) UnwrapOrElse

func (self Option[T]) UnwrapOrElse(f func() T) T

Returns the contained Some value or computes it from a closure.

func (Option[T]) Xor

func (self Option[T]) Xor(optb Option[T]) Option[T]

Returns Some if exactly one of self, optb is Some, otherwise returns None.

type Ord

type Ord[T any] interface {
	Cmp(rhs T) Ordering
}

type Ordering

type Ordering int
const OrderingEqual Ordering = Ordering(0)
const OrderingGreater Ordering = Ordering(1)
const OrderingLess Ordering = Ordering(-1)

Ordering enum values

type Pair

type Pair[K comparable, V any] struct {
	Key   K
	Value V
}

type Result

type Result[T any] struct {
	// contains filtered or unexported fields
}

func Copy

func Copy(from String, to String) Result[any]

Copies the contents of one file to another. This function will also copy the permission bits of the original file to the destination file. This function will overwrite the contents of to.

func CreateDir

func CreateDir(path String) Result[any]

Creates a new, empty directory at the provided path

func Err

func Err[T any](err error) Result[T]

func Ok

func Ok[T any](value T) Result[T]

func Read

func Read(path String) Result[[]Byte]

Read the entire contents of a file into a bytes vector.

func ReadDir

func ReadDir(path String) Result[Vec[DirEntry]]

Returns an iterator over the entries within a directory.

func ReadToString

func ReadToString(path String) Result[String]

Read the entire contents of a file into a string.

func RemoveDir

func RemoveDir(path String) Result[any]

Removes an empty directory.

func RemoveFile

func RemoveFile(path String) Result[any]

Removes a file from the filesystem.

func Rename

func Rename(from String, to String) Result[any]

Rename a file or directory to a new name, replacing the original file if to already exists. This will not work if the new name is on a different mount point.

func Write

func Write(path String, data []Byte) Result[any]

Write a slice as the entire contents of a file.

func (Result[T]) And

func (self Result[T]) And(res Result[T]) Result[T]

Returns res if the result is Ok, otherwise returns the Err value of self. Arguments passed to and are eagerly evaluated; if you are passing the result of a function call, it is recommended to use and_then, which is lazily evaluated.

func (Result[T]) AndThen

func (self Result[T]) AndThen(op func(T) Result[T]) Result[T]

Calls op if the result is Ok, otherwise returns the Err value of self. This function can be used for control flow based on Result values.

func (Result[T]) Debug

func (self Result[T]) Debug() String

impl Debug for Result

func (Result[T]) Display

func (self Result[T]) Display() String

impl Display for Result

func (Result[T]) Err

func (self Result[T]) Err() Option[error]

Converts from Result<T, E> to Option<E>. Converts self into an Option<E>, consuming self, and discarding the success value, if any.

func (Result[T]) Expect

func (self Result[T]) Expect(message string) T

Returns the contained Ok value, consuming the self value. Because this function may panic, its use is generally discouraged. Instead, prefer to use pattern matching and handle the Err case explicitly, or call unwrap_or, unwrap_or_else, or unwrap_or_default.

func (Result[T]) ExpectErr

func (self Result[T]) ExpectErr(message string) error

Returns the contained Err value, consuming the self value.

func (Result[T]) IsErr

func (self Result[T]) IsErr() Bool

Returns true if the result is Err.

func (Result[T]) IsErrAnd

func (self Result[T]) IsErrAnd(predicate func(error) Bool) Bool

Returns true if the result is Err and the value inside of it matches a predicate.

func (Result[T]) IsOk

func (self Result[T]) IsOk() Bool

Returns true if the result is Ok.

func (Result[T]) IsOkAnd

func (self Result[T]) IsOkAnd(predicate func(T) Bool) Bool

Returns true if the result is Ok and the value inside of it matches a predicate.

func (Result[T]) Map

func (self Result[T]) Map(f func(T) T) Result[T]

Maps a Result<T, E> to Result<U, E> by applying a function to a contained Ok value, leaving an Err value untouched. This function can be used to compose the results of two functions.

func (Result[T]) MapErr

func (self Result[T]) MapErr(f func(error) error) Result[T]

Maps a Result<T, E> to Result<T, F> by applying a function to a contained Err value, leaving an Ok value untouched. This function can be used to pass through a successful result while handling an error.

func (Result[T]) MapOr

func (self Result[T]) MapOr(defaultValue T, f func(T) T) T

Returns the provided default (if Err), or applies a function to the contained value (if Ok), Arguments passed to map_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use map_or_else, which is lazily evaluated.

func (Result[T]) MapOrElse

func (self Result[T]) MapOrElse(defaultValue func() T, f func(T) T) T

Maps a Result<T, E> to U by applying fallback function default to a contained Err value, or function f to a contained Ok value. This function can be used to unpack a successful result while handling an error.

func (Result[T]) Ok

func (self Result[T]) Ok() Option[T]

Converts from Result<T, E> to Option<T>. Converts self into an Option<T>, consuming self, and discarding the error, if any.

func (Result[T]) Or

func (self Result[T]) Or(res Result[T]) Result[T]

Returns res if the result is Err, otherwise returns the Ok value of self. Arguments passed to or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use or_else, which is lazily evaluated.

func (Result[T]) OrElse

func (self Result[T]) OrElse(op func(error) Result[T]) Result[T]

Calls op if the result is Err, otherwise returns the Ok value of self. This function can be used for control flow based on result values.

func (Result[T]) Unwrap

func (self Result[T]) Unwrap() T

Returns the contained Ok value, consuming the self value. Because this function may panic, its use is generally discouraged. Instead, prefer to use pattern matching and handle the Err case explicitly, or call unwrap_or, unwrap_or_else, or unwrap_or_default.

func (Result[T]) UnwrapErr

func (self Result[T]) UnwrapErr() error

Returns the contained Err value, consuming the self value.

func (Result[T]) UnwrapOr

func (self Result[T]) UnwrapOr(defaultValue T) T

Returns the contained Ok value or a provided default. Arguments passed to unwrap_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrap_or_else, which is lazily evaluated.

func (Result[T]) UnwrapOrElse

func (self Result[T]) UnwrapOrElse(f func() T) T

Returns the contained Ok value or computes it from a closure.

type Rune

type Rune rune

func (Rune) Clone

func (self Rune) Clone() Rune

func (Rune) Cmp

func (self Rune) Cmp(rhs Rune) Ordering

func (Rune) Debug

func (self Rune) Debug() String

func (Rune) Display

func (self Rune) Display() String

func (Rune) Eq

func (self Rune) Eq(rhs Rune) Bool

func (Rune) ToString

func (self Rune) ToString() String

type Stdin

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

func (*Stdin) Lock

func (self *Stdin) Lock() *sync.Mutex

Locks this handle to the standard input stream, returning a readable guard.

func (*Stdin) ReadLine

func (self *Stdin) ReadLine(buffer *String)

Locks this handle and reads a line of input, appending it to the specified buffer.

type String

type String string

func Format

func Format(format String, params ...any) String

func (String) Clone

func (self String) Clone() String

func (String) Cmp

func (self String) Cmp(rhs String) Ordering

func (String) Debug

func (self String) Debug() String

func (String) Display

func (self String) Display() String

func (String) Eq

func (self String) Eq(rhs String) Bool

func (String) ToString

func (self String) ToString() String

type Sub

type Sub[T any] interface {
	Sub(rhs T) T
}

Sub is a trait for types that support subtraction.

type SubAssign

type SubAssign[T any] interface {
	SubAssign(rhs T)
}

The subtraction assignment operator -=.

type ToString

type ToString[T any] interface {
	ToString() String
}

A trait for converting a value to a String.

type Uint

type Uint uint

func (Uint) Clone

func (self Uint) Clone() Uint

func (Uint) Cmp

func (self Uint) Cmp(rhs Uint) Ordering

func (Uint) Debug

func (self Uint) Debug() String

func (Uint) Display

func (self Uint) Display() String

func (Uint) Eq

func (self Uint) Eq(rhs Uint) Bool

func (Uint) ToString

func (self Uint) ToString() String

type Uint16

type Uint16 uint16

func (Uint16) Clone

func (self Uint16) Clone() Uint16

func (Uint16) Cmp

func (self Uint16) Cmp(rhs Uint16) Ordering

func (Uint16) Debug

func (self Uint16) Debug() String

func (Uint16) Display

func (self Uint16) Display() String

func (Uint16) Eq

func (self Uint16) Eq(rhs Uint16) Bool

func (Uint16) ToString

func (self Uint16) ToString() String

type Uint32

type Uint32 uint32

func (Uint32) Clone

func (self Uint32) Clone() Uint32

func (Uint32) Cmp

func (self Uint32) Cmp(rhs Uint32) Ordering

func (Uint32) Debug

func (self Uint32) Debug() String

func (Uint32) Display

func (self Uint32) Display() String

func (Uint32) Eq

func (self Uint32) Eq(rhs Uint32) Bool

func (Uint32) ToString

func (self Uint32) ToString() String

type Uint64

type Uint64 uint64

func (Uint64) Clone

func (self Uint64) Clone() Uint64

func (Uint64) Cmp

func (self Uint64) Cmp(rhs Uint64) Ordering

func (Uint64) Debug

func (self Uint64) Debug() String

func (Uint64) Display

func (self Uint64) Display() String

func (Uint64) Eq

func (self Uint64) Eq(rhs Uint64) Bool

func (Uint64) ToString

func (self Uint64) ToString() String

type Uint8

type Uint8 uint8

func (Uint8) Clone

func (self Uint8) Clone() Uint8

func (Uint8) Cmp

func (self Uint8) Cmp(rhs Uint8) Ordering

func (Uint8) Debug

func (self Uint8) Debug() String

func (Uint8) Display

func (self Uint8) Display() String

func (Uint8) Eq

func (self Uint8) Eq(rhs Uint8) Bool

func (Uint8) ToString

func (self Uint8) ToString() String

type Vec

type Vec[T any] struct {
	// contains filtered or unexported fields
}

func VecNew

func VecNew[T any]() Vec[T]

Constructs a new, empty Vec<T>. The vector will not allocate until elements are pushed onto it.

func VecWithCapacity

func VecWithCapacity[T any](capacity Int) Vec[T]

Constructs a new, empty Vec<T> with at least the specified capacity.

func VecWithLen

func VecWithLen[T any](len Int) Vec[T]

Constructs a new, empty Vec<T> with at least the specified capacity.

func (*Vec[T]) Append

func (self *Vec[T]) Append(other *Vec[T])

Moves all the elements of other Into self, leaving other empty.

func (Vec[T]) AsSlice

func (self Vec[T]) AsSlice() []T

Extracts a slice containing the entire vector.

func (Vec[T]) BinarySearch

func (self Vec[T]) BinarySearch(value T) Option[Int]

Binary searches this slice for a given element. If the slice is not sorted, the returned result is unspecified and meaningless.

func (Vec[T]) BinarySearchBy

func (self Vec[T]) BinarySearchBy(f func(T) Ordering) Option[Int]

Binary searches this slice with a comparator function. The comparator function should return an order code that indicates whether its argument is Less, Equal or Greater the desired target. If the slice is not sorted or if the comparator function does not implement an order consistent with the sort order of the underlying slice, the returned result is unspecified and meaningless.

func (Vec[T]) Capacity

func (self Vec[T]) Capacity() Int

Returns the total number of elements the vector can hold without reallocating.

func (*Vec[T]) Clear

func (self *Vec[T]) Clear()

Clears the vector, removing all values.

func (Vec[T]) Contains

func (self Vec[T]) Contains(value T) Bool

Returns true if the slice contains an element with the given value. This operation is O(n). Note that if you have a sorted slice, binary_search may be faster.

func (Vec[T]) Debug

func (self Vec[T]) Debug() String

impl Debug for Vec

func (*Vec[T]) Dedup

func (self *Vec[T]) Dedup()

Removes consecutive repeated elements in the vector according to the PartialEq trait implementation. If the vector is sorted, this removes all duplicates.

func (*Vec[T]) DedupByKey

func (self *Vec[T]) DedupByKey(key func(T) any)

Removes all but the first of consecutive elements in the vector that resolve to the same key. If the vector is sorted, this removes all duplicates.

func (Vec[T]) Display

func (self Vec[T]) Display() String

impl Display for Vec

func (*Vec[T]) Fill

func (self *Vec[T]) Fill(value T)

Fills self with elements by cloning value.

func (*Vec[T]) FillWith

func (self *Vec[T]) FillWith(f func() T)

Fills self with elements returned by calling a closure repeatedly.

func (Vec[T]) Get

func (self Vec[T]) Get(index Int) Option[T]

Returns a reference to an element or subslice depending on the type of index. If given a position, returns a reference to the element at that position or None if out of bounds. If given a range, returns the subslice corresponding to that range, or None if out of bounds.

func (Vec[T]) GetUnchecked

func (self Vec[T]) GetUnchecked(index Int) T

Returns a reference to an element or subslice, without doing bounds checking. For a safe alternative see get.

func (*Vec[T]) Insert

func (self *Vec[T]) Insert(index Int, value T)

Inserts an element at position index within the vector, shifting all elements after it to the right.

func (Vec[T]) IntoIter

func (self Vec[T]) IntoIter() Iterator[T]

into_iter

func (Vec[T]) IsEmpty

func (self Vec[T]) IsEmpty() Bool

Returns true if the vector contains no elements.

func (Vec[T]) Len

func (self Vec[T]) Len() Int

Returns the number of elements in the vector, also referred to as its ‘length’.

func (*Vec[T]) Pop

func (self *Vec[T]) Pop() Option[T]

Removes the last element from a vector and returns it, or None if it is empty.

func (*Vec[T]) Push

func (self *Vec[T]) Push(value T)

Appends an element to the back of a collection.

func (*Vec[T]) Reserve

func (self *Vec[T]) Reserve(additional Int)

Reserves capacity for at least additional more elements to be inserted in the given Vec<T>. The collection may reserve more space to speculatively avoid frequent reallocations. After calling reserve, capacity will be greater than or equal to self.len() + additional. Does nothing if capacity is already sufficient.

func (*Vec[T]) Retain

func (self *Vec[T]) Retain(predicate func(T) Bool)

Retains only the elements specified by the predicate.

func (*Vec[T]) Reverse

func (self *Vec[T]) Reverse()

Reverses the order of elements in the slice, in place.

func (*Vec[T]) Sort

func (self *Vec[T]) Sort()

Sorts the slice. This sort is stable (i.e., does not reorder equal elements) and O(n * log(n)) worst-case. When applicable, unstable sorting is preferred because it is generally faster than stable sorting and it doesn’t allocate auxiliary memory. See sort_unstable.

func (*Vec[T]) SortBy

func (self *Vec[T]) SortBy(compare func(T, T) Ordering)

Sorts the slice with a comparator function. This sort is stable (i.e., does not reorder equal elements) and O(n * log(n)) worst-case. The comparator function must define a total ordering for the elements in the slice. If the ordering is not total, the order of the elements is unspecified. An order is a total order if it is (for all a, b and c): - total and antisymmetric: exactly one of a < b, a == b or a > b is true, and - transitive, a < b and b < c implies a < c. The same must hold for both == and >.

func (*Vec[T]) SortUnstable

func (self *Vec[T]) SortUnstable()

Sorts the slice, but might not preserve the order of equal elements. This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not allocate), and O(n * log(n)) worst-case.

func (*Vec[T]) SortUnstableBy

func (self *Vec[T]) SortUnstableBy(compare func(T, T) Ordering)

Sorts the slice with a comparator function, but might not preserve the order of equal elements. This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not allocate), and O(n * log(n)) worst-case. The comparator function must define a total ordering for the elements in the slice. If the ordering is not total, the order of the elements is unspecified. An order is a total order if it is (for all a, b and c): - total and antisymmetric: exactly one of a < b, a == b or a > b is true, and - transitive, a < b and b < c implies a < c. The same must hold for both == and >.

func (*Vec[T]) Swap

func (self *Vec[T]) Swap(a, b Int)

Swaps two elements in the slice. If a equals to b, it’s guaranteed that elements won’t change value.

type VecIter

type VecIter[T any] struct {
	// contains filtered or unexported fields
}

func (VecIter[T]) CollectToVec

func (self VecIter[T]) CollectToVec() Vec[T]

func (VecIter[T]) Filter

func (self VecIter[T]) Filter(f func(T) Bool) Iterator[T]

filter

func (VecIter[T]) Fold

func (self VecIter[T]) Fold(init T, f func(T, T) T) T

fold

func (VecIter[T]) Map

func (self VecIter[T]) Map(f func(T) T) Iterator[T]

map

func (*VecIter[T]) Next

func (self *VecIter[T]) Next() Option[T]

next

func (VecIter[T]) Rev

func (self VecIter[T]) Rev() Iterator[T]

rev

Jump to

Keyboard shortcuts

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