1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-17 03:02:28 +08:00

fix: fix goline error

This commit is contained in:
dudaodong
2023-03-01 11:10:12 +08:00
parent 66efe61834
commit 081908bce3
6 changed files with 31 additions and 20 deletions

View File

@@ -347,7 +347,7 @@ func DeepClone[T any](src T) T {
func CopyProperties[T, U any](dst T, src U) (err error) { func CopyProperties[T, U any](dst T, src U) (err error) {
defer func() { defer func() {
if e := recover(); e != nil { if e := recover(); e != nil {
err = errors.New(fmt.Sprintf("%v", e)) err = fmt.Errorf("%v", e)
} }
}() }()

View File

@@ -260,7 +260,7 @@ func ExampleDeepClone() {
Float float64 Float float64
Bool bool Bool bool
Nil interface{} Nil interface{}
unexported string // unexported string
} }
cases := []interface{}{ cases := []interface{}{
@@ -323,12 +323,18 @@ func ExampleCopyProperties() {
user := User{Name: "user001", Age: 10, Role: "Admin", Addr: Address{Country: "CN", ZipCode: "001"}, Hobbys: []string{"a", "b"}, salary: 1000} user := User{Name: "user001", Age: 10, Role: "Admin", Addr: Address{Country: "CN", ZipCode: "001"}, Hobbys: []string{"a", "b"}, salary: 1000}
employee1 := Employee{} employee1 := Employee{}
CopyProperties(&employee1, &user) err := CopyProperties(&employee1, &user)
if err != nil {
return
}
employee2 := Employee{Name: "employee001", Age: 20, Role: "User", employee2 := Employee{Name: "employee001", Age: 20, Role: "User",
Addr: Address{Country: "UK", ZipCode: "002"}, salary: 500} Addr: Address{Country: "UK", ZipCode: "002"}, salary: 500}
CopyProperties(&employee2, &user) err = CopyProperties(&employee2, &user)
if err != nil {
return
}
fmt.Println(employee1) fmt.Println(employee1)
fmt.Println(employee2) fmt.Println(employee2)

View File

@@ -264,7 +264,7 @@ func TestDeepClone(t *testing.T) {
Float float64 Float float64
Bool bool Bool bool
Nil interface{} Nil interface{}
unexported string // unexported string
} }
cases := []interface{}{ cases := []interface{}{

View File

@@ -19,11 +19,15 @@ func ExampleContext() {
return errors.New("error occurs") return errors.New("error occurs")
} }
Retry(increaseNumber, err := Retry(increaseNumber,
RetryDuration(time.Microsecond*50), RetryDuration(time.Microsecond*50),
Context(ctx), Context(ctx),
) )
if err != nil {
return
}
fmt.Println(number) fmt.Println(number)
// Output: // Output:

View File

@@ -64,6 +64,7 @@ func Generate[T any](generator func() func() (item T, ok bool)) stream[T] {
var zeroValue T var zeroValue T
for next, item, ok := generator(), zeroValue, true; ok; { for next, item, ok := generator(), zeroValue, true; ok; {
item, ok = next() item, ok = next()
if ok { if ok {
source = append(source, item) source = append(source, item)
@@ -98,7 +99,7 @@ func FromRange[T constraints.Integer | constraints.Float](start, end, step T) st
} }
l := int((end-start)/step) + 1 l := int((end-start)/step) + 1
source := make([]T, l, l) source := make([]T, l)
for i := 0; i < l; i++ { for i := 0; i < l; i++ {
source[i] = start + (T(i) * step) source[i] = start + (T(i) * step)
@@ -160,7 +161,7 @@ func (s stream[T]) Filter(predicate func(item T) bool) stream[T] {
// Map returns a stream consisting of the elements of this stream that apply the given function to elements of stream. // Map returns a stream consisting of the elements of this stream that apply the given function to elements of stream.
func (s stream[T]) Map(mapper func(item T) T) stream[T] { func (s stream[T]) Map(mapper func(item T) T) stream[T] {
source := make([]T, s.Count(), s.Count()) source := make([]T, s.Count())
for i, v := range s.source { for i, v := range s.source {
source[i] = mapper(v) source[i] = mapper(v)