Skip to content

Commit

Permalink
Format by gofmt/gofumpt (gofumpt -l -w .)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnteee committed May 12, 2022
1 parent 456039a commit 0b406e4
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 95 deletions.
4 changes: 1 addition & 3 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[T any] interface {
Expand Down
3 changes: 3 additions & 0 deletions cor.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func (corSelf *CorDef[T]) YieldFrom(target *CorDef[T], in T) T {

return result
}

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

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

Expand All @@ -196,6 +198,7 @@ func (corSelf *CorDef[T]) close() {
}
corSelf.closedM.Unlock()
}

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

func TestCorYield(t *testing.T) {
var expectedInt int
var actualInt = 0
actualInt := 0
var testee *CorDef[interface{}]
var wg sync.WaitGroup

Expand Down
25 changes: 10 additions & 15 deletions fp.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func ComposeInterface(fnList ...func(...interface{}) []interface{}) func(...inte
// Pipe Pipe the functions from left to right
func Pipe[T any](fnList ...func(...T) []T) func(...T) []T {
return func(s ...T) []T {

lastIndex := len(fnList) - 1
f := fnList[lastIndex]
nextFnList := fnList[:lastIndex]
Expand Down Expand Up @@ -131,7 +130,6 @@ func MapIndexed[T any, R any](fn func(T, int) R, values ...T) []R {

// Reduce Reduce the values from left to right(func(memo,val), starting value, slice)
func Reduce[T any, R any](fn ReducerFunctor[T, R], memo R, input ...T) R {

for i := 0; i < len(input); i++ {
memo = fn(memo, input[i])
}
Expand All @@ -141,7 +139,6 @@ func Reduce[T any, R any](fn ReducerFunctor[T, R], memo R, input ...T) R {

// ReduceIndexed Reduce the values from left to right(func(memo,val,index), starting value, slice)
func ReduceIndexed[T any, R any](fn func(R, T, int) R, memo R, input ...T) R {

for i := 0; i < len(input); i++ {
memo = fn(memo, input[i], i)
}
Expand All @@ -151,9 +148,9 @@ func ReduceIndexed[T any, R any](fn func(R, T, int) R, memo R, input ...T) R {

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

var newLen = 0
newLen := 0

for i := range input {
if fn(input[i], i) {
Expand All @@ -176,18 +173,18 @@ func Reject[T any](fn func(T, int) bool, input ...T) []T {

// Concat Concat slices
func Concat[T any](mine []T, slices ...[]T) []T {
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([]T, totalLen)
newOne := make([]T, totalLen)

for i, item := range mine {
newOne[i] = item
Expand All @@ -199,8 +196,8 @@ func Concat[T any](mine []T, slices ...[]T) []T {
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 @@ -970,7 +967,7 @@ func PMap[T any, R any](f TransformerFunctor[T, R], option *PMapOption, list ...
return make([]R, 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 @@ -1354,7 +1351,6 @@ func UniqBy[T any, R comparable](identify TransformerFunctor[T, R], list ...T) [

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

result := make([]T, 0)

// for _, v := range list {
Expand Down Expand Up @@ -1942,8 +1938,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
24 changes: 11 additions & 13 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 ...int) []int {
fn01 := func(args ...int) []int {
val := args[0]
return SliceOf(val + 1)
}
var fn02 = func(args ...int) []int {
fn02 := func(args ...int) []int {
val := args[0]
return SliceOf(val + 2)
}
var fn03 = func(args ...int) []int {
fn03 := func(args ...int) []int {
val := args[0]
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 All @@ -84,7 +83,6 @@ func TestFPFunctions(t *testing.T) {
var actualMap map[int]int

fib := func(n int) int {

result, _ := Trampoline(func(input ...int) ([]int, bool, error) {
n := input[0]
a := input[1]
Expand Down Expand Up @@ -287,9 +285,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 @@ -302,9 +300,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 @@ -313,7 +311,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 @@ -330,7 +328,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
1 change: 1 addition & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (handlerSelf *HandlerDef) Close() {

close(*handlerSelf.ch)
}

func (handlerSelf *HandlerDef) run() {
for fn := range *handlerSelf.ch {
fn()
Expand Down
2 changes: 1 addition & 1 deletion maybe.go
Original file line number Diff line number Diff line change
Expand Up @@ -1413,5 +1413,5 @@ func (noneSelf noneDef) Kind() reflect.Kind {
// None None utils instance
var None = noneDef{someDef[any]{isNil: true, isPresent: false}}

//var noneAsSome = someDef[interface{}](None)
// var noneAsSome = someDef[interface{}](None)
var noneAsSome = None.someDef
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[interface{}]

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 @@ -37,12 +37,10 @@ func MonadIONewGenerics[T any](effect func() T) *MonadIODef[T] {

// FlatMap FlatMap the MonadIO by function
func (monadIOSelf *MonadIODef[T]) FlatMap(fn func(T) *MonadIODef[T]) *MonadIODef[T] {

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

}

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

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

Expand All @@ -89,6 +87,7 @@ func (monadIOSelf *MonadIODef[T]) doSubscribe(s *Subscription[T], obOn *HandlerD

return s
}

func (monadIOSelf *MonadIODef[T]) doEffect() T {
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 @@ -219,7 +219,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 @@ -467,7 +466,6 @@ func APIMakeDoNewRequestWithMultipartSerializer[R any](simpleAPISelf *SimpleAPID
func APIMakeDoNewRequest[R any](simpleAPISelf *SimpleAPIDef, method string, relativeURL string) APINoBody[R] {
return APINoBody[R](func(pathParam PathParam, target *R) *fpgo.MonadIODef[*APIResponse[R]] {
return fpgo.MonadIONewGenerics[*APIResponse[R]](func() *APIResponse[R] {

ctx, cancel := simpleAPISelf.GetSimpleHTTP().GetContextTimeout()
defer cancel()
response := simpleAPISelf.simpleHTTP.DoNewRequest(ctx, simpleAPISelf.DefaultHeader.Clone(), method, simpleAPISelf.replacePathParams(relativeURL, pathParam))
Expand Down
10 changes: 4 additions & 6 deletions network/simpleHTTP_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func TestSimpleAPI(t *testing.T) {
var actualContentType string

postsHandler := http.HandlerFunc(func(writer http.ResponseWriter, req *http.Request) {

actualRequestBody, _ = ioutil.ReadAll(req.Body)

// auth := req.Header.Get("Auth")
Expand Down Expand Up @@ -172,7 +171,6 @@ func TestSimpleAPIMultipart(t *testing.T) {
var actualContentType string

postsHandler := http.HandlerFunc(func(writer http.ResponseWriter, req *http.Request) {

actualRequestBody, _ = ioutil.ReadAll(req.Body)

// auth := req.Header.Get("Auth")
Expand Down Expand Up @@ -211,8 +209,8 @@ func TestSimpleAPIMultipart(t *testing.T) {

actualContentType = ""
postsPost := APIMakePostMultipartBody[PostListResponse](api, "posts")
sentValues = map[string][]string{"userId": []string{"0"}, "id": []string{"5"}, "title": []string{"aa"}, "body": []string{""}}
sentFiles := map[string][]string{"file": []string{filePath}}
sentValues = map[string][]string{"userId": {"0"}, "id": {"5"}, "title": {"aa"}, "body": {""}}
sentFiles := map[string][]string{"file": {filePath}}
apiResponse = postsPost(nil, &MultipartForm{Value: sentValues, File: sentFiles}, &PostListResponse{}).Eval()
assert.Equal(t, nil, apiResponse.Err)
_, params, _ = mime.ParseMediaType(actualContentType)
Expand All @@ -223,7 +221,7 @@ func TestSimpleAPIMultipart(t *testing.T) {

actualContentType = ""
postsPut := APIMakePutMultipartBody[PostListResponse](api, "posts")
sentValues = map[string][]string{"userId": []string{"0"}, "id": []string{"4"}, "title": []string{"bb"}, "body": []string{""}}
sentValues = map[string][]string{"userId": {"0"}, "id": {"4"}, "title": {"bb"}, "body": {""}}
apiResponse = postsPut(nil, &MultipartForm{Value: sentValues}, &PostListResponse{}).Eval()
assert.Equal(t, nil, apiResponse.Err)
_, params, _ = mime.ParseMediaType(actualContentType)
Expand All @@ -234,7 +232,7 @@ func TestSimpleAPIMultipart(t *testing.T) {

actualContentType = ""
postsPatch := APIMakePatchMultipartBody[PostListResponse](api, "posts")
sentValues = map[string][]string{"userId": []string{"0"}, "id": []string{"3"}, "title": []string{"cc"}, "body": []string{""}}
sentValues = map[string][]string{"userId": {"0"}, "id": {"3"}, "title": {"cc"}, "body": {""}}
apiResponse = postsPatch(nil, &MultipartForm{Value: sentValues}, &PostListResponse{}).Eval()
assert.Equal(t, nil, apiResponse.Err)
_, params, _ = mime.ParseMediaType(actualContentType)
Expand Down
1 change: 1 addition & 0 deletions publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (publisherSelf *PublisherDef[T]) Publish(result T) {
}
}
}

func (publisherSelf *PublisherDef[T]) doSubscribeSafe(fn func()) {
publisherSelf.subscribeM.Lock()
fn()
Expand Down
4 changes: 2 additions & 2 deletions publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func TestPublisher(t *testing.T) {
p := Publisher.New()
p2 := p

var actual = 0
var expected = 0
actual := 0
expected := 0
assert.Equal(t, expected, actual)
assert.Equal(t, true, s == nil)

Expand Down
2 changes: 2 additions & 0 deletions queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ func (q *BufferedChannelQueue[T]) freeNodePool() {
}
}
}

func (q *BufferedChannelQueue[T]) loadFromPool() {
for range q.loadWorkerCh {

Expand Down Expand Up @@ -532,6 +533,7 @@ func (q *BufferedChannelQueue[T]) loadFromPool() {

}
}

func (q *BufferedChannelQueue[T]) notifyWorkers() {
q.lock.RLock()
if q.pool.Count() > 0 {
Expand Down
Loading

0 comments on commit 0b406e4

Please sign in to comment.