Skip to content

Commit

Permalink
Godoc cosmetics fixes (#50)
Browse files Browse the repository at this point in the history
- Collected ".. is of a type" in bullet lists
- Added trailing periods in godocs
- Wrapped godoc comments to a consistent length
- Moved NOTE blocks to the end.

Signed-off-by: Ahmet Alp Balkan <[email protected]>
  • Loading branch information
ahmetb authored Jan 3, 2017
1 parent 397245e commit 873aaae
Show file tree
Hide file tree
Showing 21 changed files with 301 additions and 315 deletions.
63 changes: 33 additions & 30 deletions aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package linq

// Aggregate applies an accumulator function over a sequence.
//
// Aggregate method makes it simple to perform a calculation over a sequence of values.
// This method works by calling f() one time for each element in source
// except the first one. Each time f() is called, Aggregate passes both
// the element from the sequence and an aggregated value (as the first argument to f()).
// The first element of source is used as the initial aggregate value.
// The result of f() replaces the previous aggregated value.
// Aggregate method makes it simple to perform a calculation over a sequence of
// values. This method works by calling f() one time for each element in source
// except the first one. Each time f() is called, Aggregate passes both the
// element from the sequence and an aggregated value (as the first argument to
// f()). The first element of source is used as the initial aggregate value. The
// result of f() replaces the previous aggregated value.
//
// Aggregate returns the final result of f().
func (q Query) Aggregate(
Expand All @@ -28,9 +28,9 @@ func (q Query) Aggregate(

// AggregateT is the typed version of Aggregate.
//
// NOTE: Aggregate method has better performance than AggregateT
// - f is of type: func(TSource, TSource) TSource
//
// f is of type: func(TSource, TSource) TSource
// NOTE: Aggregate has better performance than AggregateT.
func (q Query) AggregateT(f interface{}) interface{} {

fGenericFunc, err := newGenericFunc(
Expand All @@ -48,14 +48,14 @@ func (q Query) AggregateT(f interface{}) interface{} {
return q.Aggregate(fFunc)
}

// AggregateWithSeed applies an accumulator function over a sequence.
// The specified seed value is used as the initial accumulator value.
// AggregateWithSeed applies an accumulator function over a sequence. The
// specified seed value is used as the initial accumulator value.
//
// Aggregate method makes it simple to perform a calculation over a sequence of values.
// This method works by calling f() one time for each element in source
// except the first one. Each time f() is called, Aggregate passes both
// the element from the sequence and an aggregated value (as the first argument to f()).
// The value of the seed parameter is used as the initial aggregate value.
// Aggregate method makes it simple to perform a calculation over a sequence of
// values. This method works by calling f() one time for each element in source
// except the first one. Each time f() is called, Aggregate passes both the
// element from the sequence and an aggregated value (as the first argument to
// f()). The value of the seed parameter is used as the initial aggregate value.
// The result of f() replaces the previous aggregated value.
//
// Aggregate returns the final result of f().
Expand All @@ -76,9 +76,10 @@ func (q Query) AggregateWithSeed(

// AggregateWithSeedT is the typed version of AggregateWithSeed.
//
// NOTE: AggregateWithSeed method has better performance than AggregateWithSeedT
// - f is of type "func(TAccumulate, TSource) TAccumulate"
//
// f is of a type "func(TAccumulate, TSource) TAccumulate"
// NOTE: AggregateWithSeed has better performance than
// AggregateWithSeedT.
func (q Query) AggregateWithSeedT(seed interface{}, f interface{}) interface{} {
fGenericFunc, err := newGenericFunc(
"AggregateWithSeed", "f", f,
Expand All @@ -95,17 +96,19 @@ func (q Query) AggregateWithSeedT(seed interface{}, f interface{}) interface{} {
return q.AggregateWithSeed(seed, fFunc)
}

// AggregateWithSeedBy applies an accumulator function over a sequence.
// The specified seed value is used as the initial accumulator value,
// and the specified function is used to select the result value.
// AggregateWithSeedBy applies an accumulator function over a sequence. The
// specified seed value is used as the initial accumulator value, and the
// specified function is used to select the result value.
//
// Aggregate method makes it simple to perform a calculation over a sequence of values.
// This method works by calling f() one time for each element in source.
// Each time func is called, Aggregate passes both the element from the sequence and an
// aggregated value (as the first argument to func). The value of the seed parameter is used
// as the initial aggregate value. The result of func replaces the previous aggregated value.
// Aggregate method makes it simple to perform a calculation over a sequence of
// values. This method works by calling f() one time for each element in source.
// Each time func is called, Aggregate passes both the element from the sequence
// and an aggregated value (as the first argument to func). The value of the
// seed parameter is used as the initial aggregate value. The result of func
// replaces the previous aggregated value.
//
// The final result of func is passed to resultSelector to obtain the final result of Aggregate.
// The final result of func is passed to resultSelector to obtain the final
// result of Aggregate.
func (q Query) AggregateWithSeedBy(
seed interface{},
f func(interface{}, interface{}) interface{},
Expand All @@ -124,11 +127,11 @@ func (q Query) AggregateWithSeedBy(

// AggregateWithSeedByT is the typed version of AggregateWithSeedBy.
//
// NOTE: AggregateWithSeedBy method has better performance than AggregateWithSeedByT
//
// f is of a type "func(TAccumulate, TSource) TAccumulate"
// - f is of type "func(TAccumulate, TSource) TAccumulate"
// - resultSelectorFn is of type "func(TAccumulate) TResult"
//
// resultSelectorFn is of type "func(TAccumulate) TResult"
// NOTE: AggregateWithSeedBy has better performance than
// AggregateWithSeedByT.
func (q Query) AggregateWithSeedByT(seed interface{}, f interface{}, resultSelectorFn interface{}) interface{} {
fGenericFunc, err := newGenericFunc(
"AggregateWithSeedByT", "f", f,
Expand Down
22 changes: 11 additions & 11 deletions compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ package linq

type comparer func(interface{}, interface{}) int

// Comparable is an interface that has to be implemented by a
// custom collection elememts in order to work with linq.
// Comparable is an interface that has to be implemented by a custom collection
// elememts in order to work with linq.
//
// Example:
// func (f foo) CompareTo(c Comparable) int {
// a, b := f.f1, c.(foo).f1
// func (f foo) CompareTo(c Comparable) int {
// a, b := f.f1, c.(foo).f1
//
// if a < b {
// return -1
// } else if a > b {
// return 1
// }
// if a < b {
// return -1
// } else if a > b {
// return 1
// }
//
// return 0
// }
// return 0
// }
type Comparable interface {
CompareTo(Comparable) int
}
Expand Down
12 changes: 6 additions & 6 deletions concat.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package linq

// Append inserts an item to the end of a collection,
// so it becomes the last item.
// Append inserts an item to the end of a collection, so it becomes the last
// item.
func (q Query) Append(item interface{}) Query {
return Query{
Iterate: func() Iterator {
Expand All @@ -28,8 +28,8 @@ func (q Query) Append(item interface{}) Query {
// Concat concatenates two collections.
//
// The Concat method differs from the Union method because the Concat method
// returns all the original elements in the input sequences.
// The Union method returns only unique elements.
// returns all the original elements in the input sequences. The Union method
// returns only unique elements.
func (q Query) Concat(q2 Query) Query {
return Query{
Iterate: func() Iterator {
Expand All @@ -53,8 +53,8 @@ func (q Query) Concat(q2 Query) Query {
}
}

// Prepend inserts an item to the beginning of a collection,
// so it becomes the first item.
// Prepend inserts an item to the beginning of a collection, so it becomes the
// first item.
func (q Query) Prepend(item interface{}) Query {
return Query{
Iterate: func() Iterator {
Expand Down
14 changes: 7 additions & 7 deletions distinct.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package linq

// Distinct method returns distinct elements from a collection.
// The result is an unordered collection that contains no duplicate values.
// Distinct method returns distinct elements from a collection. The result is an
// unordered collection that contains no duplicate values.
func (q Query) Distinct() Query {
return Query{
Iterate: func() Iterator {
Expand All @@ -22,11 +22,11 @@ func (q Query) Distinct() Query {
}
}

// Distinct method returns distinct elements from a collection.
// The result is an ordered collection that contains no duplicate values.
// Distinct method returns distinct elements from a collection. The result is an
// ordered collection that contains no duplicate values.
//
// NOTE: Distinct method on OrderedQuery type has better performance than
// Distinct method on Query type
// Distinct method on Query type.
func (oq OrderedQuery) Distinct() OrderedQuery {
return OrderedQuery{
orders: oq.orders,
Expand Down Expand Up @@ -76,9 +76,9 @@ func (q Query) DistinctBy(selector func(interface{}) interface{}) Query {

// DistinctByT is the typed version of DistinctBy.
//
// NOTE: DistinctBy method has better performance than DistinctByT
// - selectorFn is of type "func(TSource) TSource".
//
// selectorFn is of type "func(TSource) TSource".
// NOTE: DistinctBy has better performance than DistinctByT.
func (q Query) DistinctByT(selectorFn interface{}) Query {
selectorFunc, ok := selectorFn.(func(interface{}) interface{})
if !ok {
Expand Down
16 changes: 7 additions & 9 deletions except.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package linq

// Except produces the set difference of two sequences.
// The set difference is the members of the first sequence
// that don't appear in the second sequence.
// Except produces the set difference of two sequences. The set difference is
// the members of the first sequence that don't appear in the second sequence.
func (q Query) Except(q2 Query) Query {
return Query{
Iterate: func() Iterator {
Expand All @@ -27,10 +26,9 @@ func (q Query) Except(q2 Query) Query {
}
}

// ExceptBy invokes a transform function on each element of a collection
// and produces the set difference of two sequences.
// The set difference is the members of the first sequence
// that don't appear in the second sequence.
// ExceptBy invokes a transform function on each element of a collection and
// produces the set difference of two sequences. The set difference is the
// members of the first sequence that don't appear in the second sequence.
func (q Query) ExceptBy(
q2 Query, selector func(interface{}) interface{}) Query {
return Query{
Expand Down Expand Up @@ -60,9 +58,9 @@ func (q Query) ExceptBy(

// ExceptByT is the typed version of ExceptBy.
//
// NOTE: ExceptBy method has better performance than ExceptByT
// - selectorFn is of type "func(TSource) TSource"
//
// selectorFn is of a type "func(TSource) TSource"
// NOTE: ExceptBy has better performance than ExceptByT.
func (q Query) ExceptByT(q2 Query, selectorFn interface{}) Query {
selectorGenericFunc, err := newGenericFunc(
"ExceptByT", "selectorFn", selectorFn,
Expand Down
34 changes: 17 additions & 17 deletions from.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ import "reflect"
// Iterator is an alias for function to iterate over data.
type Iterator func() (item interface{}, ok bool)

// Query is the type returned from query functions.
// It can be iterated manually as shown in the example.
// Query is the type returned from query functions. It can be iterated manually
// as shown in the example.
type Query struct {
Iterate func() Iterator
}

// KeyValue is a type that is used to iterate over a map
// (if query is created from a map). This type is also used by
// ToMap() method to output result of a query into a map.
// KeyValue is a type that is used to iterate over a map (if query is created
// from a map). This type is also used by ToMap() method to output result of a
// query into a map.
type KeyValue struct {
Key interface{}
Value interface{}
}

// Iterable is an interface that has to be implemented by a
// custom collection in order to work with linq.
// Iterable is an interface that has to be implemented by a custom collection in
// order to work with linq.
type Iterable interface {
Iterate() Iterator
}

// From initializes a linq query with passed slice, array or map
// as the source. String, channel or struct implementing Iterable
// interface can be used as an input. In this case From delegates it
// to FromString, FromChannel and FromIterable internally.
// From initializes a linq query with passed slice, array or map as the source.
// String, channel or struct implementing Iterable interface can be used as an
// input. In this case From delegates it to FromString, FromChannel and
// FromIterable internally.
func From(source interface{}) Query {
src := reflect.ValueOf(source)

Expand Down Expand Up @@ -84,8 +84,8 @@ func From(source interface{}) Query {
}
}

// FromChannel initializes a linq query with passed channel,
// linq iterates over channel until it is closed.
// FromChannel initializes a linq query with passed channel, linq iterates over
// channel until it is closed.
func FromChannel(source <-chan interface{}) Query {
return Query{
Iterate: func() Iterator {
Expand All @@ -97,8 +97,8 @@ func FromChannel(source <-chan interface{}) Query {
}
}

// FromString initializes a linq query with passed string,
// linq iterates over runes of string.
// FromString initializes a linq query with passed string, linq iterates over
// runes of string.
func FromString(source string) Query {
runes := []rune(source)
len := len(runes)
Expand All @@ -120,8 +120,8 @@ func FromString(source string) Query {
}
}

// FromIterable initializes a linq query with custom collection passed.
// This collection has to implement Iterable interface, linq iterates over items,
// FromIterable initializes a linq query with custom collection passed. This
// collection has to implement Iterable interface, linq iterates over items,
// that has to implement Comparable interface or be basic types.
func FromIterable(source Iterable) Query {
return Query{
Expand Down
15 changes: 8 additions & 7 deletions genericfunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"strings"
)

// genericType represents a any reflect.Type
// genericType represents a any reflect.Type.
type genericType int

var genericTp = reflect.TypeOf(new(genericType)).Elem()

// functionCache keeps genericFunc reflection objects in cache
// functionCache keeps genericFunc reflection objects in cache.
type functionCache struct {
MethodName string
ParamName string
Expand All @@ -21,12 +21,12 @@ type functionCache struct {
TypesOut []reflect.Type
}

// genericFunc is a type used to validate and call dynamic functions
// genericFunc is a type used to validate and call dynamic functions.
type genericFunc struct {
Cache *functionCache
}

// Call calls a dynamic function
// Call calls a dynamic function.
func (g *genericFunc) Call(params ...interface{}) interface{} {
paramsIn := make([]reflect.Value, len(params))
for i, param := range params {
Expand Down Expand Up @@ -68,7 +68,8 @@ func newGenericFunc(methodName, paramName string, fn interface{}, validateFunc f
return &genericFunc{Cache: cache}, nil
}

// simpleParamValidator creates a function to validate genericFunc based in the In and Out function parameters
// simpleParamValidator creates a function to validate genericFunc based in the
// In and Out function parameters.
func simpleParamValidator(In []reflect.Type, Out []reflect.Type) func(cache *functionCache) error {
return func(cache *functionCache) error {
var isValid = func() bool {
Expand Down Expand Up @@ -102,7 +103,7 @@ func simpleParamValidator(In []reflect.Type, Out []reflect.Type) func(cache *fun
}
}

// newElemTypeSlice creates a slice of items elem types
// newElemTypeSlice creates a slice of items elem types.
func newElemTypeSlice(items ...interface{}) []reflect.Type {
typeList := make([]reflect.Type, len(items))
for i, item := range items {
Expand All @@ -114,7 +115,7 @@ func newElemTypeSlice(items ...interface{}) []reflect.Type {
return typeList
}

// formatFnSignature formats the func signature based in the parameters types
// formatFnSignature formats the func signature based in the parameters types.
func formatFnSignature(In []reflect.Type, Out []reflect.Type) string {
paramInNames := make([]string, len(In))
for i, typeIn := range In {
Expand Down
Loading

0 comments on commit 873aaae

Please sign in to comment.