Documentation ¶
Overview ¶
c3 stands for common containers collection and provides a few simple to use containers.
The containers provided:
- Iterable: a container that allow iterating over its items.
- Bag: an unordered container that allows duplicate items.
- Set: an unordered container that does not allow duplicate items.
- List: an indexable container.
- Queue: a fifo container.
- Stack: a lifo container.
It also provides a query api for those containers that looks like C#'s Linq
The code lives at http://github.com/ReSc/c3#c3
You can find the CI builds at http://travis-ci.org/ReSc/c3
The api documentation can be found at http://godoc.org/github.com/ReSc/c3
Index ¶
- func For(c Iterable, action Action)
- func Go(c Iterable, action Action)
- func GoBuffered(c Iterable, bufferSize int, action Action)
- func Sort(l List, lesser Lesser)
- func ToSlice(c Iterable) []interface{}
- type Action
- type Aggregator
- type Bag
- type Clearer
- type Consumable
- type Consume
- type Consumer
- type Generate
- type Generator
- type Indexable
- type Iterable
- type Iterator
- type Lesser
- type List
- type ManySelector
- type Peeker
- type Predicate
- type Q
- func (q *Q) Aggregate(aggregate interface{}, action Aggregator) interface{}
- func (q *Q) All(predicate Predicate) bool
- func (q *Q) Any() bool
- func (q *Q) Append(items ...interface{}) *Q
- func (q *Q) Concat(items Iterable) *Q
- func (q *Q) Contains(item interface{}) bool
- func (q *Q) Count() int
- func (q *Q) Distinct() *Q
- func (q *Q) First() (interface{}, bool)
- func (q *Q) For(action Action)
- func (q *Q) Go(action Action)
- func (q *Q) GoBuffered(bufferSize int, action Action)
- func (q *Q) Iterator() Iterator
- func (q *Q) Last() (interface{}, bool)
- func (q *Q) Prepend(items ...interface{}) *Q
- func (q *Q) Run()
- func (q *Q) Select(selector Selector) *Q
- func (q *Q) SelectMany(selector ManySelector) *Q
- func (q *Q) Shuffle() *Q
- func (q *Q) Skip(count int) *Q
- func (q *Q) Sort(lesser Lesser) *Q
- func (q *Q) Take(count int) *Q
- func (q *Q) Tee(action Action) *Q
- func (q *Q) ToBag() Bag
- func (q *Q) ToList() List
- func (q *Q) ToQueue() Queue
- func (q *Q) ToReadOnlyBag() ReadOnlyBag
- func (q *Q) ToReadOnlyList() ReadOnlyList
- func (q *Q) ToSet() Set
- func (q *Q) ToSlice() []interface{}
- func (q *Q) ToStack() Stack
- func (q *Q) Where(filter Predicate) *Q
- type Queue
- type ReadOnlyBag
- type ReadOnlyList
- type Selector
- type Set
- type Sorter
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Go ¶
Go applies the action to each item in the Iterable on a separate goroutine using an unbuffered channel
func GoBuffered ¶
GoBuffered applies the action to each item in the Iterable on a separate goroutine using a buffered channel
Types ¶
type Action ¶
type Action func(item interface{})
Action is invoked for every item in the query result.
type Aggregator ¶
type Aggregator func(item interface{}, aggregate interface{}) (aggregateResult interface{})
Aggregator converts an item and an aggregate into an aggregate result
type Bag ¶
type Bag interface { Clearer ReadOnlyBag // Add adds an item to the container, // returns true if the container was modified, // false if it was not modified Add(item interface{}) bool // Delete removes an item from the container, // returns true if the container was modified, // false if it was not modified Delete(item interface{}) bool }
Bag is an unordered mutable container
type Clearer ¶
type Clearer interface {
// Clear removes all items from the container.
Clear()
}
Clearer provides a method to clear the container.
type Consumable ¶
type Consumable interface {
Consumer() Consumer
}
Consumable is a container that provides a consuming iterator.
type Consume ¶
type Consume func() (interface{}, bool)
Consume removes and returns the next item in a sequence. Returns the next item and true or nil and false if there are no more items.
type Consumer ¶
type Consumer interface { Iterator }
Consumer is an Iterator that removes items from a container.
func WrapConsumer ¶
func WrapConsumer(c <-chan interface{}) Consumer
WrapConsumer wraps a channel in a consuming Iterator
type Generate ¶
type Generate func() (interface{}, bool)
Generate computes the next item in a sequence. Returns the next item and true or nil and false if there are no more items.
func MakeGenerate ¶
MakeGenerate converts the Iterator into a Generate function.
type Generator ¶
type Generator func() Generate
Generator creates a new Generate function
func MakeGenerator ¶
MakeGenerator converts the Iterable into a Generator function.
type Indexable ¶
type Indexable interface { // Returns the first item and true, // or nil and false if there is no first item First() (interface{}, bool) // Returns the item at the index and true, // or nil and false if the index is out of bounds Get(index int) (interface{}, bool) // Returns the last item and true, // or nil and false if there is no last item Last() (interface{}, bool) // Returns the first index of the item and true, // or -1 and false if there is no such item IndexOf(item interface{}) (int, bool) // Returns the index of the next item before the offset and true, // or -1 and false if there is no such item PrevIndexOf(offset int, item interface{}) (int, bool) // Returns the index of the next item after the offset and true, // or -1 and false if there is no such item NextIndexOf(offset int, item interface{}) (int, bool) // Returns the last index of the item and true, // or -1 and false if there is no such item LastIndexOf(item interface{}) (int, bool) }
Indexable provides methods to get items from a container by index
type Iterable ¶
type Iterable interface { // returns a new Iterator positioned at the start of the container. Iterator() Iterator }
Iterable is a container of items that can be iterated over.
func EmptyIterable ¶
func EmptyIterable() Iterable
func IterableOf ¶
func IterableOf(items ...interface{}) Iterable
IterableOf creates an Iterable with the given items.
func MakeIterable ¶
MakeIterable converts the Generator function into an Iterable.
type Iterator ¶
type Iterator interface { // Move the iterator to the next item, returns true on succes // or false if the are no more item MoveNext() bool // returns the value at the current iterator position, or nil Value() interface{} }
Iterator provides a way to iterate over a container
Usage:
for i := iterable.Iterator(); i.MoveNext(); { value := i.Value() }
Iterator.Value() only return a valid value if the preceding call to Iterator.MoveNext() returned true
func EmptyIterator ¶
func EmptyIterator() Iterator
func IteratorOf ¶
func IteratorOf(items ...interface{}) Iterator
IteratorOf creates an Iterator with the given items.
func MakeIterator ¶
MakeIterator converts the Generate function into an Iterator.
type Lesser ¶
type Lesser func(a, b interface{}) bool
Lesser compares 2 items, such that a<b:true, false otherwise
type List ¶
type List interface { Bag Indexable // Inserts the item at the given index, // returns true if the container was modified, // false if it was not modified. InsertAt(index int, item interface{}) bool // Swaps the 2 items at the given indexes Swap(i, j int) // Deletes the item at the given index, // returns true if the container was modified, // false if it was not modified. DeleteAt(index int) bool }
type ManySelector ¶
type ManySelector func(interface{}) Iterable
ManySelector converts 1 item into zero or more items
type Peeker ¶
type Peeker interface { // Peek returns the next item without removing it from the container. Peek() (interface{}, bool) }
Peeker provides a method to look at the next item without removing it from the container.
type Predicate ¶
type Predicate func(item interface{}) bool
Predicate if a function that returns true if the predicate holds for the item.
type Q ¶
type Q struct {
// contains filtered or unexported fields
}
The c3 query representation
func NewQuery ¶
NewQuery provides a entry point to the c3 query api.
Usage:
list := c3.ListOf(1,2,3) q := NewQuery(list). Where(/* filter function here */). Select( /* selector function here */). ToList() /* collect the results */
func QueryOf ¶
func QueryOf(items ...interface{}) *Q
QueryOf provides a entry point to the c3 query api.
Usage:
q := c3.QueryOf(1,2,3). Where(/* filter function here */). Select( /* selector function here */). ToList() /* collect the results */
func (*Q) Aggregate ¶
func (q *Q) Aggregate(aggregate interface{}, action Aggregator) interface{}
Aggregate applies the action to every item in the query result and combines them in a single result.
func (*Q) First ¶
First returns the first query result and true, or nil and false if there are no results.
func (*Q) Go ¶
Go applies the action to every item in the query result on a seperate goroutine using an unbuffered channel.
func (*Q) GoBuffered ¶
Go applies the action to every item in the query result on a seperate goroutine using a buffered channel of the supplied size.
func (*Q) Last ¶
Last returns the last query result and true, or nil and false if there are no results.
func (*Q) SelectMany ¶
func (q *Q) SelectMany(selector ManySelector) *Q
SelectMany uses the selector to create an Iteratable containing zero or more items for each item, and concatenates all the results.
func (*Q) Skip ¶
Skip skips the first count results and returns all results after that. If there are less results Skip returns an empty result set.
func (*Q) Take ¶
Take truncates the results after count results have been computed. If there are less results Take returns only the available results.
func (*Q) Tee ¶
Tee applies the action to every item in the query result and passes every result on to the next query operator.
func (*Q) ToReadOnlyBag ¶
func (q *Q) ToReadOnlyBag() ReadOnlyBag
ToReadOnlyList puts the query results in a new ReadOnlyList
func (*Q) ToReadOnlyList ¶
func (q *Q) ToReadOnlyList() ReadOnlyList
ToReadOnlyList puts the query results in a new ReadOnlyList
func (*Q) ToSlice ¶
func (q *Q) ToSlice() []interface{}
ToSlice puts the query results in a new slice
type Queue ¶
type Queue interface { ReadOnlyBag Peeker Clearer Consumable // Appends an item at the tail of the queue, // returns true if the queue was modified, // false if it was not modified. Enqueue(item interface{}) bool // Removes an item from the head of the queue, // returns the item and true if the queue was modified, // or nil and false if it was not modified. Dequeue() (interface{}, bool) }
A simple queuing container.
type ReadOnlyBag ¶
type ReadOnlyBag interface { Iterable // Returns the item count Len() int // Returns true if the item is in the container, false otherwise. Contains(item interface{}) bool }
ReadOnlyBag provides a length and a test for determining if an item is present in a container
func ReadOnlyBagOf ¶
func ReadOnlyBagOf(items ...interface{}) ReadOnlyBag
ReadOnlyBagOf creates a ReadOnlyBag with the given items.
func ToReadOnlyBag ¶
func ToReadOnlyBag(c Iterable) ReadOnlyBag
ToReadOnlyBag creates a new ReadOnlyBag of the items in an Iterable
type ReadOnlyList ¶
type ReadOnlyList interface { ReadOnlyBag Indexable }
ReadOnlyList is an indexable readonly list
func ReadOnlyListOf ¶
func ReadOnlyListOf(items ...interface{}) ReadOnlyList
ReadOnlyListOf creates a ReadOnlyList with the given items.
func ToReadOnlyList ¶
func ToReadOnlyList(c Iterable) ReadOnlyList
ToReadOnlyList creates a new ReadOnlyList of the items in an Iterable
type Selector ¶
type Selector func(item interface{}) interface{}
Selector converts an item into another item
type Set ¶
type Set interface { Bag // Union computes the union of the set. // i.e. all items in this set and the other set, without duplicates Union(other Set) Set // SymmetricDifference computes the symmetric difference of the sets. // i.e. all the items that are either in this set, // or in the other set, but not in both. SymmetricDifference(other Set) Set // Difference computes the items that are in this set but not in the other set. Difference(other Set) Set // Intersection computes the items that are present in both sets. Intersection(other Set) Set }
A set type with basic set operations. See also http://en.wikipedia.org/wiki/Set_theory
type Stack ¶
type Stack interface { ReadOnlyBag Peeker Clearer Consumable // Adds an item at the top of the stack, // returns true if the stack was modified, // false if it was not modified. Push(item interface{}) bool // Removes an item from the top of the stack, // returns the item and true if the stack was modified, // nil and false if it was not modified. Pop() (interface{}, bool) }
A simple stack container
Source Files ¶
- c3.go
- constructors.go
- consumers.go
- generateIterator.go
- generatorIterable.go
- list.go
- listIterator.go
- queries.go
- queue.go
- queueConsumer.go
- queueIterator.go
- selectIterable.go
- selectIterator.go
- selectManyIterable.go
- selectManyIterator.go
- set.go
- sorter.go
- stack.go
- stackConsumer.go
- stackIterator.go
- utils.go
- whereIterable.go
- whereIterator.go
- wrappers.go