{"id":26021905,"url":"https://github.com/beeleelee/list","last_synced_at":"2025-07-04T16:08:11.130Z","repository":{"id":84668765,"uuid":"197141752","full_name":"beeleelee/list","owner":"beeleelee","description":"Collection manipulation utilities.","archived":false,"fork":false,"pushed_at":"2019-09-09T07:24:51.000Z","size":94,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-31T17:28:24.427Z","etag":null,"topics":["functional-programming","go","golang","underscore"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beeleelee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-16T07:19:25.000Z","updated_at":"2019-07-29T09:14:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"16961b32-47e7-45bf-8d77-63af82c687f3","html_url":"https://github.com/beeleelee/list","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beeleelee%2Flist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beeleelee%2Flist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beeleelee%2Flist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beeleelee%2Flist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beeleelee","download_url":"https://codeload.github.com/beeleelee/list/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242187633,"owners_count":20086217,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["functional-programming","go","golang","underscore"],"created_at":"2025-03-06T09:53:28.828Z","updated_at":"2025-03-06T09:53:29.338Z","avatar_url":"https://github.com/beeleelee.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"Package list\n\n\tlist provide some useful utilities\n\n\tin order to manipulate collection conveniently\n\n\tin the form of functional programming\n\n\thope it will be helpful\n\n\nExample\n\n``` package main\n\n    import (\n\n\t\"fmt\"\n\tlee \"github.com/beeleelee/list\"\n\n    )\n\n    func main() {\n\n\tintList, _ := lee.From([]int{0,1,2})\n\t// list.Each\n\tintList.Each(func(v lee.Item, i int){\n\t\tfmt.Println(v, i)\n\t})\n\t// lee.Each(intList, func(v lee.Item, i int){\n\t// \tfmt.Println(v, i)\n\t// })\n\n\t//\t0 0\n\t//\t1 1\n\t//\t2 2\n\n\t// list.Map\n\tintListMapped := intList.Map(func(v lee.Item, i int) lee.Item {\n\t\treturn v.(int) * 2\n\t})\n\t// intListMapped := lee.Map(intList, func(v lee.Item, i int) lee.Item {\n\t// \treturn v.(int) * 2\n\t// })\n\n\tfmt.Println(intListMapped)\n\t// [0 2 4]\n\n\t// list.Filter\n\tintListFiltered := intList.Filter(func(v lee.Item, i int) bool {\n\t\treturn v.(int) % 2 == 1\n\t})\n\n\t// intListFiltered := lee.Filter(intList, func(v lee.Item, i int) bool {\n\t// \treturn v.(int) % 2 == 1\n\t// })\n\n\tfmt.Println(intListFiltered)\n\t// [1]\n\n\tlee.FromInts([]int{1,2,3,4,5})\n\t\t.Reduce(func(a, b lee.Item) lee.Item {\n\t\t\treturn a.(int) + b.(int)\n\t\t}, nil)\n\t// 15\n\n\tlee.FromInts([]int{3,6,9,12})\n\t\t.Intersection(leeFromInts([]{2,4,6,8,10,12}), func(a, b lee.Item) bool {\n\t\t\treturn a == b\n\t\t})\n\t// [6,12]\n\n    } \n```\n\nFUNCTIONS\n\nfunc Contains(list List, f ItemTestFn) (r bool)\n    Contains - like Find\n\n    return true if find the item return false if can not find the item\n\nfunc Each(list List, f EachFn)\n    Each - each loop\n\n    use for loop to get item from list and feed item to EachFn\n\nfunc Equal(s, t List, f EqualFn) (r bool)\n    Equal - a way to compare whether two list is equal\n\n    it accept a EqualFn which handle the equal logic\n\nfunc Every(list List, f ItemTestFn) (r bool)\n    Every - return true if every item pass test\n\nfunc FindIndex(list List, f ItemTestFn) (index int)\n    FindIndex - a way to find the index of a specific item\n\n\tit return -1 if could not find the item\n\tit accept a ItemTestFn which will specific the item\n\nfunc IsSorted(list List, f LessFn) bool\n    IsSorted - convenience wrapper for std sort.SliceIsSorted\n\nfunc Some(list List, f ItemTestFn) (r bool)\n    Some - return true if any item pass test\n\nfunc Sort(list List, f LessFn)\n    Sort - convenience wrapper for std sort.Slice\n\nTYPES\n\ntype EachFn func(Item, int)\n    EachFn each loop handle signature\n\n    func(v Item, i int){\n\n\t// switch value to the expected type\n\tsv, _ := v.(int) // just for example, actually can use any type you specified\n\tfmt.Println(sv)\n\n    }\n\ntype EqualFn func(a, b Item) bool\n    EqualFn compare handle signature\n\n    func(a, b Item) bool {\n\n\treturn a == b\n\n    }\n\ntype Item interface{}\n    Item - generic type for list item\n\n    in order to accept any type of item in collection\n\nfunc Find(list List, f ItemTestFn) (r Item, ok bool)\n    Find - like FindIndex, but not return index of item\n\n    it returns the specific item and ok flag\n\nfunc Get(list List, i int) Item\n    Get - get item from list it can accept negative int as index, like -1\n    attention: it will never failed if then index out of range, or no item\n    in list, it will return nil\n\nfunc Reduce(list List, f ReduceFn, a Item) (r Item)\n    Reduce - fold the list\n\ntype ItemTestFn func(Item, int) bool\n    ItemTestFn filter loop handle signature\n\n    func(v Item, i int) bool {\n\n\tsv := v.(string)\n\treturn sv == \"foo\"\n\n    }\n\ntype LessFn func(i, j int) bool\n    LessFn same signature as sort.Less\n\ntype List []Item\n    List a struct wrap collection in Data field\n\nfunc Difference(s List, t List, f EqualFn) (r List)\n    Difference - return a list with items not in the other list\n\nfunc Filter(list List, f ItemTestFn) List\n    Filter - filter loop\n\n    first create a new list then use each loop to get item from list and\n    feed item to ItemTestFn which decide weather keep it or not\n\nfunc From(source interface{}) (nl List, e error)\n    From - convert regular slice to List\n\n\tas do not know the item type in the slic\n\tso use reflect package to get the item type\n\tand rebuild a new slice with Item type\n\n\tcall it like this:\n\tlist.From([]int{1,2,3})\n\nfunc FromFloat64s(source []float64) (nl List)\n    FromFloat64s convert float64 slice to List\n\nfunc FromInts(source []int) (nl List)\n    FromInts convert int slice to List\n\nfunc FromStrings(source []string) (nl List)\n    FromStrings convert string slice to List\n\nfunc Intersection(s List, t List, f EqualFn) (r List)\n    Intersection - return a list with items in both list\n\nfunc Map(list List, f MapFn) List\n    Map - map loop\n\n    use for loop to get item from list and feed item to MapFn\n\nfunc New(length int) List\n    New generate a new List instance\n\nfunc Shuffle(list List) (r List)\n    Shuffle - return a shuffled list\n\nfunc Tail(list List, n int) List\n    Tail - get items from last\n\nfunc Union(s List, t List) List\n    Union - union two lists\n\nfunc (l List) Contains(f ItemTestFn) bool\n    Contains convenience wrapper for Contains function\n\nfunc (l List) Difference(t List, f EqualFn) List\n    Difference convenience wrapper for Difference Function\n\nfunc (l List) Each(f EachFn) List\n    Each convenience wrapper for Each function\n\nfunc (l List) Equal(t List, f EqualFn) bool\n    Equal convenience wrapper for Equal function\n\nfunc (l List) Every(f ItemTestFn) bool\n    Every convenience wrapper for Every Function\n\nfunc (l List) Filter(f ItemTestFn) List\n    Filter convenience wrapper for Filter function\n\nfunc (l List) Find(f ItemTestFn) (Item, bool)\n    Find convenience wrapper for Find function\n\nfunc (l List) FindIndex(f ItemTestFn) int\n    FindIndex convenience wrapper for FindIndex function\n\nfunc (l List) Get(i int) Item\n    Get convenience wrapper for Get Function\n\nfunc (l List) Intersection(t List, f EqualFn) List\n    Intersection convenience wrapper for Intersection Function\n\nfunc (l List) IsSorted(f LessFn) bool\n    IsSorted convenience wrapper for std sort.SliceIsSorted\n\nfunc (l List) Map(f MapFn) List\n    Map convenience wrapper for Map function\n\nfunc (l List) Reduce(f ReduceFn, a Item) Item\n    Reduce convenience wrapper for Reduce function\n\nfunc (l List) Shuffle() List\n    Shuffle convenience wrapper for Shuffle Function\n\nfunc (l List) Some(f ItemTestFn) bool\n    Some convenience wrapper for Some Function\n\nfunc (l List) Sort(f LessFn) List\n    Sort convenience wrapper for std sort.Slice\n\nfunc (l List) Tail(n int) List\n    Tail convenience wrapper for Tail Function\n\nfunc (l List) Union(t List) List\n    Union convenience wrapper for Union Function\n\ntype MapFn func(Item, int) Item\n    MapFn map loop handle signature\n\n    func(v Item, i int) (item Item) {\n\n\tsv, _ := v.(float64)\n\treturn sv * sv\n\n    }\n\ntype ReduceFn func(a, b Item) Item\n    ReduceFn reduce handle signature\n\ntype SwapFn func(i, j int)\n    SwapFn swap items by index","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeeleelee%2Flist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeeleelee%2Flist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeeleelee%2Flist/lists"}