Skip to content

Commit

Permalink
Fix lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnteee committed May 12, 2022
1 parent 3dc8f82 commit d31b191
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 86 deletions.
10 changes: 4 additions & 6 deletions actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (
"time"
)

var (
ErrActorAskTimeout = fmt.Errorf("ErrActorAskTimeout")
)
var ErrActorAskTimeout = fmt.Errorf("ErrActorAskTimeout")

// ActorHandle A target could send messages
type ActorHandle interface {
Expand Down Expand Up @@ -183,9 +181,9 @@ func (askSelf *AskDef) Reply(response interface{}) {
var Ask AskDef

func init() {
//Ask = *Ask.New(0, nil)
//Actor = *Actor.New(func(_ *ActorDef, _ interface{}) {})
//Actor.Close()
// Ask = *Ask.New(0, nil)
// Actor = *Actor.New(func(_ *ActorDef, _ interface{}) {})
// Actor.Close()
Actor.isClosed = true
defaultActor = &Actor
}
4 changes: 0 additions & 4 deletions actor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,23 @@ func TestActorAsk(t *testing.T) {
timeout = 10 * time.Millisecond

// Normal cases
actual = 0
expectedInt = 10
result, _ = Ask.New(1).AskOnce(actorRoot, nil)
actual, _ = Maybe.Just(result).ToInt()
assert.Equal(t, expectedInt, actual)
// Ask with Timeout
actual = 0
expectedInt = 20
result, _ = Ask.New(2).AskOnce(actorRoot, &timeout)
actual, _ = Maybe.Just(result).ToInt()
assert.Equal(t, expectedInt, actual)
// Ask channel
actual = 0
expectedInt = 30
ch := AskNewGenerics(3).AskChannel(actorRoot)
actual, _ = Maybe.Just(<-*ch).ToInt()
close(*ch)
assert.Equal(t, expectedInt, actual)

// Timeout cases
actual = 9999
expectedInt = 0
result, err = Ask.New(-1).AskOnce(actorRoot, &timeout)
actual, _ = Maybe.Just(result).ToInt()
Expand Down
3 changes: 3 additions & 0 deletions cor.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (corSelf *CorDef) YieldFrom(target *CorDef, in interface{}) interface{} {

return result
}

func (corSelf *CorDef) receive(cor *CorDef, in interface{}) {
corSelf.doCloseSafe(func() {
if corSelf.opCh != nil {
Expand Down Expand Up @@ -179,6 +180,7 @@ func (corSelf *CorDef) IsDone() bool {
func (corSelf *CorDef) IsStarted() bool {
return corSelf.isStarted.Get()
}

func (corSelf *CorDef) close() {
corSelf.isClosed.Set(true)

Expand All @@ -191,6 +193,7 @@ func (corSelf *CorDef) close() {
}
corSelf.closedM.Unlock()
}

func (corSelf *CorDef) doCloseSafe(fn func()) {
if corSelf.IsDone() {
return
Expand Down
3 changes: 1 addition & 2 deletions cor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ func logMessage(args ...interface{}) {
}

func TestCorYield(t *testing.T) {
var expectedInt int
var actualInt = 0
var expectedInt, actualInt int
var testee *CorDef
var wg sync.WaitGroup

Expand Down
27 changes: 11 additions & 16 deletions fp.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func Compose(fnList ...func(...interface{}) []interface{}) func(...interface{})
// Pipe Pipe the functions from left to right
func Pipe(fnList ...func(...interface{}) []interface{}) func(...interface{}) []interface{} {
return func(s ...interface{}) []interface{} {

lastIndex := len(fnList) - 1
f := fnList[lastIndex]
nextFnList := fnList[:lastIndex]
Expand Down Expand Up @@ -100,7 +99,6 @@ func MapIndexed(fn func(interface{}, int) interface{}, values ...interface{}) []

// Reduce Reduce the values from left to right(func(memo,val), starting value, slice)
func Reduce(fn ReducerFunctor, memo interface{}, input ...interface{}) interface{} {

for i := 0; i < len(input); i++ {
memo = fn(memo, input[i])
}
Expand All @@ -110,7 +108,6 @@ func Reduce(fn ReducerFunctor, memo interface{}, input ...interface{}) interface

// ReduceIndexed Reduce the values from left to right(func(memo,val,index), starting value, slice)
func ReduceIndexed(fn func(interface{}, interface{}, int) interface{}, memo interface{}, input ...interface{}) interface{} {

for i := 0; i < len(input); i++ {
memo = fn(memo, input[i], i)
}
Expand All @@ -120,9 +117,9 @@ func ReduceIndexed(fn func(interface{}, interface{}, int) interface{}, memo inte

// Filter Filter the values by the given predicate function (predicate func, slice)
func Filter(fn func(interface{}, int) bool, input ...interface{}) []interface{} {
var list = make([]interface{}, len(input))
list := make([]interface{}, len(input))

var newLen = 0
newLen := 0

for i := range input {
if fn(input[i], i) {
Expand All @@ -145,18 +142,18 @@ func Reject(fn func(interface{}, int) bool, input ...interface{}) []interface{}

// Concat Concat slices
func Concat(mine []interface{}, slices ...[]interface{}) []interface{} {
var mineLen = len(mine)
var totalLen = mineLen
mineLen := len(mine)
totalLen := mineLen

for _, slice := range slices {
if slice == nil {
continue
}

var targetLen = len(slice)
targetLen := len(slice)
totalLen += targetLen
}
var newOne = make([]interface{}, totalLen)
newOne := make([]interface{}, totalLen)

for i, item := range mine {
newOne[i] = item
Expand All @@ -168,8 +165,8 @@ func Concat(mine []interface{}, slices ...[]interface{}) []interface{} {
continue
}

var target = slice
var targetLen = len(target)
target := slice
targetLen := len(target)
for j, item := range target {
newOne[totalIndex+j] = item
}
Expand Down Expand Up @@ -646,7 +643,7 @@ func PMap(f TransformerFunctor, option *PMapOption, list ...interface{}) []inter
return make([]interface{}, 0)
}

var worker = len(list)
worker := len(list)
if option != nil {
if option.FixedPool > 0 && option.FixedPool < worker {
worker = option.FixedPool
Expand Down Expand Up @@ -942,7 +939,6 @@ func UniqBy(identify TransformerFunctor, list ...interface{}) []interface{} {

// Flatten creates a new slice where one level of nested elements are unnested
func Flatten(list ...[]interface{}) []interface{} {

result := make([]interface{}, 0)

// for _, v := range list {
Expand All @@ -952,7 +948,7 @@ func Flatten(list ...[]interface{}) []interface{} {
return Concat(result, list...)
}

// Prepend returns the slice with the additional element added to the beggining
// Prepend returns the slice with the additional element added to the beginning
func Prepend(element interface{}, list []interface{}) []interface{} {
return append([]interface{}{element}, list...)
}
Expand Down Expand Up @@ -1500,8 +1496,7 @@ type ProductType struct {
}

// NilTypeDef NilType implemented by Nil determinations
type NilTypeDef struct {
}
type NilTypeDef struct{}

// Matches Check does it match the SumType
func (typeSelf SumType) Matches(value ...interface{}) bool {
Expand Down
25 changes: 11 additions & 14 deletions fp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ func SortStringAscending(input ...interface{}) []interface{} {
func TestCompose(t *testing.T) {
var expectedinteger int

var fn01 = func(args ...interface{}) []interface{} {
fn01 := func(args ...interface{}) []interface{} {
val, _ := Maybe.Just(args[0]).ToInt()
return SliceOf(val + 1)
}
var fn02 = func(args ...interface{}) []interface{} {
fn02 := func(args ...interface{}) []interface{} {
val, _ := Maybe.Just(args[0]).ToInt()
return SliceOf(val + 2)
}
var fn03 = func(args ...interface{}) []interface{} {
fn03 := func(args ...interface{}) []interface{} {
val, _ := Maybe.Just(args[0]).ToInt()
return SliceOf(val + 3)
}
Expand Down Expand Up @@ -68,7 +68,6 @@ func TestCompose(t *testing.T) {

expectedinteger = 6
assert.Equal(t, expectedinteger, Pipe(fn01, fn02, fn03)((0))[0])

}

func TestFPFunctions(t *testing.T) {
Expand Down Expand Up @@ -98,7 +97,6 @@ func TestFPFunctions(t *testing.T) {
var actualMap map[interface{}]interface{}

fib := func(n int) int {

result, _ := Trampoline(func(input ...interface{}) ([]interface{}, bool, error) {
n, _ := Maybe.Just(input[0]).ToInt()
a, _ := Maybe.Just(input[1]).ToInt()
Expand Down Expand Up @@ -237,7 +235,6 @@ func TestFPFunctions(t *testing.T) {
aVal, _ := Maybe.Just(a).ToInt()
return aVal % 2
}, 1, 2, 3, 4, 5, 6, 7, 8))

}

func TestVariadic(t *testing.T) {
Expand Down Expand Up @@ -326,9 +323,9 @@ func TestCurry(t *testing.T) {
}

func TestCompType(t *testing.T) {
var compTypeA = DefProduct(reflect.Int, reflect.String)
var compTypeB = DefProduct(reflect.String)
var myType = DefSum(NilType, compTypeA, compTypeB)
compTypeA := DefProduct(reflect.Int, reflect.String)
compTypeB := DefProduct(reflect.String)
myType := DefSum(NilType, compTypeA, compTypeB)

assert.Equal(t, true, myType.Matches((1), ("1")))
assert.Equal(t, true, myType.Matches(("2")))
Expand All @@ -341,9 +338,9 @@ func TestCompType(t *testing.T) {
}

func TestPatternMatching(t *testing.T) {
var compTypeA = DefProduct(reflect.Int, reflect.String)
var compTypeB = DefProduct(reflect.String, reflect.String)
var myType = DefSum(NilType, compTypeA, compTypeB)
compTypeA := DefProduct(reflect.Int, reflect.String)
compTypeB := DefProduct(reflect.String, reflect.String)
myType := DefSum(NilType, compTypeA, compTypeB)

assert.Equal(t, true, compTypeA.Matches(1, "3"))
assert.Equal(t, false, compTypeA.Matches(1, 3))
Expand All @@ -352,7 +349,7 @@ func TestPatternMatching(t *testing.T) {
assert.Equal(t, true, myType.Matches("1", "3"))
assert.Equal(t, false, myType.Matches(1, 3))

var patterns = []Pattern{
patterns := []Pattern{
InCaseOfKind(reflect.Int, func(x interface{}) interface{} {
return (fmt.Sprintf("Integer: %v", x))
}),
Expand All @@ -369,7 +366,7 @@ func TestPatternMatching(t *testing.T) {
return (fmt.Sprintf("got this object: %v", x))
}),
}
var pm = DefPattern(patterns...)
pm := DefPattern(patterns...)
assert.Equal(t, "Integer: 42", pm.MatchFor((42)))
assert.Equal(t, "Hello world", pm.MatchFor(("world")))
assert.Equal(t, "Matched: ccc", pm.MatchFor(("ccc")))
Expand Down
2 changes: 1 addition & 1 deletion maybe.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (maybeSelf someDef) ToPtr() *interface{} {

// ToMaybe Maybe to Maybe
func (maybeSelf someDef) ToMaybe() MaybeDef {
var ref = maybeSelf.ref
ref := maybeSelf.ref
switch (ref).(type) {
default:
return maybeSelf
Expand Down
8 changes: 4 additions & 4 deletions maybe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestIsPresent(t *testing.T) {
assert.Equal(t, false, m.IsPresent())
assert.Equal(t, true, m.IsNil())

var i = 1
i := 1
var iptr *int

iptr = nil
Expand All @@ -45,9 +45,9 @@ func TestOr(t *testing.T) {
func TestClone(t *testing.T) {
var m MaybeDef

var i = 1
var i2 = 2
var temp = 3
i := 1
i2 := 2
temp := 3
var iptr *int
var iptr2 *int
iptr2 = &i2
Expand Down
5 changes: 2 additions & 3 deletions monadIO.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ func (monadIOSelf *MonadIODef) New(effect func() interface{}) *MonadIODef {

// FlatMap FlatMap the MonadIO by function
func (monadIOSelf *MonadIODef) FlatMap(fn func(interface{}) *MonadIODef) *MonadIODef {

return &MonadIODef{effect: func() interface{} {
next := fn(monadIOSelf.doEffect())
return next.doEffect()
}}

}

// Subscribe Subscribe the MonadIO by Subscription
Expand All @@ -53,8 +51,8 @@ func (monadIOSelf *MonadIODef) ObserveOn(h *HandlerDef) *MonadIODef {
monadIOSelf.obOn = h
return monadIOSelf
}
func (monadIOSelf *MonadIODef) doSubscribe(s *Subscription, obOn *HandlerDef, subOn *HandlerDef) *Subscription {

func (monadIOSelf *MonadIODef) doSubscribe(s *Subscription, obOn *HandlerDef, subOn *HandlerDef) *Subscription {
if s.OnNext != nil {
var result interface{}

Expand All @@ -79,6 +77,7 @@ func (monadIOSelf *MonadIODef) doSubscribe(s *Subscription, obOn *HandlerDef, su

return s
}

func (monadIOSelf *MonadIODef) doEffect() interface{} {
return monadIOSelf.effect()
}
Expand Down
2 changes: 0 additions & 2 deletions network/simpleHTTP.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ func (simpleHTTPSelf *SimpleHTTPDef) DoNewRequestWithBodyOptions(context context

// DoRequest Do HTTP Request with interceptors
func (simpleHTTPSelf *SimpleHTTPDef) DoRequest(request *http.Request) *ResponseWithError {

response, err := simpleHTTPSelf.client.Do(request)

return &ResponseWithError{
Expand Down Expand Up @@ -454,7 +453,6 @@ func (simpleAPISelf *SimpleAPIDef) MakeDoNewRequestWithMultipartSerializer(metho
func (simpleAPISelf *SimpleAPIDef) MakeDoNewRequest(method string, relativeURL string) APINoBody {
return APINoBody(func(pathParam PathParam, target interface{}) *fpgo.MonadIODef {
return fpgo.MonadIO.New(func() interface{} {

ctx, cancel := simpleAPISelf.GetSimpleHTTP().GetContextTimeout()
defer cancel()
response := simpleAPISelf.simpleHTTP.DoNewRequest(ctx, simpleAPISelf.DefaultHeader.Clone(), method, simpleAPISelf.replacePathParams(relativeURL, pathParam))
Expand Down
Loading

0 comments on commit d31b191

Please sign in to comment.