Skip to content

Commit

Permalink
Merge pull request #11 from lxzan/dev
Browse files Browse the repository at this point in the history
simplify vector
  • Loading branch information
lxzan committed Jan 16, 2024
2 parents f769d89 + 85a127b commit 5873fab
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 266 deletions.
17 changes: 17 additions & 0 deletions types/maps/maps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package maps

func Keys[K comparable, V any](m map[K]V) []K {
var keys = make([]K, 0, len(m))
for k, _ := range m {
keys = append(keys, k)
}
return keys
}

func Values[K comparable, V any](m map[K]V) []V {
var values = make([]V, 0, len(m))
for _, v := range m {
values = append(values, v)
}
return values
}
38 changes: 38 additions & 0 deletions types/maps/maps_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package maps

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestKeys(t *testing.T) {
t.Run("", func(t *testing.T) {
var m = map[string]any{
"a": 1,
"b": 1,
"c": 1,
}
assert.ElementsMatch(t, Keys(m), []string{"a", "b", "c"})
})

t.Run("", func(t *testing.T) {
type Map map[string]any
var m = Map{
"a": 1,
"b": 1,
"c": 1,
}
assert.ElementsMatch(t, Keys(m), []string{"a", "b", "c"})
})
}

func TestValues(t *testing.T) {
t.Run("", func(t *testing.T) {
var m = map[string]any{
"a": 1,
"b": 2,
"c": 3,
}
assert.ElementsMatch(t, Values(m), []int{1, 2, 3})
})
}
55 changes: 0 additions & 55 deletions vector/types.go

This file was deleted.

Loading

0 comments on commit 5873fab

Please sign in to comment.