This commit is contained in:
Andrey Parhomenko 2022-11-25 18:30:51 +05:00
commit 0a277876bb
6 changed files with 67 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
exe

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module github.com/surdeus/godat
go 1.19

5
mkconfig Normal file
View file

@ -0,0 +1,5 @@
MKSHELL = sh
<$(MKINCDIR)/config
WATCH_FILES = src tmpl
CC = cc

5
mkfile Normal file
View file

@ -0,0 +1,5 @@
<mkconfig
<$MKINCDIR/gobuild
<$MKINCDIR/w3/run-dev

24
src/cmd/test/main.go Normal file
View file

@ -0,0 +1,24 @@
package main
import (
"github.com/surdeus/godat/src/mapx"
"fmt"
)
func main() {
m := map[string] string {
"Key1" : "Value1",
"Key2" : "Value2",
"Key3" : "Value3",
}
m1 := map[int] string {
1 : "Val1",
2 : "Val2",
7 : "Val7",
}
fmt.Println(m)
fmt.Printf("%q\n", mapx.Keys(m))
fmt.Printf("%q\n", mapx.Values(m))
fmt.Printf("%q\n", mapx.Reverse(m))
fmt.Printf("%v\n", mapx.Reverse(m1))
}

29
src/mapx/main.go Normal file
View file

@ -0,0 +1,29 @@
package mapx
func Keys[K comparable, V any](m map[K] V) []K {
r := make([]K, 0, len(m))
for k := range m {
r = append(r, k)
}
return r
}
func Values[K comparable, V any](m map[K] V) []V {
r := make([]V, 0, len(m))
for _, v := range m {
r = append(r, v)
}
return r
}
func Reverse[K, V comparable](m map[K] V) map[V] K {
r := make(map[V] K)
for k, v := range m {
r[v] = k
}
return r
}