Skip to content

several suggestions #8

@ggaaooppeenngg

Description

@ggaaooppeenngg

I browsed your code and have some suggestions.

first, I think underscore need a more general function instead of specifying a function for a certain type,for instance in order to map string you need to specify a SMap function pointer.Your code was excellent,could be there any way to implement such general function? such like not returning []interface{},but receive a point of return value as argument,in order to reflect the result.

second, in Each, I think sync.WaitGroup is more comlicated because it is implemented by lock,and why not do like


var done = make(chan struct{}{},m.Len()) //m is the map or slice
for i:= 0;i<s.Len();i++{
    go func(){
        donw <-
    }() 
}

for i:= 0;i<s.Len();i++{
    done <-
}

I thins this dose the same work,but in more Go way.

third, function decleration is not constant,Each has argument name but Map does not which will make some confusion.

fourth chan argument should be more strict ,to spefigy read-only or write-only
reader need argument like job <- chan,which should only read from in the function body.

fifth , jobs in Each should be bufferd capabible of len of workers number,
so that workers will not block on read or write and will be more akin parallel

That's my thoughts,maybe it's wrong or not appropriate,hoping to discuss!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions