{"id":13414147,"url":"https://github.com/thoas/go-funk","last_synced_at":"2025-05-11T03:43:58.609Z","repository":{"id":37663406,"uuid":"77689140","full_name":"thoas/go-funk","owner":"thoas","description":"A modern Go utility library which provides helpers (map, find, contains, filter, ...)","archived":false,"fork":false,"pushed_at":"2024-07-24T11:49:17.000Z","size":326,"stargazers_count":4893,"open_issues_count":8,"forks_count":275,"subscribers_count":39,"default_branch":"main","last_synced_at":"2025-05-07T23:06:30.948Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/thoas.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.md","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":"2016-12-30T13:55:15.000Z","updated_at":"2025-04-29T03:31:09.000Z","dependencies_parsed_at":"2024-05-05T03:30:40.966Z","dependency_job_id":"f734b849-d5ad-4a77-949f-aee8bc632db3","html_url":"https://github.com/thoas/go-funk","commit_stats":{"total_commits":276,"total_committers":55,"mean_commits":"5.0181818181818185","dds":0.5,"last_synced_commit":"4107456c7aeb9c56439474a6917ccea36365b869"},"previous_names":["thoas/go-fn"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoas%2Fgo-funk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoas%2Fgo-funk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoas%2Fgo-funk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoas%2Fgo-funk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thoas","download_url":"https://codeload.github.com/thoas/go-funk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252968118,"owners_count":21833251,"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":[],"created_at":"2024-07-30T20:01:59.121Z","updated_at":"2025-05-07T23:06:35.558Z","avatar_url":"https://github.com/thoas.png","language":"Go","funding_links":[],"categories":["Utilities","Go","开源类库","Utility","Open source library","公用事业公司","实用工具","工具库","工具库`可以提升效率的通用代码库和工具`","\u003ca name=\"Go\"\u003e\u003c/a\u003eGo"],"sub_categories":["Utility/Miscellaneous","开发辅助包","Development Aid Package","HTTP Clients","实用程序/Miscellaneous","Advanced Console UIs","查询语","交流","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","Fail injection"],"readme":"go-funk\n=======\n\n.. image:: https://secure.travis-ci.org/thoas/go-funk.svg?branch=master\n    :alt: Build Status\n    :target: http://travis-ci.org/thoas/go-funk\n\n.. image:: https://godoc.org/github.com/thoas/go-funk?status.svg\n    :alt: GoDoc\n    :target: https://pkg.go.dev/github.com/thoas/go-funk\n\n.. image:: https://goreportcard.com/badge/github.com/thoas/go-funk\n    :alt: Go report\n    :target: https://goreportcard.com/report/github.com/thoas/go-funk\n\n``go-funk`` is a modern Go library based on reflect_.\n\nGeneric helpers rely on reflect_, be careful this code runs exclusively on runtime so you must have a good test suite.\n\nThese helpers have started as an experiment to learn reflect_. It may look like lodash_ in some aspects but\nit will have its own roadmap. lodash_ is an awesome library with a lot of work behind it, all features included in\n``go-funk`` come from internal use cases.\n\nYou can also find typesafe implementation in the godoc_.\n\nWhy this name?\n--------------\n\nLong story, short answer because ``func`` is a reserved word in Go, I wanted something similar.\n\nInitially this project was named ``fn`` I don't need to explain why that was a bad idea for french speakers :)\n\nLet's ``funk``!\n\n.. image:: https://media.giphy.com/media/3oEjHQKtDXpeGN9rW0/giphy.gif\n\n\u003c3\n\nInstallation\n------------\n\n.. code-block:: bash\n\n    go get github.com/thoas/go-funk\n\nUsage\n-----\n\n.. code-block:: go\n\n    import \"github.com/thoas/go-funk\"\n\nThese examples will be based on the following data model:\n\n.. code-block:: go\n\n    type Foo struct {\n        ID        int\n        FirstName string `tag_name:\"tag 1\"`\n        LastName  string `tag_name:\"tag 2\"`\n        Age       int    `tag_name:\"tag 3\"`\n    }\n\n    func (f Foo) TableName() string {\n        return \"foo\"\n    }\n\nWith fixtures:\n\n.. code-block:: go\n\n    f := \u0026Foo{\n        ID:        1,\n        FirstName: \"Foo\",\n        LastName:  \"Bar\",\n        Age:       30,\n    }\n\nYou can import ``go-funk`` using a basic statement:\n\n.. code-block:: go\n\n    import \"github.com/thoas/go-funk\"\n\nfunk.Contains\n.............\n\nReturns true if an element is present in a iteratee (slice, map, string).\n\nOne frustrating thing in Go is to implement ``contains`` methods for each type, for example:\n\n.. code-block:: go\n\n    func ContainsInt(s []int, e int) bool {\n        for _, a := range s {\n            if a == e {\n                return true\n            }\n        }\n        return false\n    }\n\nthis can be replaced by ``funk.Contains``:\n\n.. code-block:: go\n\n    // slice of string\n    funk.Contains([]string{\"foo\", \"bar\"}, \"bar\") // true\n\n    // slice of Foo ptr\n    funk.Contains([]*Foo{f}, f) // true\n    funk.Contains([]*Foo{f}, func (foo *Foo) bool {\n        return foo.ID == f.ID\n    }) // true\n    funk.Contains([]*Foo{f}, nil) // false\n\n    b := \u0026Foo{\n        ID:        2,\n        FirstName: \"Florent\",\n        LastName:  \"Messa\",\n        Age:       28,\n    }\n\n    funk.Contains([]*Foo{f}, b) // false\n\n    // string\n    funk.Contains(\"florent\", \"rent\") // true\n    funk.Contains(\"florent\", \"foo\") // false\n\n    // even map\n    funk.Contains(map[int]string{1: \"Florent\"}, 1) // true\n    funk.Contains(map[int]string{1: \"Florent\"}, func(key int, name string) bool {\n        return key == 1 // or `name == \"Florent\"` for the value type\n    }) // true\n\nsee also, typesafe implementations: ContainsInt_, ContainsInt64_, ContainsFloat32_, ContainsFloat64_, ContainsString_\n\n.. _ContainsFloat32: https://godoc.org/github.com/thoas/go-funk#ContainsFloat32\n.. _ContainsFloat64: https://godoc.org/github.com/thoas/go-funk#ContainsFloat64\n.. _ContainsInt: https://godoc.org/github.com/thoas/go-funk#ContainsInt\n.. _ContainsInt64: https://godoc.org/github.com/thoas/go-funk#ContainsInt64\n.. _ContainsString: https://godoc.org/github.com/thoas/go-funk#ContainsString\n\nfunk.Intersect\n..............\n\nReturns the intersection between two collections.\n\n.. code-block:: go\n\n    funk.Intersect([]int{1, 2, 3, 4}, []int{2, 4, 6})  // []int{2, 4}\n    funk.Intersect([]string{\"foo\", \"bar\", \"hello\", \"bar\"}, []string{\"foo\", \"bar\"})  // []string{\"foo\", \"bar\"}\n\nsee also, typesafe implementations: IntersectString\n\n.. IntersectString: https://godoc.org/github.com/thoas/go-funk#IntersectString\n\n\nfunk.Difference\n..............\n\nReturns the difference between two collections.\n\n.. code-block:: go\n\n    funk.Difference([]int{1, 2, 3, 4}, []int{2, 4, 6})  // []int{1, 3}, []int{6}\n    funk.Difference([]string{\"foo\", \"bar\", \"hello\", \"bar\"}, []string{\"foo\", \"bar\"})  // []string{\"hello\"}, []string{}\n\nsee also, typesafe implementations: DifferenceString\n\n.. DifferenceString: https://godoc.org/github.com/thoas/go-funk#DifferenceString\n\n\nfunk.IndexOf\n............\n\nGets the index at which the first occurrence of a value is found in an array or return -1\nif the value cannot be found.\n\n.. code-block:: go\n\n    // slice of string\n    funk.IndexOf([]string{\"foo\", \"bar\"}, \"bar\") // 1\n    funk.IndexOf([]string{\"foo\", \"bar\"}, func(value string) bool {\n        return value == \"bar\"\n    }) // 1\n    funk.IndexOf([]string{\"foo\", \"bar\"}, \"gilles\") // -1\n\nsee also, typesafe implementations: IndexOfInt_, IndexOfInt64_, IndexOfFloat32_, IndexOfFloat64_, IndexOfString_\n\n.. _IndexOfFloat32: https://godoc.org/github.com/thoas/go-funk#IndexOfFloat32\n.. _IndexOfFloat64: https://godoc.org/github.com/thoas/go-funk#IndexOfFloat64\n.. _IndexOfInt: https://godoc.org/github.com/thoas/go-funk#IndexOfInt\n.. _IndexOfInt64: https://godoc.org/github.com/thoas/go-funk#IndexOfInt64\n.. _IndexOfString: https://godoc.org/github.com/thoas/go-funk#IndexOfString\n\nfunk.LastIndexOf\n................\n\nGets the index at which the last occurrence of a value is found in an array or return -1\nif the value cannot be found.\n\n.. code-block:: go\n\n    // slice of string\n    funk.LastIndexOf([]string{\"foo\", \"bar\", \"bar\"}, \"bar\") // 2\n    funk.LastIndexOf([]string{\"foo\", \"bar\", \"bar\"}, func(value string) bool {\n        return value == \"bar\"\n    }) // 2\n    funk.LastIndexOf([]string{\"foo\", \"bar\"}, \"gilles\") // -1\n\nsee also, typesafe implementations: LastIndexOfInt_, LastIndexOfInt64_, LastIndexOfFloat32_, LastIndexOfFloat64_, LastIndexOfString_\n\n.. _LastIndexOfFloat32: https://godoc.org/github.com/thoas/go-funk#LastIndexOfFloat32\n.. _LastIndexOfFloat64: https://godoc.org/github.com/thoas/go-funk#LastIndexOfFloat64\n.. _LastIndexOfInt: https://godoc.org/github.com/thoas/go-funk#LastIndexOfInt\n.. _LastIndexOfInt64: https://godoc.org/github.com/thoas/go-funk#LastIndexOfInt64\n.. _LastIndexOfString: https://godoc.org/github.com/thoas/go-funk#LastIndexOfString\n\nfunk.ToMap\n..........\n\nTransforms a slice or an array of structs to a map based on a ``pivot`` field.\n\n.. code-block:: go\n\n    f := \u0026Foo{\n        ID:        1,\n        FirstName: \"Gilles\",\n        LastName:  \"Fabio\",\n        Age:       70,\n    }\n\n    b := \u0026Foo{\n        ID:        2,\n        FirstName: \"Florent\",\n        LastName:  \"Messa\",\n        Age:       80,\n    }\n\n    results := []*Foo{f, b}\n\n    mapping := funk.ToMap(results, \"ID\") // map[int]*Foo{1: f, 2: b}\n\nfunk.ToSet\n..........\n\nTransforms an array or a slice to a set (a map with zero-size values).\n\n.. code-block:: go\n\n    f := Foo{\n        ID:        1,\n        FirstName: \"Gilles\",\n        LastName:  \"Fabio\",\n        Age:       70,\n    }\n\n    b := Foo{\n        ID:        2,\n        FirstName: \"Florent\",\n        LastName:  \"Messa\",\n        Age:       80,\n    }\n\n    mapping := funk.ToSet([]Foo{f, b}) // map[Foo]stuct{}{f: struct{}{}, b: struct{}{}}\n\n    mapping := funk.ToSet([4]int{1, 1, 2, 2}) // map[int]struct{}{1: struct{}{}, 2: struct{}{}}\n\n\n\nfunk.Filter\n...........\n\nFilters a slice based on a predicate.\n\n.. code-block:: go\n\n    r := funk.Filter([]int{1, 2, 3, 4}, func(x int) bool {\n        return x%2 == 0\n    }) // []int{2, 4}\n\nsee also, typesafe implementations: FilterInt_, FilterInt64_, FilterFloat32_, FilterFloat64_, FilterString_\n\n.. _FilterFloat32: https://godoc.org/github.com/thoas/go-funk#FilterFloat32\n.. _FilterFloat64: https://godoc.org/github.com/thoas/go-funk#FilterFloat64\n.. _FilterInt: https://godoc.org/github.com/thoas/go-funk#FilterInt\n.. _FilterInt64: https://godoc.org/github.com/thoas/go-funk#FilterInt64\n.. _FilterString: https://godoc.org/github.com/thoas/go-funk#FilterString\n\nfunk.Reduce\n...........\n\nReduces an iteratee based on an accumulator function or operation rune for numbers.\n\n.. code-block:: go\n\n    // Using operation runes. '+' and '*' only supported.\n    r := funk.Reduce([]int{1, 2, 3, 4}, '+', float64(0)) // 10\n    r := funk.Reduce([]int{1, 2, 3, 4}, '*', 1) // 24\n\n    // Using accumulator function\n    r := funk.Reduce([]int{1, 2, 3, 4}, func(acc float64, num int) float64 {\n        return acc + float64(num)\n    }, float64(0)) // 10\n\n    r := funk.Reduce([]int{1, 2, 3, 4}, func(acc string, num int) string {\n        return acc + fmt.Sprint(num)\n    }, \"\") // \"1234\"\n\nfunk.Find\n.........\n\nFinds an element in a slice based on a predicate.\n\n.. code-block:: go\n\n    r := funk.Find([]int{1, 2, 3, 4}, func(x int) bool {\n        return x%2 == 0\n    }) // 2\n\nsee also, typesafe implementations: FindInt_, FindInt64_, FindFloat32_, FindFloat64_, FindString_\n\n.. _FindFloat32: https://godoc.org/github.com/thoas/go-funk#FindFloat32\n.. _FindFloat64: https://godoc.org/github.com/thoas/go-funk#FindFloat64\n.. _FindInt: https://godoc.org/github.com/thoas/go-funk#FindInt\n.. _FindInt64: https://godoc.org/github.com/thoas/go-funk#FindInt64\n.. _FindString: https://godoc.org/github.com/thoas/go-funk#FindString\n\nfunk.Map\n........\n\nManipulates an iteratee (map, slice) and transforms it to another type:\n\n* map -\u003e slice\n* map -\u003e map\n* slice -\u003e map\n* slice -\u003e slice\n\n.. code-block:: go\n\n    r := funk.Map([]int{1, 2, 3, 4}, func(x int) int {\n        return x * 2\n    }) // []int{2, 4, 6, 8}\n\n    r := funk.Map([]int{1, 2, 3, 4}, func(x int) string {\n        return \"Hello\"\n    }) // []string{\"Hello\", \"Hello\", \"Hello\", \"Hello\"}\n\n    r = funk.Map([]int{1, 2, 3, 4}, func(x int) (int, int) {\n        return x, x\n    }) // map[int]int{1: 1, 2: 2, 3: 3, 4: 4}\n\n    mapping := map[int]string{\n        1: \"Florent\",\n        2: \"Gilles\",\n    }\n\n    r = funk.Map(mapping, func(k int, v string) int {\n        return k\n    }) // []int{1, 2}\n\n    r = funk.Map(mapping, func(k int, v string) (string, string) {\n        return fmt.Sprintf(\"%d\", k), v\n    }) // map[string]string{\"1\": \"Florent\", \"2\": \"Gilles\"}\n\nfunk.FlatMap\n............\n\nManipulates an iteratee (map, slice) and transforms it to to a flattened collection of another type:\n\n* map -\u003e slice\n* slice -\u003e slice\n\n.. code-block:: go\n\n    r := funk.FlatMap([][]int{{1, 2}, {3, 4}}, func(x []int) []int {\n        return append(x, 0)\n    }) // []int{1, 2, 0, 3, 4, 0}\n\n    mapping := map[string][]int{\n        \"Florent\": {1, 2},\n        \"Gilles\": {3, 4},\n    }\n\n    r = funk.FlatMap(mapping, func(k string, v []int) []int {\n        return v\n    }) // []int{1, 2, 3, 4}\n\nfunk.Get\n........\n\nRetrieves the value at path of struct(s) or map(s).\n\n.. code-block:: go\n\n    var bar *Bar = \u0026Bar{\n        Name: \"Test\",\n        Bars: []*Bar{\n            \u0026Bar{\n                Name: \"Level1-1\",\n                Bar: \u0026Bar{\n                    Name: \"Level2-1\",\n                },\n            },\n            \u0026Bar{\n                Name: \"Level1-2\",\n                Bar: \u0026Bar{\n                    Name: \"Level2-2\",\n                },\n            },\n        },\n    }\n\n    var foo *Foo = \u0026Foo{\n        ID:        1,\n        FirstName: \"Dark\",\n        LastName:  \"Vador\",\n        Age:       30,\n        Bar:       bar,\n        Bars: []*Bar{\n            bar,\n            bar,\n        },\n    }\n\n    funk.Get([]*Foo{foo}, \"Bar.Bars.Bar.Name\") // []string{\"Level2-1\", \"Level2-2\"}\n    funk.Get(foo, \"Bar.Bars.Bar.Name\") // []string{\"Level2-1\", \"Level2-2\"}\n    funk.Get(foo, \"Bar.Name\") // Test\n\n``funk.Get`` also support ``map`` values:\n\n.. code-block:: go\n\n    bar := map[string]interface{}{\n        \"Name\": \"Test\",\n    }\n\n    foo1 := map[string]interface{}{\n        \"ID\":        1,\n        \"FirstName\": \"Dark\",\n        \"LastName\":  \"Vador\",\n        \"Age\":       30,\n        \"Bar\":       bar,\n    }\n\n    foo2 := \u0026map[string]interface{}{\n        \"ID\":        1,\n        \"FirstName\": \"Dark\",\n        \"LastName\":  \"Vador\",\n        \"Age\":       30,\n        \"Labels\": map[string]interface{} {\n            \"example.com/hello\": \"world\",\n        },\n    } // foo2.Bar is nil\n\n    funk.Get(bar, \"Name\") // \"Test\"\n    funk.Get([]map[string]interface{}{foo1, foo2}, \"Bar.Name\") // []string{\"Test\"}\n    funk.Get(foo2, \"Bar.Name\") // nil\n    funk.Get(foo2, `Labels.\"example.com/hello\"`) // world\n\n\n``funk.Get`` also handles ``nil`` values:\n\n.. code-block:: go\n\n    bar := \u0026Bar{\n        Name: \"Test\",\n    }\n\n    foo1 := \u0026Foo{\n        ID:        1,\n        FirstName: \"Dark\",\n        LastName:  \"Vador\",\n        Age:       30,\n        Bar:       bar,\n    }\n\n    foo2 := \u0026Foo{\n        ID:        1,\n        FirstName: \"Dark\",\n        LastName:  \"Vador\",\n        Age:       30,\n    } // foo2.Bar is nil\n\n    funk.Get([]*Foo{foo1, foo2}, \"Bar.Name\") // []string{\"Test\"}\n    funk.Get(foo2, \"Bar.Name\") // nil\n\n\n\nfunk.GetOrElse\n..............\n\nRetrieves the value of the pointer or default.\n\n.. code-block:: go\n\n    str := \"hello world\"\n    GetOrElse(\u0026str, \"foobar\")   // string{\"hello world\"}\n    GetOrElse(str, \"foobar\")    // string{\"hello world\"}\n    GetOrElse(nil, \"foobar\")    // string{\"foobar\"}\n\nfunk.Set\n........\nSet value at a path of a struct\n\n.. code-block:: go\n\n    var bar Bar = Bar{\n        Name: \"level-0\",\n        Bar: \u0026Bar{\n            Name: \"level-1\",\n            Bars: []*Bar{\n                {Name: \"level2-1\"},\n                {Name: \"level2-2\"},\n            },\n        },\n    }\n\n    _ = Set(\u0026bar, \"level-0-new\", \"Name\")\n    fmt.Println(bar.Name) // \"level-0-new\"\n\n    MustSet(\u0026bar, \"level-1-new\", \"Bar.Name\")\n    fmt.Println(bar.Bar.Name) // \"level-1-new\"\n\n    Set(\u0026bar, \"level-2-new\", \"Bar.Bars.Name\")\n    fmt.Println(bar.Bar.Bars[0].Name) // \"level-2-new\"\n    fmt.Println(bar.Bar.Bars[1].Name) // \"level-2-new\"\n\nfunk.MustSet\n............\nShort hand for funk.Set if struct does not contain interface{} field type to discard errors.\n\nfunk.Prune\n..........\nCopy a struct with only selected fields. Slice is handled by pruning all elements.\n\n.. code-block:: go\n\n    bar := \u0026Bar{\n        Name: \"Test\",\n    }\n\n    foo1 := \u0026Foo{\n        ID:        1,\n        FirstName: \"Dark\",\n        LastName:  \"Vador\",\n        Bar:       bar,\n    }\n\n    pruned, _ := Prune(foo1, []string{\"FirstName\", \"Bar.Name\"})\n    // *Foo{\n    //    ID:        0,\n    //    FirstName: \"Dark\",\n    //    LastName:  \"\",\n    //    Bar:       \u0026Bar{Name: \"Test},\n    // }\n\nfunk.PruneByTag\n..........\nSame functionality as funk.Prune, but uses struct tags instead of struct field names.\n\nfunk.Keys\n.........\n\nCreates an array of the own enumerable map keys or struct field names.\n\n.. code-block:: go\n\n    funk.Keys(map[string]int{\"one\": 1, \"two\": 2}) // []string{\"one\", \"two\"} (iteration order is not guaranteed)\n\n    foo := \u0026Foo{\n        ID:        1,\n        FirstName: \"Dark\",\n        LastName:  \"Vador\",\n        Age:       30,\n    }\n\n    funk.Keys(foo) // []string{\"ID\", \"FirstName\", \"LastName\", \"Age\"} (iteration order is not guaranteed)\n\nfunk.Values\n...........\n\nCreates an array of the own enumerable map values or struct field values.\n\n.. code-block:: go\n\n    funk.Values(map[string]int{\"one\": 1, \"two\": 2}) // []int{1, 2} (iteration order is not guaranteed)\n\n    foo := \u0026Foo{\n        ID:        1,\n        FirstName: \"Dark\",\n        LastName:  \"Vador\",\n        Age:       30,\n    }\n\n    funk.Values(foo) // []interface{}{1, \"Dark\", \"Vador\", 30} (iteration order is not guaranteed)\n\nfunk.ForEach\n............\n\nRange over an iteratee (map, slice).\n\nOr update element in slice(Not map, reflect#Value#MapIndex#CanSet is false).\n\n.. code-block:: go\n\n    funk.ForEach([]int{1, 2, 3, 4}, func(x int) {\n        fmt.Println(x)\n    })\n\n    foo := []int{1,2,3}\n    funk.ForEach(foo, func(x *int){ *x = *x * 2})\n    fmt.Println(foo) // []int{2, 4, 6}\n\nfunk.ForEachRight\n............\n\nRange over an iteratee (map, slice) from the right.\n\n.. code-block:: go\n\n    results := []int{}\n\n    funk.ForEachRight([]int{1, 2, 3, 4}, func(x int) {\n        results = append(results, x)\n    })\n\n    fmt.Println(results) // []int{4, 3, 2, 1}\n\nfunk.Chunk\n..........\n\nCreates an array of elements split into groups with the length of the size.\nIf array can't be split evenly, the final chunk will be the remaining element.\n\n.. code-block:: go\n\n    funk.Chunk([]int{1, 2, 3, 4, 5}, 2) // [][]int{[]int{1, 2}, []int{3, 4}, []int{5}}\n\nfunk.FlattenDeep\n................\n\nRecursively flattens an array.\n\n.. code-block:: go\n\n    funk.FlattenDeep([][]int{[]int{1, 2}, []int{3, 4}}) // []int{1, 2, 3, 4}\n\nfunk.Uniq\n.........\n\nCreates an array with unique values.\n\n.. code-block:: go\n\n    funk.Uniq([]int{0, 1, 1, 2, 3, 0, 0, 12}) // []int{0, 1, 2, 3, 12}\n\nsee also, typesafe implementations: UniqInt_, UniqInt64_, UniqFloat32_, UniqFloat64_, UniqString_\n\n.. _UniqFloat32: https://godoc.org/github.com/thoas/go-funk#UniqFloat32\n.. _UniqFloat64: https://godoc.org/github.com/thoas/go-funk#UniqFloat64\n.. _UniqInt: https://godoc.org/github.com/thoas/go-funk#UniqInt\n.. _UniqInt64: https://godoc.org/github.com/thoas/go-funk#UniqInt64\n.. _UniqString: https://godoc.org/github.com/thoas/go-funk#UniqString\n\nfunk.UniqBy\n.........\n\nCreates an array with unique values returned by a callback.\n\n.. code-block:: go\n\n    funk.UniqBy([]int{0, 1, 1, 2, 3, 0, 0, 12}, func(nbr int) int {\n\t\treturn nbr % 3\n\t}) // []int{0, 1, 2}\n\n    foo1 := Foo{\n        ID: 42,\n        FirstName: \"Bob\",\n    }\n    foo2 := Foo{\n        ID: 42,\n        FirstName: \"Bob\",\n    }\n    funk.UniqBy([]Foo{foo1, foo2}, func(f Foo) int {\n\t\treturn f.ID\n\t}) // []Foo{ Foo{ID: 42, Firstname: \"Bob\"} }\n\nfunk.Drop\n.........\n\nCreates an array/slice with `n` elements dropped from the beginning.\n\n.. code-block:: go\n\n    funk.Drop([]int{0, 0, 0, 0}, 3) // []int{0}\n\nsee also, typesafe implementations: DropInt_, DropInt32_, DropInt64_, DropFloat32_, DropFloat64_, DropString_\n\n.. _DropInt: https://godoc.org/github.com/thoas/go-funk#DropInt\n.. _DropInt32: https://godoc.org/github.com/thoas/go-funk#DropInt64\n.. _DropInt64: https://godoc.org/github.com/thoas/go-funk#DropInt64\n.. _DropFloat32: https://godoc.org/github.com/thoas/go-funk#DropFloat32\n.. _DropFloat64: https://godoc.org/github.com/thoas/go-funk#DropFloat64\n.. _DropString: https://godoc.org/github.com/thoas/go-funk#DropString\n\nfunk.Initial\n............\n\nGets all but the last element of array.\n\n.. code-block:: go\n\n    funk.Initial([]int{0, 1, 2, 3, 4}) // []int{0, 1, 2, 3}\n\nfunk.Tail\n.........\n\nGets all but the first element of array.\n\n.. code-block:: go\n\n    funk.Tail([]int{0, 1, 2, 3, 4}) // []int{1, 2, 3, 4}\n\nfunk.Shuffle\n............\n\nCreates an array of shuffled values.\n\n.. code-block:: go\n\n    funk.Shuffle([]int{0, 1, 2, 3, 4}) // []int{2, 1, 3, 4, 0}\n\n\nsee also, typesafe implementations: ShuffleInt_, ShuffleInt64_, ShuffleFloat32_, ShuffleFloat64_, ShuffleString_\n\n.. _ShuffleFloat32: https://godoc.org/github.com/thoas/go-funk#ShuffleFloat32\n.. _ShuffleFloat64: https://godoc.org/github.com/thoas/go-funk#ShuffleFloat64\n.. _ShuffleInt: https://godoc.org/github.com/thoas/go-funk#ShuffleInt\n.. _ShuffleInt64: https://godoc.org/github.com/thoas/go-funk#ShuffleInt64\n.. _ShuffleString: https://godoc.org/github.com/thoas/go-funk#ShuffleString\n\nfunk.Subtract\n.............\n\nReturns the subtraction between two collections. It preserve order.\n\n.. code-block:: go\n\n    funk.Subtract([]int{0, 1, 2, 3, 4}, []int{0, 4}) // []int{1, 2, 3}\n    funk.Subtract([]int{0, 3, 2, 3, 4}, []int{0, 4}) // []int{3, 2, 3}\n\n\nsee also, typesafe implementations: SubtractString_\n\n.. SubtractString: https://godoc.org/github.com/thoas/go-funk#SubtractString\n\nfunk.Sum\n........\n\nComputes the sum of the values in an array.\n\n.. code-block:: go\n\n    funk.Sum([]int{0, 1, 2, 3, 4}) // 10.0\n    funk.Sum([]interface{}{0.5, 1, 2, 3, 4}) // 10.5\n\nsee also, typesafe implementations: SumInt_, SumInt64_, SumFloat32_, SumFloat64_\n\n.. _SumFloat32: https://godoc.org/github.com/thoas/go-funk#SumFloat32\n.. _SumFloat64: https://godoc.org/github.com/thoas/go-funk#SumFloat64\n.. _SumInt: https://godoc.org/github.com/thoas/go-funk#SumInt\n.. _SumInt64: https://godoc.org/github.com/thoas/go-funk#SumInt64\n\nfunk.Reverse\n............\n\nTransforms an array such that the first element will become the last, the second element\nwill become the second to last, etc.\n\n.. code-block:: go\n\n    funk.Reverse([]int{0, 1, 2, 3, 4}) // []int{4, 3, 2, 1, 0}\n\nsee also, typesafe implementations: ReverseInt_, ReverseInt64_, ReverseFloat32_, ReverseFloat64_, ReverseString_, ReverseStrings_\n\n.. _ReverseFloat32: https://godoc.org/github.com/thoas/go-funk#ReverseFloat32\n.. _ReverseFloat64: https://godoc.org/github.com/thoas/go-funk#ReverseFloat64\n.. _ReverseInt: https://godoc.org/github.com/thoas/go-funk#ReverseInt\n.. _ReverseInt64: https://godoc.org/github.com/thoas/go-funk#ReverseInt64\n.. _ReverseString: https://godoc.org/github.com/thoas/go-funk#ReverseString\n.. _ReverseStrings: https://godoc.org/github.com/thoas/go-funk#ReverseStrings\n\nfunk.SliceOf\n............\n\nReturns a slice based on an element.\n\n.. code-block:: go\n\n    funk.SliceOf(f) // will return a []*Foo{f}\n\nfunk.RandomInt\n..............\n\nGenerates a random int, based on a min and max values.\n\n.. code-block:: go\n\n    funk.RandomInt(0, 100) // will be between 0 and 100\n\nfunk.RandomString\n.................\n\nGenerates a random string with a fixed length.\n\n.. code-block:: go\n\n    funk.RandomString(4) // will be a string of 4 random characters\n\nfunk.Shard\n..........\n\nGenerates a sharded string with a fixed length and depth.\n\n.. code-block:: go\n\n    funk.Shard(\"e89d66bdfdd4dd26b682cc77e23a86eb\", 1, 2, false) // []string{\"e\", \"8\", \"e89d66bdfdd4dd26b682cc77e23a86eb\"}\n\n    funk.Shard(\"e89d66bdfdd4dd26b682cc77e23a86eb\", 2, 2, false) // []string{\"e8\", \"9d\", \"e89d66bdfdd4dd26b682cc77e23a86eb\"}\n\n    funk.Shard(\"e89d66bdfdd4dd26b682cc77e23a86eb\", 2, 3, true) // []string{\"e8\", \"9d\", \"66\", \"bdfdd4dd26b682cc77e23a86eb\"}\n\nfunk.Subset\n.............\n\nReturns true if a collection is a subset of another\n\n.. code-block:: go\n\n    funk.Subset([]int{1, 2, 4}, []int{1, 2, 3, 4, 5}) // true\n    funk.Subset([]string{\"foo\", \"bar\"},[]string{\"foo\", \"bar\", \"hello\", \"bar\", \"hi\"}) //true\n\n\nPerformance\n-----------\n\n``go-funk`` currently has an open issue about performance_, don't hesitate to participate in the discussion\nto enhance the generic helpers implementations.\n\nLet's stop beating around the bush, a typesafe implementation in pure Go of ``funk.Contains``, let's say for example:\n\n.. code-block:: go\n\n    func ContainsInt(s []int, e int) bool {\n        for _, a := range s {\n            if a == e {\n                return true\n            }\n        }\n        return false\n    }\n\nwill always outperform an implementation based on reflect_ in terms of speed and allocs because of\nhow it's implemented in the language.\n\nIf you want a similarity, gorm_ will always be slower than sqlx_ (which is very low level btw) and will use more allocs.\n\nYou must not think generic helpers of ``go-funk`` as a replacement when you are dealing with performance in your codebase,\nyou should use typesafe implementations instead.\n\nContributing\n------------\n\n* Ping me on twitter `@thoas \u003chttps://twitter.com/thoas\u003e`_ (DMs, mentions, whatever :))\n* Fork the `project \u003chttps://github.com/thoas/go-funk\u003e`_\n* Fix `open issues \u003chttps://github.com/thoas/go-funk/issues\u003e`_ or request new features\n\nDon't hesitate ;)\n\nAuthors\n-------\n\n* Florent Messa\n* Gilles Fabio\n* Alexey Pokhozhaev\n* Alexandre Nicolaie\n\n.. _reflect: https://golang.org/pkg/reflect/\n.. _lodash: https://lodash.com/\n.. _performance: https://github.com/thoas/go-funk/issues/19\n.. _gorm: https://github.com/jinzhu/gorm\n.. _sqlx: https://github.com/jmoiron/sqlx\n.. _godoc: https://godoc.org/github.com/thoas/go-funk\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoas%2Fgo-funk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthoas%2Fgo-funk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoas%2Fgo-funk/lists"}