Skip to content

Commit

Permalink
Lenght -> Length
Browse files Browse the repository at this point in the history
  • Loading branch information
quackable committed Jun 14, 2024
1 parent 6766a26 commit a3fada2
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 152 deletions.
14 changes: 7 additions & 7 deletions functions/sequence_using.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import "github.com/elliotchance/pie/pie/util"
// SequenceUsing generates slice in range using creator function
//
// There are 3 variations to generate:
// 1. [0, n).
// 2. [min, max).
// 3. [min, max) with step.
// 1. [0, n).
// 2. [min, max).
// 3. [min, max) with step.
//
// if len(params) == 1 considered that will be returned slice between 0 and n,
// where n is the first param, [0, n).
Expand All @@ -18,13 +18,13 @@ import "github.com/elliotchance/pie/pie/util"
// others params will be ignored
func (ss SliceType) SequenceUsing(creator func(int) ElementType, params ...int) SliceType {
var seq = func(min, max, step int) (seq SliceType) {
lenght := int(util.Round(float64(max-min) / float64(step)))
if lenght < 1 {
length := int(util.Round(float64(max-min) / float64(step)))
if length < 1 {
return
}

seq = make(SliceType, lenght)
for i := 0; i < lenght; min += step {
seq = make(SliceType, length)
for i := 0; i < length; min += step {
seq[i] = creator(min)
i++
}
Expand Down
48 changes: 23 additions & 25 deletions pie/carpointers_pie.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/elliotchance/pie/pie/util"
"math/rand"
"sort"
"strconv"
"strings"

"github.com/elliotchance/pie/pie/util"
)

// All will return true if all callbacks return true. It follows the same logic
Expand Down Expand Up @@ -153,18 +154,17 @@ func (ss carPointers) DropWhile(f func(s *car) bool) (ss2 carPointers) {
// Each is more condensed version of Transform that allows an action to happen
// on each elements and pass the original slice on.
//
// cars.Each(func (car *Car) {
// fmt.Printf("Car color is: %s\n", car.Color)
// })
// cars.Each(func (car *Car) {
// fmt.Printf("Car color is: %s\n", car.Color)
// })
//
// Pie will not ensure immutability on items passed in so they can be
// manipulated, if you choose to do it this way, for example:
//
// // Set all car colors to Red.
// cars.Each(func (car *Car) {
// car.Color = "Red"
// })
//
// // Set all car colors to Red.
// cars.Each(func (car *Car) {
// car.Color = "Red"
// })
func (ss carPointers) Each(fn func(*car)) carPointers {
for _, s := range ss {
fn(s)
Expand Down Expand Up @@ -460,11 +460,11 @@ func (ss carPointers) Mode() carPointers {
//
// Usage Example:
//
// type knownGreetings []string
// greetings := knownGreetings{"ciao", "hello", "hola"}
// for greeting := greetings.Pop(); greeting != nil; greeting = greetings.Pop() {
// fmt.Println(*greeting)
// }
// type knownGreetings []string
// greetings := knownGreetings{"ciao", "hello", "hola"}
// for greeting := greetings.Pop(); greeting != nil; greeting = greetings.Pop() {
// fmt.Println(*greeting)
// }
func (ss *carPointers) Pop() (popped **car) {

if len(*ss) == 0 {
Expand Down Expand Up @@ -495,8 +495,7 @@ func (ss carPointers) Random(source rand.Source) *car {
// Reverse returns a new copy of the slice with the elements ordered in reverse.
// This is useful when combined with Sort to get a descending sort order:
//
// ss.Sort().Reverse()
//
// ss.Sort().Reverse()
func (ss carPointers) Reverse() carPointers {
// Avoid the allocation. If there is one element or less it is already
// reversed.
Expand Down Expand Up @@ -534,9 +533,9 @@ func (ss carPointers) Send(ctx context.Context, ch chan<- *car) carPointers {
// SequenceUsing generates slice in range using creator function
//
// There are 3 variations to generate:
// 1. [0, n).
// 2. [min, max).
// 3. [min, max) with step.
// 1. [0, n).
// 2. [min, max).
// 3. [min, max) with step.
//
// if len(params) == 1 considered that will be returned slice between 0 and n,
// where n is the first param, [0, n).
Expand All @@ -547,13 +546,13 @@ func (ss carPointers) Send(ctx context.Context, ch chan<- *car) carPointers {
// others params will be ignored
func (ss carPointers) SequenceUsing(creator func(int) *car, params ...int) carPointers {
var seq = func(min, max, step int) (seq carPointers) {
lenght := int(util.Round(float64(max-min) / float64(step)))
if lenght < 1 {
length := int(util.Round(float64(max-min) / float64(step)))
if length < 1 {
return
}

seq = make(carPointers, lenght)
for i := 0; i < lenght; min += step {
seq = make(carPointers, length)
for i := 0; i < length; min += step {
seq[i] = creator(min)
i++
}
Expand Down Expand Up @@ -642,8 +641,7 @@ func (ss carPointers) SortUsing(less func(a, b *car) bool) carPointers {
// If the element type implements fmt.Stringer it will be used. Otherwise it
// will fallback to the result of:
//
// fmt.Sprintf("%v")
//
// fmt.Sprintf("%v")
func (ss carPointers) Strings() Strings {
l := len(ss)

Expand Down
48 changes: 23 additions & 25 deletions pie/cars_pie.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/elliotchance/pie/pie/util"
"math/rand"
"sort"
"strconv"
"strings"

"github.com/elliotchance/pie/pie/util"
)

// All will return true if all callbacks return true. It follows the same logic
Expand Down Expand Up @@ -153,18 +154,17 @@ func (ss cars) DropWhile(f func(s car) bool) (ss2 cars) {
// Each is more condensed version of Transform that allows an action to happen
// on each elements and pass the original slice on.
//
// cars.Each(func (car *Car) {
// fmt.Printf("Car color is: %s\n", car.Color)
// })
// cars.Each(func (car *Car) {
// fmt.Printf("Car color is: %s\n", car.Color)
// })
//
// Pie will not ensure immutability on items passed in so they can be
// manipulated, if you choose to do it this way, for example:
//
// // Set all car colors to Red.
// cars.Each(func (car *Car) {
// car.Color = "Red"
// })
//
// // Set all car colors to Red.
// cars.Each(func (car *Car) {
// car.Color = "Red"
// })
func (ss cars) Each(fn func(car)) cars {
for _, s := range ss {
fn(s)
Expand Down Expand Up @@ -460,11 +460,11 @@ func (ss cars) Mode() cars {
//
// Usage Example:
//
// type knownGreetings []string
// greetings := knownGreetings{"ciao", "hello", "hola"}
// for greeting := greetings.Pop(); greeting != nil; greeting = greetings.Pop() {
// fmt.Println(*greeting)
// }
// type knownGreetings []string
// greetings := knownGreetings{"ciao", "hello", "hola"}
// for greeting := greetings.Pop(); greeting != nil; greeting = greetings.Pop() {
// fmt.Println(*greeting)
// }
func (ss *cars) Pop() (popped *car) {

if len(*ss) == 0 {
Expand Down Expand Up @@ -495,8 +495,7 @@ func (ss cars) Random(source rand.Source) car {
// Reverse returns a new copy of the slice with the elements ordered in reverse.
// This is useful when combined with Sort to get a descending sort order:
//
// ss.Sort().Reverse()
//
// ss.Sort().Reverse()
func (ss cars) Reverse() cars {
// Avoid the allocation. If there is one element or less it is already
// reversed.
Expand Down Expand Up @@ -534,9 +533,9 @@ func (ss cars) Send(ctx context.Context, ch chan<- car) cars {
// SequenceUsing generates slice in range using creator function
//
// There are 3 variations to generate:
// 1. [0, n).
// 2. [min, max).
// 3. [min, max) with step.
// 1. [0, n).
// 2. [min, max).
// 3. [min, max) with step.
//
// if len(params) == 1 considered that will be returned slice between 0 and n,
// where n is the first param, [0, n).
Expand All @@ -547,13 +546,13 @@ func (ss cars) Send(ctx context.Context, ch chan<- car) cars {
// others params will be ignored
func (ss cars) SequenceUsing(creator func(int) car, params ...int) cars {
var seq = func(min, max, step int) (seq cars) {
lenght := int(util.Round(float64(max-min) / float64(step)))
if lenght < 1 {
length := int(util.Round(float64(max-min) / float64(step)))
if length < 1 {
return
}

seq = make(cars, lenght)
for i := 0; i < lenght; min += step {
seq = make(cars, length)
for i := 0; i < length; min += step {
seq[i] = creator(min)
i++
}
Expand Down Expand Up @@ -642,8 +641,7 @@ func (ss cars) SortUsing(less func(a, b car) bool) cars {
// If the element type implements fmt.Stringer it will be used. Otherwise it
// will fallback to the result of:
//
// fmt.Sprintf("%v")
//
// fmt.Sprintf("%v")
func (ss cars) Strings() Strings {
l := len(ss)

Expand Down
55 changes: 26 additions & 29 deletions pie/float64s_pie.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/elliotchance/pie/pie/util"
"math"
"math/rand"
"sort"
"strconv"
"strings"

"github.com/elliotchance/pie/pie/util"
)

// Abs is a function which returns the absolute value of all the
Expand Down Expand Up @@ -192,18 +193,17 @@ func (ss Float64s) DropWhile(f func(s float64) bool) (ss2 Float64s) {
// Each is more condensed version of Transform that allows an action to happen
// on each elements and pass the original slice on.
//
// cars.Each(func (car *Car) {
// fmt.Printf("Car color is: %s\n", car.Color)
// })
// cars.Each(func (car *Car) {
// fmt.Printf("Car color is: %s\n", car.Color)
// })
//
// Pie will not ensure immutability on items passed in so they can be
// manipulated, if you choose to do it this way, for example:
//
// // Set all car colors to Red.
// cars.Each(func (car *Car) {
// car.Color = "Red"
// })
//
// // Set all car colors to Red.
// cars.Each(func (car *Car) {
// car.Color = "Red"
// })
func (ss Float64s) Each(fn func(float64)) Float64s {
for _, s := range ss {
fn(s)
Expand Down Expand Up @@ -320,7 +320,6 @@ func (ss Float64s) Float64s() Float64s {
}

// Group returns a map of the value with an individual count.
//
func (ss Float64s) Group() map[float64]int {
group := map[float64]int{}
for _, n := range ss {
Expand Down Expand Up @@ -641,11 +640,11 @@ func (ss Float64s) Mode() Float64s {
//
// Usage Example:
//
// type knownGreetings []string
// greetings := knownGreetings{"ciao", "hello", "hola"}
// for greeting := greetings.Pop(); greeting != nil; greeting = greetings.Pop() {
// fmt.Println(*greeting)
// }
// type knownGreetings []string
// greetings := knownGreetings{"ciao", "hello", "hola"}
// for greeting := greetings.Pop(); greeting != nil; greeting = greetings.Pop() {
// fmt.Println(*greeting)
// }
func (ss *Float64s) Pop() (popped *float64) {

if len(*ss) == 0 {
Expand Down Expand Up @@ -705,8 +704,7 @@ func (ss Float64s) Reduce(reducer func(float64, float64) float64) (el float64) {
// Reverse returns a new copy of the slice with the elements ordered in reverse.
// This is useful when combined with Sort to get a descending sort order:
//
// ss.Sort().Reverse()
//
// ss.Sort().Reverse()
func (ss Float64s) Reverse() Float64s {
// Avoid the allocation. If there is one element or less it is already
// reversed.
Expand Down Expand Up @@ -744,9 +742,9 @@ func (ss Float64s) Send(ctx context.Context, ch chan<- float64) Float64s {
// Sequence generates all numbers in range or returns nil if params invalid
//
// There are 3 variations to generate:
// 1. [0, n).
// 2. [min, max).
// 3. [min, max) with step.
// 1. [0, n).
// 2. [min, max).
// 3. [min, max) with step.
//
// if len(params) == 1 considered that will be returned slice between 0 and n,
// where n is the first param, [0, n).
Expand All @@ -766,9 +764,9 @@ func (ss Float64s) Sequence(params ...int) Float64s {
// SequenceUsing generates slice in range using creator function
//
// There are 3 variations to generate:
// 1. [0, n).
// 2. [min, max).
// 3. [min, max) with step.
// 1. [0, n).
// 2. [min, max).
// 3. [min, max) with step.
//
// if len(params) == 1 considered that will be returned slice between 0 and n,
// where n is the first param, [0, n).
Expand All @@ -779,13 +777,13 @@ func (ss Float64s) Sequence(params ...int) Float64s {
// others params will be ignored
func (ss Float64s) SequenceUsing(creator func(int) float64, params ...int) Float64s {
var seq = func(min, max, step int) (seq Float64s) {
lenght := int(util.Round(float64(max-min) / float64(step)))
if lenght < 1 {
length := int(util.Round(float64(max-min) / float64(step)))
if length < 1 {
return
}

seq = make(Float64s, lenght)
for i := 0; i < lenght; min += step {
seq = make(Float64s, length)
for i := 0; i < length; min += step {
seq[i] = creator(min)
i++
}
Expand Down Expand Up @@ -875,8 +873,7 @@ func (ss Float64s) Stddev() float64 {
// If the element type implements fmt.Stringer it will be used. Otherwise it
// will fallback to the result of:
//
// fmt.Sprintf("%v")
//
// fmt.Sprintf("%v")
func (ss Float64s) Strings() Strings {
l := len(ss)

Expand Down
Loading

0 comments on commit a3fada2

Please sign in to comment.