From 1f61c28a5d33a6d92609319ab10fc1fcca3089a6 Mon Sep 17 00:00:00 2001 From: b97tsk Date: Mon, 12 Aug 2024 08:00:00 +0800 Subject: [PATCH] drop dependency on golang.org/x/exp/constraints --- constraints.go | 6 ++++++ go.mod | 2 -- go.sum | 2 -- pair.go | 4 +--- range.go | 6 ++---- 5 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 constraints.go delete mode 100644 go.sum diff --git a/constraints.go b/constraints.go new file mode 100644 index 00000000..9db6f839 --- /dev/null +++ b/constraints.go @@ -0,0 +1,6 @@ +package rx + +// Integer is a constraint that permits any integer type. +type Integer interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr +} diff --git a/go.mod b/go.mod index 829b29e5..928f0e8f 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,4 @@ module github.com/b97tsk/rx go 1.22.0 -require golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 - retract [v0.0.1, v0.9.0] diff --git a/go.sum b/go.sum deleted file mode 100644 index dcd770d4..00000000 --- a/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY= -golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI= diff --git a/pair.go b/pair.go index 04f76a0e..6527cd04 100644 --- a/pair.go +++ b/pair.go @@ -1,7 +1,5 @@ package rx -import "golang.org/x/exp/constraints" - // A Pair is a struct of two elements. type Pair[K, V any] struct { Key K @@ -97,7 +95,7 @@ func RightOf[_ Pair[K, V], K, V any]() Operator[Pair[K, V], V] { // Enumerate maps each value emitted by the source [Observable] to a [Pair] // where the Key field stores the index of each value starting from init // and the Value field stores each value. -func Enumerate[V any, K constraints.Integer](init K) Operator[V, Pair[K, V]] { +func Enumerate[V any, K Integer](init K) Operator[V, Pair[K, V]] { return NewOperator( func(source Observable[V]) Observable[Pair[K, V]] { return func(c Context, o Observer[Pair[K, V]]) { diff --git a/range.go b/range.go index 958b733d..458e666b 100644 --- a/range.go +++ b/range.go @@ -1,10 +1,8 @@ package rx -import "golang.org/x/exp/constraints" - // Range creates an [Observable] that emits a sequence of integers // within a specified range. -func Range[T constraints.Integer](low, high T) Observable[T] { +func Range[T Integer](low, high T) Observable[T] { return func(c Context, o Observer[T]) { done := c.Done() @@ -25,7 +23,7 @@ func Range[T constraints.Integer](low, high T) Observable[T] { // Iota creates an [Observable] that emits an infinite sequence of integers // starting from init. -func Iota[T constraints.Integer](init T) Observable[T] { +func Iota[T Integer](init T) Observable[T] { return func(c Context, o Observer[T]) { done := c.Done()