@ -33,6 +33,7 @@ Implementation of various data structures and algorithms in Go.
- [EnumerableWithKey](#enumerablewithkey)
- [EnumerableWithKey](#enumerablewithkey)
- [Sort](#sort)
- [Sort](#sort)
- [Container](#container)
- [Container](#container)
- [Appendix](#appendix)
## Containers
## Containers
@ -48,9 +49,9 @@ type Container interface {
}
}
```
```
Containers are either ordered or unordered. All ordered containers provide [stateful iterators](iterator) and some of them allow [enumerable functions](#enumerable).
Containers are either ordered or unordered. All ordered containers provide [stateful iterators](#iterator) and some of them allow [enumerable functions](#enumerable).
All ordered containers have stateful iterators. Typically an iterator is obtained by _Iterator()_ function of an ordered container. Once obtained, iterator's _Next()_ function moves the iterator to the next element and returns true if there was a next element. If there was an element, then element's can be obtained by iterator's _Value()_ function. Depending on the ordering type, it's position can be obtained by iterator's _Index()_ or _Key()_ functions. '
All ordered containers have stateful iterators. Typically an iterator is obtained by _Iterator()_ function of an ordered container. Once obtained, iterator's _Next()_ function moves the iterator to the next element and returns true if there was a next element. If there was an element, then element's can be obtained by iterator's _Value()_ function. Depending on the ordering type, it's position can be obtained by iterator's _Index()_ or _Key()_ functions.
#### IteratorWithIndex
#### IteratorWithIndex
@ -673,68 +674,92 @@ Enumerable functions for ordered containers that implement [EnumerableWithIndex]
#### EnumerableWithIndex
#### EnumerableWithIndex
Enumerable function for ordered containers whose values can be fetched by an index.
[Enumerable](#enumerable) functions for ordered containers whose values can be fetched by an index.
Definition:
**Each**: Calls the given function once for each element, passing that element's index and value.
```go
```go
type EnumerableWithIndex interface {
Each(func(index int, value interface{}))
// Calls the given function once for each element, passing that element's index and value.
```
Each(func(index int, value interface{}))
// Invokes the given function once for each element and returns a
**Map**: Invokes the given function once for each element and returns a container containing the values returned by the given function.
// container containing the values returned by the given function.
Map(func(index int, value interface{}) interface{}) Container
// Returns a new container containing all elements for which the given function returns a true value.
```go
Select(func(index int, value interface{}) bool) Container
Map(func(index int, value interface{}) interface{}) Container
```
// Passes each element of the container to the given function and
**Select**: Returns a new container containing all elements for which the given function returns a true value.
// returns true if the function ever returns true for any element.
Any(func(index int, value interface{}) bool) bool
// Passes each element of the container to the given function and
```go
// returns true if the function returns true for all elements.
Select(func(index int, value interface{}) bool) Container
All(func(index int, value interface{}) bool) bool
```
// Passes each element of the container to the given function and returns
**Any**: Passes each element of the container to the given function and returns true if the function ever returns true for any element.
// the first (index,value) for which the function is true or -1,nil otherwise
// if no element matches the criteria.
```go
Find(func(index int, value interface{}) bool) (int, interface{})
Any(func(index int, value interface{}) bool) bool
}
```
**All**: Passes each element of the container to the given function and returns true if the function returns true for all elements.
```go
All(func(index int, value interface{}) bool) bool
```
**Find**: Passes each element of the container to the given function and returns the first (index,value) for which the function is true or -1,nil otherwise if no element matches the criteria.
```go
Find(func(index int, value interface{}) bool) (int, interface{})}
```
Typical usage:
```go
TODO
```
```
#### EnumerableWithKey
#### EnumerableWithKey
Enumerable functions for ordered containers whose values whose elements are key/value pairs.
Enumerable functions for ordered containers whose values whose elements are key/value pairs.
Definition:
**Each**: Calls the given function once for each element, passing that element's key and value.
```go
Each(func(key interface{}, value interface{}))
```
**Map**: Invokes the given function once for each element and returns a container containing the values returned by the given function as key/value pairs.
```go
Map(func(key interface{}, value interface{}) (interface{}, interface{})) Container
```
**Select**: Returns a new container containing all elements for which the given function returns a true value.
```go
```go
type EnumerableWithKey interface {
Select(func(key interface{}, value interface{}) bool) Container
// Calls the given function once for each element, passing that element's key and value.
```
Each(func(key interface{}, value interface{}))
**Any**: Passes each element of the container to the given function and returns true if the function ever returns true for any element.
// Invokes the given function once for each element and returns a container
```go
// containing the values returned by the given function as key/value pairs.
Any(func(key interface{}, value interface{}) bool) bool
Map(func(key interface{}, value interface{}) (interface{}, interface{})) Container
```
// Returns a new container containing all elements for which the given function returns a true value.
**All**: Passes each element of the container to the given function and returns true if the function returns true for all elements.
Select(func(key interface{}, value interface{}) bool) Container
// Passes each element of the container to the given function and
```go
// returns true if the function ever returns true for any element.
All(func(key interface{}, value interface{}) bool) bool
Any(func(key interface{}, value interface{}) bool) bool
```
// Passes each element of the container to the given function and
**Find**: Passes each element of the container to the given function and returns the first (key,value) for which the function is true or nil,nil otherwise if no element matches the criteria.
// returns true if the function returns true for all elements.
All(func(key interface{}, value interface{}) bool) bool
// Passes each element of the container to the given function and returns
```go
// the first (key,value) for which the function is true or nil,nil otherwise if no element
Find(func(key interface{}, value interface{}) bool) (interface{}, interface{})
// matches the criteria.
```
Find(func(key interface{}, value interface{}) bool) (interface{}, interface{})