package nstd// 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.func [ ~[], any]( int) {returnappend((nil), make(, )...)}// 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/69872func [ ~[], any]( int) {returnappend((nil), make(, )...)[:0]}// 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)func [ ~map[], comparable, any]( , int) {returnmake(, )}// 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/68261func [ comparable, any]( map[]) [] {iflen() == 0 {returnnil }var = make([], 0, len())for := range { = append(, ) }return}// AppendMapKeys appends all the keys in a map into the specified slice.func [ comparable, any]( [], map[]) [] {for := range { = append(, ) }return}
The pages are generated with Goldsv0.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.