package nstd
Import Path
go101.org/nstd (on go.dev)
Dependency Relation
imports 8 packages, and imported by 0 packages
Involved Source Files
builtin.go
byteseq.go
container.go
conv.go
fmt.go
io.go
log.go
nstd packages provide some missing types and functions
in standard library.
numeric.go
ordered.go
os.go
reflect.go
sync.go
time.go
Package-Level Type Names (total 11)
A ByteSeq is either a string or a byte slice.
Complex is a constraint that permits any complex numeric type.
If future releases of Go add new predeclared complex numeric types,
this constraint will be modified to include them.
Float is a constraint that permits any floating-point type.
If future releases of Go add new predeclared floating-point types,
this constraint will be modified to include them.
Integer is a constraint that permits any integer type.
If future releases of Go add new predeclared integer types,
this constraint will be modified to include them.
Methods of *Mutex return a *Mutex result, so that
these methods may be called in a chain.
It is just a simpler wrapper of the [sync.Mutex].
The main purpose of this type is to support
the following use case:
var aMutex nstd.Mutex
func foo() {
defer aMutex.Lock().Unlock()
... // do something
}
Do guards the execution of a function in Lock() and Unlock()
See: https://github.com/golang/go/issues/63941
Lock return m, so that the methods of m can be called in chain.
Unlock return m, so that the methods of m can be called in chain.
func (*Mutex).Lock() *Mutex
func (*Mutex).Unlock() *Mutex
type Numeric (interface)
Ordered is a constraint that permits any ordered type: any type
that supports the operators < <= >= >.
If future releases of Go add new ordered types,
this constraint will be modified to include them.
type Real (interface)
Signed is a constraint that permits any signed integer type.
If future releases of Go add new predeclared signed integer types,
this constraint will be modified to include them.
Unsigned is a constraint that permits any unsigned integer type.
If future releases of Go add new predeclared unsigned integer types,
this constraint will be modified to include them.
WaitGroup extends sync.WaitGroup.
Each WaitGroup maintains an internal count which initial value is zero.
GoN starts several concurrent tasks and increases the internal count by len(fs).
The internal count will be descreased by one when each of the task is done.
See: https://github.com/golang/go/issues/18022
GoN starts a task n times concurrently and increases the internal count by n.
The internal count will be descreased by one when each of the task instances is done.
Wait blocks until the internal counter is zero.
WaitChannel returns a channel which reads will block until the internal counter is zero.
Package-Level Functions (total 33)
Type Parameters:
K: comparable
E: any
AppendMapKeys appends all the keys in a map into the specified slice.
Type Parameters:
B: ~bool
Btoi converts a bool value to int (true -> 1, false -> 0).
See: https://github.com/golang/go/issues/64825
Type Parameters:
X: ByteSeq
Y: ByteSeq
ByteSeqCommonPrefixes returns the common prefixes of two [ByteSeq] values.
Type Parameters:
T: Ordered
Clamp clamps an ordered value within a range.
Both min and max are inclusive.
If v is NaN, then NaN is returned.
See: https://github.com/golang/go/issues/58146
Type Parameters:
K: comparable
E: any
CollectMapKeys collects all the keys in a map into a freshly
created result slice. The length and capacity of the result slice
are both equal to the length of the map.
See: https://github.com/golang/go/issues/68261
ElapsedTimeLogFunc returns a function which prints the duration elapsed
since the time the function is invoked.
Use example:
logElapsedTime := nstd.ElapsedTimeLogFunc("")
... // do task 1
logElapsedTime("task 1:")
... // do task 1
logElapsedTime("task 2:")
Type Parameters:
T: any
Eval is used to ensure the evaluation order of some expressions
in a statement.
See:
* https://go101.org/article/evaluation-orders.html
* https://github.com/golang/go/issues/27804
* https://github.com/golang/go/issues/36449
Type Parameters:
K: comparable
E: any
HasMapEntry checks whether or not a map contains an entry
with the specified key.
Different from log.Print, Log returns a true bool value,
so that it can be used in
_ = Debug && nstd.Log(...)
Different from log.Printf, Logf returns a true bool value,
so that it can be used in
_ = Debug && nstd.Logf(...)
Different from log.Println, Logln returns a true bool value,
so that it can be used in
_ = Debug && nstd.Logln(...)
Type Parameters:
S: ~[]E
E: any
MakeSlice makes a slice with the specified length.
Different from the built-in make function, the capacity
of the result slice might be larger than the length.
Type Parameters:
S: ~[]E
E: any
MakeSliceWithMinCap makes a slice with capacity not smaller than cap.
The length of the result slice is zero.
See: https://github.com/golang/go/issues/69872
Type Parameters:
T: any
Must panics if err is not nil; otherwise, the T value is returned.
See: https://github.com/golang/go/issues/58280
Type Parameters:
T1: any
T2: any
Must2 panics if err is not nil; otherwise, the T1 and T2 values are returned.
Type Parameters:
T: any
New allocates a T value and initialize it with the specified one.
Generally, Panicf(format, v...) is a short form of panic(fmt.Sprintf(format, v...)).
When format is blank, then it is a short form of panic(fmt.Sprint(v...)).
Printfln(format, a...) is a combintion of fmt.Printf(format, a...)
and fmt.Println().
Type Parameters:
Bytes: ~[]byte
ReverseBytes inverts the bytes in a byte slice.
The argument is returned so that calls to ReverseBytes can be used as expressions.
Type Parameters:
Seq: ByteSeq
ReverseByteSeq returnes a copy (in the form of byte slice) of
a byte sequence (in the form of either string or byte slice) but reversed.
Type Parameters:
Seq: ByteSeq
ReverseRuneSeq returnes a copy (in the form of byte slice) of
a rune sequence (in the form of either string or byte slice) but reversed.
See:
* https://github.com/golang/go/issues/14777
* https://github.com/golang/go/issues/68348
Type Parameters:
T: Signed
Sign returns the sign of a value of a [Signed] integer type.
For a negative integer, it returns -1;
for a positive integer, it returns 1;
for 0, it returns 0.
Type Parameters:
T: any
SliceFrom is used to create a slice from some values of the same type.
Some use scenarios:
1. Convert multiple results of a function call to a []any slice,
then use the slice in fmt.Printf alike functions.
2. Construct a []T slice from some T values without using the []T{...} form.
NOTE: SliceFrom(aSlice...) returns aSlice,
See: https://github.com/golang/go/issues/61213
Type Parameters:
T: any
Type returns a reflect.Type which represents type T,
which may be either an non-interface type or interface type.
Type Parameters:
T: any
TypeAssert asserts an interface value x to type T.
If the assertion succeeds, true is returned, othewise, false is returned.
If into is not nil, then the concrete value of x will be assigned to
the value referenced by into.
See: https://github.com/golang/go/issues/65846
Type Parameters:
T: any
TypeOf returns a reflect.Type which represents the type of v,
which may be either an non-interface value or interface value.
Type Parameters:
T: any
Value returns a reflect.Value which represents the value v,
which may be either an non-interface value or interface value.
WriteStringWithBuffer writes a string into an [io.Writer] with a provided buffer.
The buffer is used to avoid a string-> []byte conversion (which might allocate).
This function is like [io.CopyBuffer] but much simpler.
CheckWriteResult checks whether or not a Write method is badly implemented.
See:
* https://github.com/golang/go/issues/67921
* https://github.com/golang/go/issues/9096
Type Parameters:
T: any
Zero(p) zeros the value referenced by the pointer p.
Zero is useful for resetting values of some unexported types,
or resetting values of some other packages but without importing those packages.
Type Parameters:
M: ~map[K]E
K: comparable
E: any
BlankMap returns a blank map which has the same type as the input map.
* Usage 1: `ZeroMap[MapType](nil, 32)
* Usage 2: `ZeroMap(aMap, 8)
Type Parameters:
T: any
ZeroOf[T]() and ZeroOf(valueOfT) both return the zero value of type T.
The pages are generated with Golds v0.7.0-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |