New Upstream Release - golang-github-juju-collections
Ready changes
Summary
Merged new upstream version: 1.0.2 (was: 1.0.1).
Diff
diff --git a/debian/changelog b/debian/changelog
index 89b5f9c..e92301f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+golang-github-juju-collections (1.0.2-1) UNRELEASED; urgency=low
+
+ * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk> Sun, 26 Feb 2023 08:52:57 -0000
+
golang-github-juju-collections (1.0.1-1) unstable; urgency=medium
* New upstream release
diff --git a/transform/package_test.go b/transform/package_test.go
new file mode 100644
index 0000000..36e23c6
--- /dev/null
+++ b/transform/package_test.go
@@ -0,0 +1,14 @@
+// Copyright 2023 Canonical Ltd.
+// Licensed under the LGPLv3, see LICENCE file for details.
+
+package transform
+
+import (
+ "testing"
+
+ gc "gopkg.in/check.v1"
+)
+
+func TestPackage(t *testing.T) {
+ gc.TestingT(t)
+}
diff --git a/transform/slice.go b/transform/slice.go
index eac42d7..7402629 100644
--- a/transform/slice.go
+++ b/transform/slice.go
@@ -12,3 +12,15 @@ func Slice[F any, T any](from []F, transform func(F) T) []T {
}
return to
}
+
+// SliceToMap transforms a slice of one type to an equal length
+// map with values from the slice, keyed by values indicated by
+// the input transformation function.
+func SliceToMap[F any, K comparable, V any](from []F, transform func(F) (K, V)) map[K]V {
+ to := make(map[K]V, len(from))
+ for _, oneFrom := range from {
+ k, v := transform(oneFrom)
+ to[k] = v
+ }
+ return to
+}
diff --git a/transform/slice_test.go b/transform/slice_test.go
index a557297..2127854 100644
--- a/transform/slice_test.go
+++ b/transform/slice_test.go
@@ -15,7 +15,7 @@ type sliceSuite struct {
var _ = gc.Suite(sliceSuite{})
-func (sliceSuite) TestSimpleTransformation(c *gc.C) {
+func (sliceSuite) TestSliceTransformation(c *gc.C) {
type this struct {
number int
}
@@ -38,3 +38,27 @@ func (sliceSuite) TestSimpleTransformation(c *gc.C) {
c.Assert(transform.Slice(from, thisToThat), gc.DeepEquals, to)
}
+
+func (sliceSuite) TestSliceToMapTransformation(c *gc.C) {
+ type this struct {
+ number int
+ }
+
+ type that struct {
+ numero int
+ }
+
+ from := []this{
+ {number: 1},
+ {number: 2},
+ }
+
+ thisToThat := func(from this) (int, that) { return from.number, that{numero: from.number} }
+
+ to := map[int]that{
+ 1: {numero: 1},
+ 2: {numero: 2},
+ }
+
+ c.Assert(transform.SliceToMap(from, thisToThat), gc.DeepEquals, to)
+}
More details
Historical runs
- failed: src/github.com/juju/collections/transform/slice.go:8:11: error: expected ‘(’
- push-failed: Failed to push result branch: Connection closed: Connection closed early The remote server unexpectedly closed the connection.
- run-disappeared: Worker started processing new run rather than fc695dd5-c0b6-4591-b380-183026b6a7e2
- nothing-to-do: Last upstream version 0.0~git20220203.febd7ca already imported.
- nothing-to-do: Last upstream version 0.0~git20220203.febd7ca already imported.
- nothing-to-do: Last upstream version 0.0~git20220203.febd7ca already imported.
- build-failed-stage-explain-bd-uninstallable: build failed stage explain-bd-uninstallable
- worker-timeout: No keepalives received in 10:00:10.145294.