Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
cde2c1e7
Commit
cde2c1e7
authored
1 year ago
by
Pavel Antonov
Browse files
Options
Downloads
Patches
Plain Diff
Fix SliceToMap function
parent
7e3569b1
Branches
feature/PRXS-2648-LocalizedSync
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/data/list.go
+3
-3
3 additions, 3 deletions
pkg/data/list.go
pkg/data/list_test.go
+15
-0
15 additions, 0 deletions
pkg/data/list_test.go
with
18 additions
and
3 deletions
pkg/data/list.go
+
3
−
3
View file @
cde2c1e7
...
...
@@ -193,12 +193,12 @@ func CloneSlice[T interface{ Clone() T }](s []T) []T {
return
result
}
type
Keyed
[
T
any
]
interface
{
type
Keyed
[
T
comparable
]
interface
{
Key
()
T
}
func
SliceToMap
[
T
Keyed
[
any
]](
s
[]
T
)
map
[
any
]
T
{
res
:=
make
(
map
[
any
]
T
,
len
(
s
))
func
SliceToMap
[
K
comparable
,
T
Keyed
[
K
]](
s
[]
T
)
map
[
K
]
T
{
res
:=
make
(
map
[
K
]
T
,
len
(
s
))
for
_
,
elem
:=
range
s
{
res
[
elem
.
Key
()]
=
elem
}
...
...
This diff is collapsed.
Click to expand it.
pkg/data/list_test.go
+
15
−
0
View file @
cde2c1e7
...
...
@@ -139,3 +139,18 @@ keyB2: val20
})
}
}
type
KV
struct
{
K
string
V
string
}
func
(
kv
*
KV
)
Key
()
string
{
return
kv
.
K
}
func
TestSliceToMap
(
t
*
testing
.
T
)
{
s
:=
[]
*
KV
{{
"a"
,
"1"
},
{
"b"
,
"2"
},
{
"c"
,
"3"
}}
m
:=
SliceToMap
(
s
)
assert
.
Equal
(
t
,
map
[
string
]
*
KV
{
"a"
:
{
"a"
,
"1"
},
"b"
:
{
"b"
,
"2"
},
"c"
:
{
"c"
,
"3"
}},
m
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment