Skip to content

Commit

Permalink
Merge pull request #13 from go-board/feat/deprecate_delegate
Browse files Browse the repository at this point in the history
[delegate] clean usage, remove pkg
  • Loading branch information
leaxoy authored Jun 12, 2022
2 parents 75aeded + 49048e4 commit 5fcd993
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 113 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ go get -u github.com/go-board/std
- [queue](https://github.com/go-board/std/blob/master/collections/queue) double ended queue
- [cond](https://github.com/go-board/std/blob/master/cond) conditional operator
- [core](https://github.com/go-board/std/blob/master/core) core types & constraints
- [~~delegate~~](https://github.com/go-board/std/blob/master/delegate) [DEPRECATED] delegate function signature
- [hash](https://github.com/go-board/std/blob/master/hash) hash a object
- [iterator](https://github.com/go-board/std/blob/master/iterator) iterators
- [adapters](https://github.com/go-board/std/blob/master/iterator/adapters) adapter to create iterators & streams
Expand Down
6 changes: 4 additions & 2 deletions algorithm/dp/dp.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package dp

import "github.com/go-board/std/delegate"
import (
"github.com/go-board/std/cmp"
)

func LcsBy[T any](left []T, right []T, eq delegate.Equal[T]) []T {
func LcsBy[T any](left []T, right []T, eq cmp.EqFunc[T]) []T {
if len(left) == 0 || len(right) == 0 {
return nil
}
Expand Down
6 changes: 1 addition & 5 deletions clone/clone.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package clone

import (
"github.com/go-board/std/delegate"
)

type Cloneable[T any] interface{ Clone() T }

func Clone[T Cloneable[T]](o T) T { return o.Clone() }

type Cloner[T any] delegate.Function1[T, T]
type Cloner[T any] func(T) T
5 changes: 2 additions & 3 deletions collections/btree/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package btree

import (
"github.com/go-board/std/clone"
"github.com/go-board/std/delegate"
"github.com/go-board/std/iterator"
"github.com/go-board/std/optional"
"github.com/go-board/std/tuple"
Expand All @@ -25,7 +24,7 @@ func (self MapEntry[K, V]) Value() V { return self.inner.Second() }

// TreeMap is a map based on a B-Tree.
type TreeMap[TKey, TValue any] struct {
less delegate.Lt[TKey]
less func(TKey, TKey) bool
inner *btree.Generic[MapEntry[TKey, TValue]]
}

Expand All @@ -35,7 +34,7 @@ var (
)

// NewTreeMap creates a new TreeMap.
func NewTreeMap[TKey, TValue any](less delegate.Lt[TKey]) *TreeMap[TKey, TValue] {
func NewTreeMap[TKey, TValue any](less func(TKey, TKey) bool) *TreeMap[TKey, TValue] {
entryLessFn := func(a, b MapEntry[TKey, TValue]) bool { return less(a.Key(), b.Key()) }
return &TreeMap[TKey, TValue]{inner: btree.NewGeneric(entryLessFn)}
}
Expand Down
3 changes: 1 addition & 2 deletions collections/btree/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package btree

import (
"github.com/go-board/std/clone"
"github.com/go-board/std/delegate"
"github.com/go-board/std/iterator"
"github.com/go-board/std/iterator/stream"
"github.com/go-board/std/optional"
Expand All @@ -20,7 +19,7 @@ var (
)

// NewTreeSet creates a new TreeSet.
func NewTreeSet[TElement any](less delegate.Lt[TElement]) *TreeSet[TElement] {
func NewTreeSet[TElement any](less func(TElement, TElement) bool) *TreeSet[TElement] {
return &TreeSet[TElement]{inner: btree.NewGeneric(less)}
}

Expand Down
5 changes: 2 additions & 3 deletions collections/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ package collections

import (
"github.com/go-board/std/collections/btree"
"github.com/go-board/std/delegate"
)

type TreeMap[TKey, TValue any] struct {
*btree.TreeMap[TKey, TValue]
}

func NewTreeMap[TKey, TValue any](less delegate.Lt[TKey]) *TreeMap[TKey, TValue] {
func NewTreeMap[TKey, TValue any](less func(TKey, TKey) bool) *TreeMap[TKey, TValue] {
return &TreeMap[TKey, TValue]{btree.NewTreeMap[TKey, TValue](less)}
}

type TreeSet[TElement any] struct {
*btree.TreeSet[TElement]
}

func NewTreeSet[TElement any](less delegate.Lt[TElement]) *TreeSet[TElement] {
func NewTreeSet[TElement any](less func(TElement, TElement) bool) *TreeSet[TElement] {
return &TreeSet[TElement]{btree.NewTreeSet(less)}
}
25 changes: 0 additions & 25 deletions delegate/comparison.go

This file was deleted.

22 changes: 0 additions & 22 deletions delegate/consumer.go

This file was deleted.

36 changes: 0 additions & 36 deletions delegate/function.go

This file was deleted.

4 changes: 0 additions & 4 deletions delegate/predicate.go

This file was deleted.

4 changes: 0 additions & 4 deletions delegate/transform.go

This file was deleted.

10 changes: 4 additions & 6 deletions lazy/lazy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ package lazy

import (
"sync"

"github.com/go-board/std/delegate"
)

// Lazy is a lazy value.
type Lazy[T any] struct {
compute func() T
}

func NewLazy[T any](compute func() T) *Lazy[T] { return &Lazy[T]{compute} }
func (self *Lazy[T]) Get() T { return self.compute() }
func (self *Lazy[T]) With(consumer delegate.Consumer1[T]) { consumer(self.Get()) }
func NewLazy[T any](compute func() T) *Lazy[T] { return &Lazy[T]{compute} }
func (self *Lazy[T]) Get() T { return self.compute() }
func (self *Lazy[T]) With(consumer func(T)) { consumer(self.Get()) }

// OnceLazy is a lazy value that is computed only once.
type OnceLazy[T any] struct {
Expand All @@ -31,6 +29,6 @@ func (self *OnceLazy[T]) Get() T {
return self.inner
}

func (self *OnceLazy[T]) With(consumer delegate.Consumer1[T]) {
func (self *OnceLazy[T]) With(consumer func(T)) {
consumer(self.Get())
}

0 comments on commit 5fcd993

Please sign in to comment.