{"id":21658475,"url":"https://github.com/logic-building/functional-go","last_synced_at":"2025-07-17T21:31:06.968Z","repository":{"id":48167641,"uuid":"162655897","full_name":"logic-building/functional-go","owner":"logic-building","description":"This library is inspired by functional programming - Clojure","archived":false,"fork":false,"pushed_at":"2023-11-15T16:17:46.000Z","size":1688,"stargazers_count":179,"open_issues_count":0,"forks_count":8,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-06-18T23:17:14.401Z","etag":null,"topics":["difference","exists","filter","functional","functional-go","functional-programming","go-functional","golang","intersection","map","map-filter-in-go","merge","pmap","set","sort","sort-struct","sorting","superset","union","zip"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/logic-building.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":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-21T02:35:33.000Z","updated_at":"2024-01-28T14:57:54.000Z","dependencies_parsed_at":"2024-06-18T23:00:19.236Z","dependency_job_id":"dc721736-7828-4e50-8bc8-792b03e785fe","html_url":"https://github.com/logic-building/functional-go","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logic-building%2Ffunctional-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logic-building%2Ffunctional-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logic-building%2Ffunctional-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logic-building%2Ffunctional-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/logic-building","download_url":"https://codeload.github.com/logic-building/functional-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226304718,"owners_count":17603655,"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":["difference","exists","filter","functional","functional-go","functional-programming","go-functional","golang","intersection","map","map-filter-in-go","merge","pmap","set","sort","sort-struct","sorting","superset","union","zip"],"created_at":"2024-11-25T09:29:19.541Z","updated_at":"2024-11-25T09:29:31.612Z","avatar_url":"https://github.com/logic-building.png","language":"Go","readme":"[![Docs](https://godoc.org/github.com/logic-building/functional-go?status.svg)](https://godoc.org/github.com/logic-building/functional-go)\n[![Go Report Card](https://goreportcard.com/badge/github.com/logic-building/functional-go)](https://goreportcard.com/report/github.com/logic-building/functional-go)\n\n# functional-go : Functional programming in golang. This library is inspired by clojure.\n## Simple but functional\n\n### Install\n```\ngo get github.com/logic-building/functional-go/fp/\ngo get github.com/logic-building/functional-go/set/\ngo install github.com/logic-building/functional-go/gofp\n\ngo get -u github.com/logic-building/functional-go/fp/\ngo get -u github.com/logic-building/functional-go/set/\ngo install github.com/logic-building/functional-go/gofp\n\n```\n\n### dep Gopkg.toml entry\n```toml\n[[constraint]]\nname = \"github.com/logic-building/functional-go\"\nversion = \"8.14.0\"\n```\n\n### Quick Start\n#### For Data types available in golang\n```go\nimport \"github.com/logic-building/functional-go/fp\"\n\nfp.MapInt(square, []int{1, 2, 3, 4}) // Returns: [1 4 9 16]\n\nfunc square(num int) int {\n\treturn num * num\n}\n\n```\n#### Four variants of the function. 1 is given above and 3 are given below\n##### MapInt, MapIntPtr, MapIntErr, MapIntPtrErr\n### MapIntPtr\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/logic-building/functional-go/fp\"\n)\n\nvar v1 int = 1\nvar v2 int = 2\nvar v3 int = 3\nvar v4 int = 4\n\nfunc main() {\n\tresult := fp.MapIntPtr(square, []*int{\u0026v1, \u0026v2, \u0026v3, \u0026v4})\n\tfmt.Println(*result[0], *result[1], *result[2], *result[3])\n}\n\nfunc square(num *int) *int {\n\tr := *num * *num\n\treturn \u0026r\n}\n\n/*\noutput:\n1 4 9 16\n*/\n```\n\n### MapIntErr\n```go\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"github.com/logic-building/functional-go/fp\"\n)\n\nfunc main() {\n\tresult, _ := fp.MapIntErr(square, []int{1, 2, 3, 4})\n\tfmt.Println(result[0], result[1], result[2], result[3])\n}\n\nfunc square(num int) (int, error) {\n\tif num == -1 {\n\t\treturn 0, errors.New(\"-1 is not valid\")\n\t}\n\tr := num * num\n\treturn r, nil\n}\n\n/*\noutput:\n1 4 9 16\n*/\n```\n\n### MapIntPtrErr\n```go\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\n\t\"github.com/logic-building/functional-go/fp\"\n)\n\nfunc main() {\n\tvar v1 int = 1\n\tvar v2 int = 2\n\tvar v3 int = 3\n\tvar v4 int = 4\n\n\tresult, _ := fp.MapIntPtrErr(square, []*int{\u0026v1, \u0026v2, \u0026v3, \u0026v4})\n\tfmt.Println(*result[0], *result[1], *result[2], *result[3])\n}\n\nfunc square(num *int) (*int, error) {\n\tif *num == -1 {\n\t\treturn nil, errors.New(\"-1 is not valid\")\n\t}\n\tr := *num * *num\n\treturn \u0026r, nil\n}\n/*\noutput:\n1 4 9 16\n*/\n```\n\n####  Generate functional code locally in project for user defined data type\n```\nDesign 1: Functional code distributed within different package\nDesign 2: All functional code in one place\n```\n### Design 1:  Functional code distributed within different package\n#### Generate functional code for struct - Employee\n```go\n   type Employee struct {\n   \tid     int\n   \tname   string\n   \tsalary float64\n   }\n```\n#### 1. Add line given below in the file where struct resides\n```go\n//go:generate gofp -destination fp.go -pkg employee -type \"Employee\"\n```\n##### Example: \n```go\n   //go:generate gofp -destination fp.go -pkg employee -type \"Employee\"\n   type Employee struct {\n   \tid     int\n   \tname   string\n   \tsalary float64\n   }\n```\n##### Note:\n```\n//go:generate gofp -destination fp.go -pkg employee -type \"Employee\"\n\n-destination fp.go : fp.go is a new file which contains functional code for struct - Employee\n-pkg employee      : employee is package where struct \"Employee\" resides\n-type \"Employee\"   : Employee is struct for which functional code is generated.\n\n```\n#### Step 2. Install \"gofp\n```\n    go get github.com/logic-building/functional-go/gofp\n    go get -u github.com/logic-building/functional-go/gofp\n    go install github.com/logic-building/functional-go/gofp\n```\n#### Step 3. Run go generate from root folder of the project\n```\n go generate ./...\n```\n#### You are done. Enjoy the functional code\n```go\n    emp1 := employee.Employee{1, \"A\", 1000}\n    emp2 := employee.Employee{2, \"B\", 1000}\n    emp3 := employee.Employee{3, \"C\", 1000}\n\n    empList := []employee.Employee{emp1, emp2, emp3}\n\n    newEmpList := employee.Map(incrementSalary, empList) //  Returns: [{1 A 1500} {2 B 1500} {3 C 1500}]\n\n   func incrementSalary(emp employee.Employee) employee.Employee {\n        emp.Salary = emp.Salary + 500\n        return emp\n   }\n```\n\n##### Optional parameter \n```  \nOptions on go:generate :\n    A: -only: overrides default behavior of generating all the functions. But it always includes Map and Filter\n     //go:generate gofp -destination fp.go -pkg employee -type \"Employee\" -only \"Distinct, DistinctPtr, DistinctP\"\n     full-list-values-for-only: \"Distinct, DistinctP, DropLast, DropLastPtr, \n                                 DropWhile, DropWhileErr, DropWhilePtr, DropWhilePtrErr, Every, EveryErr, EveryPtr, \n                                 EveryPtrErr, FilterMap, FilterMapErr, FilterMapPtr, FilterMapPtrErr, \n                                 Remove, RemoveErr, RemovePtr, RemovePtrErr, Reduce, ReduceErr, ReducePtr, ReducePtrErr, Rest, RestPtr, \n                                 Reverse, ReversePtr, Some, SomeErr, SomePtr, SomePtrErr, Take, TakePtr,\n                                 TakeWhile, TakeWhileErr, TakeWhilePtr, TakeWhilePtrErr\"\n                                 \n    B. -sort: generate sorting functions for struct will override default behavior of generating sorting functions by each member of sturct of basic types \n      //go:generate gofp -destination fp.go -pkg employee -type \"Employee\" -sort \"Employee:Name, Employee:Salary\"\n      \n    C. -set: generate set functions-Union, Intersection, Difference, Set, Superset, Subset for struct will override default behavior of generating set functions by each member of struct of basic types\n      //go:generate gofp -destination fp.go -pkg employee -type \"Employee\" -set \"Employee:Name:string\"\n      \n    D. -mapfun: To generate Merge \u0026 Zip functions for struct\n      //go:generate gofp -destination fp.go -pkg employee -type \"Employee\" -mapfun \"true\"\n      Caution: It will complain at runtime if struct contains slice or array \n```\n\n### Design 2: All functional code in one place\n```\n1. Install \"gofp\" to generate code\n   go get -u github.com/logic-building/functional-go/gofp\n   go install github.com/logic-building/functional-go/gofp\n\n2. create package \"gfp\" : See the example - internal/gfp/gfp.go\n   and two lines given below\n\n   package gfp\n   //go:generate gofp -destination fp.go -pkg gfp -type \"employer.Employer, employee.Employee, int\" -imports \"github.com/logic-building/functional-go/internal/employee, github.com/logic-building/functional-go/internal/employer\"\n\n\n   -destination fp.go  : Generated file in package \"gfp\" will be \"fp.go\" which contains all the functional code\n   -pkg gfp : Saying that package is \"gfp\"\n   -type \"employer.Employer, employee.Employee, int\" : Generate functions for the combinations of these three data types\n   -imports \"github.com/logic-building/functional-go/internal/employee, github.com/logic-building/functional-go/internal/employer\" : import statements for two user defined types\n                \"employee.Employee\" and employer.Employer. The value for -imports should be comma separated\n\n\n3. Generate functional code : Run the command given below from the root folder of your project\n   go generate ./...\n\n4. Now write your code\n\n    gfp.MapEmployer\n    or\n    gfp.MapEmployee\n    or\n    gfp.MapEmployerEmployee\n\n```\n\n### All Standard FP Function\n```\n1. Dedupe\u003cType\u003e        : Returns a new list removing consecutive duplicates in provided list.\n2. Difference\u003cType\u003e    : Returns a set that is the first set without elements of the remaining sets\n3. Distinct\u003cType\u003e      : Returns a new list with duplicates removed.\n4. Distinct\u003cType\u003eP     : Returns true if no two of the arguments are =\n5. Drop\u003cType\u003e          : Returns a new list after dropping the given item\n6. DropWhile\u003cType\u003e     : Returns a new list after dropping the items in the given list as long as condition satisfies(1st argument - predicate)\n7. Equal\u003cType\u003esP       : Returns true if both list are equal else returns false\n8. EqualMap\u003cType\u003eP     : Returns true if both maps are equal else returns false\n9. EqualMap\u003cType1\u003e\u003cType2\u003eP : Returns true if both maps are equal else returns false\n10. Even\u003cType\u003eP         : Returns true if n is even\n11. Every\u003cType\u003e         : Returns true if supplied predicate function(1st argument) returns logical true for every item in the list\n12. Exists\u003cType\u003e        : Returns true if given item exists in the list else false\n13. Filter\u003cType\u003e        : Returns a new list after filtering the list(2nd argument) based on predicate function passed (1st argument)\n14. FilterMap\u003cType\u003e    : Returns a new list after filtering given list(3rd argument), based on predicate function(1st argument) then apply function(2nd argument) on each item in the list(3rd argument)\n15. FilterMap\u003cInputType\u003e\u003cOutputType\u003e : similar to FilterMap\u003cType\u003e with additional feature - input(3rd argument) type is different\n                                       output(return list) type is different\n16. Intersection\u003cType\u003e : Returns a set that is the intersection of the input sets. Repeated value within the list(arguments) will be ignored\n17. Keys\u003cType\u003e         : Returns new a list of map's keys\n18. Keys\u003cType1\u003e\u003cType2\u003e : Returns new a list of map's Keys\n19. Map\u003cType\u003e          : Returns a new list after  applying the function(1st argument) on each item in the list(2nd argument) \n20. Map\u003cInputType\u003e\u003cOutputType\u003e : Similar to Map\u003cType\u003e with additional feature - input(2nd argument) type is different and output(return) type is different\n21. Max\u003cType\u003e          : Returns max item from the list.\n22. Merge\u003cType\u003e        : Returns new map[\u003cType\u003e]\u003cType\u003e after merging map[\u003cType\u003e]\u003cType\u003e and map[\u003cType\u003e]\u003cType\u003e \n23. Merge\u003cType1\u003e\u003cType2\u003e: Returns new map\u003c[\u003cType1\u003e]\u003cType2\u003e after merging map[\u003cType1\u003e]\u003cType2\u003e and map[\u003cType1\u003e]\u003cType2\u003e\n24. Min\u003cType\u003e          : Returns min item from the list.\n25. MinMax\u003cType\u003e       : Returns min and max items from the list.\n26. Neg\u003cType\u003eP         : Returns true if num is less than zero, else false\n27. Odd\u003cType\u003eP         : Returns true if n is odd\n28. PMap\u003cType\u003e         : Similar to Map\u003cType\u003e with additional feature - function(1st) argument runs concurrently for each item in the list(2nd argument)\n                        EX. PMapInt(squareInt, []int{v1, v2, v3})\n                            PMapInt(squareInt, []int{v1, v2, v3}, Optional{FixedPool: 2, RandomOrder: true})\n                        \n29. PMap\u003cInputType\u003e\u003cOutputType\u003e: Similar to Map\u003cInputType\u003e\u003cOutputType\u003e with additional feature - function(1st) argument runs concurrently for each item in the list(2nd argument)\n                       EX. PMapIntInt64(plusOneIntInt64, []int{1, 2, 3}) // input: list(int), returns: list(int64) \n                           PMapIntInt64(plusOneIntInt64, []int{1, 2, 3}, Optional{FixedPool: 2, RandomOrder: true})\n                           \n30. Pos\u003cType\u003eP         : Returns true if num is greater than zero, else false\n31. Range\u003cType\u003e        : Returns a new list of range between lower and upper value. Optional argument(3rd) will increment value by given number\n32. Reduce\u003cType\u003e       : Reduces a list to a single value by combining elements via a supplied function\n33. Remove\u003cType\u003e       : Returns a new list after removing the items from the given list(2nd argument) based on supplied predicate function(1st argument)\n34. Rest\u003cType\u003e         : Returns a new list after removing 1st item in the list(2nd argument)\n35. Reverse\u003cType\u003e      : Returns a new list after reversing the list\n36. Set\u003cType\u003e          : Returns a new list after removing duplicates items in the list\n37. Some\u003cType\u003e         : Returns true if item is found in the list(2nd argument) based on predicate function(1st argument)\n38. Sort\u003cType\u003es        : Returns new sorted list\n39. Subset\u003cType\u003e       : Returns true or false by checking if set1 is a subset of set2. Repeated value within list(argument) will be ignored\n40. Superset\u003cType\u003e     : Returns true or false by checking if set1 is a superset of set2. Repeated value within list(argument) will be ignored\n41. Take\u003cType\u003e         : Returns n items in the list\n42. TakeWhile\u003cType\u003e    : Returns a new list based on predicate function(1st argument). It returns new list once condition fails.\n43. Union\u003cType\u003e        : Return a set that is the union of the input sets. Repeated value within list(argument) will be ignored\n44. Zero\u003cType\u003eP        : Returns true if num is zero, else false\n45. Zip\u003cType\u003e          : Returns New map([\u003cType\u003e])Type after merging two lists \n46. Zip\u003cType1\u003e\u003cType2\u003e  : Similar to Zip\u003cType\u003e with additional feature: Type of both list can be different\n```\n\n### Functions in generated code for struct (user defined type)\n```\nNote: \n  Comparison logic for struct is based on == operator as long as the members of struct are of simple types.\n  But reflect.DeepEqual is used for struct comparison if the struct contains any slices, maps. \n```\n```\n1. Difference : Returns a set that is the first set without elements of the remaining sets\n2. Difference\u003cstruct\u003eBy\u003cField\u003e \n3. Distinct  : Returns a new list with duplicates removed\n4. DistinctP : Returns true if no two of the arguments are =\n5. DropWhile : Returns a new list after dropping the items in the given list as long as condition satisfies(1st argument - predicate)\n6. Every     : Returns true if supplied predicate function(1st argument) returns logical true for every item in the list\n7. Filter    : Returns a new list after filtering the list(2nd argument) based on predicate function passed (1st argument)\n8. FilterMap : Returns a new list after filtering given list(3rd argument), based on predicate function(1st argument) then apply function(2nd argument) on each item in the list(3rd argument)\n9. Intersection : Returns a set that is the intersection of the input sets. Repeated value within the list(arguments) will be ignored\n10. Intersection\u003cstruct\u003eBy\u003cField\u003e\n11. Map      : Returns a new list after  applying the function(1st argument) on each item in the list(2nd argument)\n12. PMap     : Similar to Map\u003cType\u003e with additional feature - function(1st) argument runs concurrently for each item in the list(2nd argument)\n13. Reduce   : Reduces a list to a single value by combining elements via a supplied function\n14. Remove   : Returns a new list after removing the items from the given list(2nd argument) based on supplied predicate function(1st argument)\n15. Rest     : Returns a new list after removing 1st item in the list(2nd argument)\n16. Reverse  : Returns a new list after reversing the list\n17. Set      : Returns a new list after removing duplicates items in the list\n18. Set\u003cstruct\u003eBy\u003cField\u003e\n19. Some     : Returns true if item is found in the list(2nd argument) based on predicate function(1st argument)\n20. Sort\u003cstruct\u003eBy\u003cField\u003e : Returns new sorted list\n21. Subset   : Returns true or false by checking if set1 is a subset of set2. Repeated value within list(argument) will be ignored\n22. Subset\u003cstruct\u003eBy\u003cField\u003e\n23. Superset : Returns true or false by checking if set1 is a superset of set2. Repeated value within list(argument) will be ignored\n24. Superset\u003cstruct\u003eBy\u003cField\u003e\n25. TakeWhile : Returns a new list based on predicate function(1st argument). It returns new list once condition fails.\n26. Union     : Return a set that is the union of the input sets. Repeated value within list(argument) will be ignored\n27. Union\u003cstruct\u003eBy\u003cField\u003e\n```\n\n### Method chain functionality for Basic type as well as struct - \n#### Map, Filter, Sort, Distinct, Reverse, DropWhile, TakeWhile, Remove\n#### Examples\n```go\n// Use MakeIntSlicePtr for pointer version\nr := fp.MakeIntSlice([]int{3, 2, 1}...).\n        Filter(odd).\n        Map(square).\n        Sort()\nfmt.Println(r) // [1 9]\n\nfunc odd (num int) bool {\n        return num % 2 != 0\n}\nfunc square(num int) int {\n        return num * num\n}\n    \n```\n\n### Contains functions\n```\nTakes list as argument and returns Distinct list.  Returns empty list if 2nd parameter is empty or nil\nDistinctInt\nDistinctInt64\nDistinctInt32\nDistinctInt16\nDistinctInt8\nDistinctUint\nDistinctUint64\nDistinctUint32\nDistinctUint16\nDistinctUint8\nDistinctFloat64\nDistinctFloat32\nDistinctStr\n\nadd Ptr at end for pointer versioon function\neg. DistinctIntPtr\n\nTakes function as argument and apply it on each item in the list and return list\nMapInt\nMapInt64\nMapInt32\nMapInt16\nMapInt8\nMapUint\nMapUint64\nMapUint32\nMapUint16\nMapUint8\nMapFloat64\nMapFloat32\nMapStr\n   And also all basic combination such as\nMapStrInt64\nMapInt64Str\n...\n\nPmap : For parallel processing\nPmapInt\nPmapInt64\nPmapInt32\nPmapInt16\nPmapInt8\nPmapUint\nPmapUint64\nPmapUint32\nPmapUint16\nPmapUint8\nPmapFloat64\nPmapFloat32\nPmapStr\n    And also all basic combination such as\nPMapStrInt64\nPMapInt64Str\n\nadd Ptr at end for pointer versioon function\neg. PMapInt64StrPtr\n\nTakes function as argument and apply it on each item in the list and return filtered list\nFilterInt\nFilterInt64\nFilterInt32\nFilterInt16\nFilterInt8\nFilterUint\nFilterUint64\nFilterUint32\nFilterUint16\nFilterUint8\nFilterFloat64\nFilterFloat32\nFilterStr\n\nadd Ptr at end for pointer versioon function\neg. FilterIntPtr\n\nTakes two functions as argument and apply them on each item in the list and return the filtered list\nFilterMapInt\nFilterMapInt64\nFilterMapInt32\nFilterMapInt16\nFilterMapInt8\nFilterMapUint\nFilterMapUint64\nFilterMapUint32\nFilterMapUint16\nFilterMapUint8\nFilterMapFloat64\nFilterMapFloat32\nFilterMapStr\n    And also all basic combination such as\nFilterMapStrInt64\nFilterMapInt64Str\n\nadd Ptr at end for pointer versioon function\neg. FilterMapIntPtr\n\nTakes list as parameter and returns new list which includes all the items except 1st one.\n    Input: list\n    output: New list includes all the items except 1st one.\n            Returns new empty list if the input is either nil or empty or length 1 list\n    Ex.\n\t\tlist := []int{1, 2, 3, 4, 5}\n\t\tRestInt(list) // returns [2, 3, 4, 5]\n\nRestInt\nRestInt64\nRestInt32\nRestInt16\nRestInt8\nRestUint\nRestUint64\nRestUint32\nRestUint16\nRestUint8\nRestFloat64\nRestFloat32\nRestStr\n\nadd Ptr at end for pointer versioon function\neg. RestIntPtr\n\n\nTakes function as argument and apply it on each item in the list and return true/false. Returns false if 2nd argument is empty\nEveryBool : Takes two arguments\n             a. function without arguments and returns bool\n             b. list of boolean values\n\n        return:\n           true if all the values in the list are true, otherwise false\n           See example below\n\n\nEveryInt :\n       Takes two arguments\n        a. function with 1 argument type int and returns bool\n        b. list of int\n\n        return: True if function-1st argument returns true for each item in the list, otherwise false\nEveryInt64\nEveryInt32\nEveryInt16\nEveryInt8\nEveryUint\nEveryUint64\nEveryUint32\nEveryUint16\nEveryUint8\nEveryFloat64\nEveryFloat32\nEveryStr\n\nadd Ptr at end for pointer versioon function\neg. EveryIntPtr\n\nTakes a number and a list as arguments and returns true if number exists in the list else returns false\nExistsInt\nExistsInt64\nExistsInt32\nExistsInt16\nExistsInt8\nExistsUint\nExistsUint64\nExistsUint32\nExistsUint16\nExistsUint8\nExistsFloat64\nExistsFloat32\nExistsStr\n\nadd Ptr at end for pointer versioon function\neg. ExistsIntPtr\n\nTakes list as argument and return max number\n- Returns 0 if list is either empty or nil\n\nMaxInt\nMaxInt64\nMaxInt32\nMaxInt16\nMaxInt8\nMaxUint\nMaxUint64\nMaxUint32\nMaxUint16\nMaxUint8\nMaxFloat64\nMaxFloat32\n\nadd Ptr at end for pointer versioon function\neg. MaxIntPtr\n\nTakes list as argument and return min number\n- Returns 0 if list is either empty or nil\nMinInt\nMinInt64\nMinInt32\nMinInt8\nMinUint\nMinUint64\nMinUint32\nMinUint16\nMinUint8\nMinFloat64\nMinFloat32\n\nTakes List as argument and returns Min and Max\n   - Returns 0, 0 if list is either empty or nil\n   - Returns same result for min and max if there is only one item in the list\nMinMaxInt\nMinMaxInt64\nMinMaxInt32\nMinMaxInt8\nMinMaxUint\nMinMaxUint64\nMinMaxUint32\nMinMaxUint16\nMinMaxUint8\nMinMaxFloat64\nMinMaxFloat32\n\nReturns a new list after dropping single item or multiple items \nDropInt\nDropInts\nDropInt64\nDropInts64\nDropInt32\nDropInts32\nDropInt16\nDropInts16\nDropInt8\nDropInts8\nDropUint\nDropUInts\nDropUint64\nDropUints64\nDropUint32\nDropUints32\nDropUint16\nDropUints16\nDropUint8\nDropUints8\nDropFloat64\nDropFloats64\nDropFloat32\nDropFloats32\nDropStr\nDropStrIgnoreCase\nDropStrs\nDropStrsIgnoreCase\n\nDropWhile:\n  Drop the items in the list based on condition\n  Takes 2 inputs\n    a. Function : takes 1 input - int or float or string and return true/false\n    b. list\n  returns:\n      NewList\n\n      see example\n\nDropWhileInt\nDropWhileInt64\nDropWhileInt32\nDropWhileInt16\nDropWhileInt8\nDropWhileUint\nDropWhileUint64\nDropWhileUint32\nDropWhileUint16\nDropWhileUint8\nDropWhileFloat64\nDropWhileFloat32\nDropWhileStr\n\nTakeWhile:\n  take the items in the list based on condition\n\nTakes 2 inputs\n  a. Function : takes 1 input - int or float or string and return true/false\n  b. list\n\n  returns:\n     NewList\n\n        see example\n\nTakeWhileInt\nTakeWhileInt64\nTakeWhileInt32\nTakeWhileInt16\nTakeWhileInt8\nTakeWhileUint\nTakeWhileUint64\nTakeWhileUint32\nTakeWhileUint16\nTakeWhileUint8\nTakeWhileFloat64\nTakeWhileFloat32\nTakeWhileStr\n\nTakes function  and list as arguments and remove items based on function passed and return new list. See example\nRemoveInt\nRemoveInts\nRemoveInt64\nRemoveInts64\nRemoveInt32\nRemoveInts32\nRemoveInt16\nRemoveInts16\nRemoveInt8\nRemoveInts8\nRemoveUint\nRemoveUInts\nRemoveUint64\nRemoveUints64\nRemoveUint32\nRemoveUints32\nRemoveUint16\nRemoveUints16\nRemoveUint8\nRemoveUints8\nRemoveFloat64\nRemoveFloats64\nRemoveFloat32\nRemoveFloats32\nRemoveStr\nRemoveStrIgnoreCase\nRemoveStrs\nRemoveStrsIgnoreCase\n\nRange function\nTakes 3 inputs:\n   a. lower\n   b. upper\n   c. hops(optional)\n\n      Returns list of range between lower and upper value\n      Returns empty list if 3rd arguments is either of the following\n           a. 0\n           b. Negative number\n\n      Note: 3rd argument is considered as hops value if 3 or more than 3 arguments are passed.\n\nRangeInt\nRangeInt64\nRangeInt32\nRangeInt16\nRangeInt8\nRangeUint\nRangeUint64\nRangeUint32\nRangeUint16\nRangeUint8\n\nSomeInt: takes two parameters\n    A. Function - one parameter and returns boolean\n    B. list\nReturns:\n   Bool\n\nEx.\n    SomeInt(isEven, []int{1, 2, 3, 5}) : returns true\n    SomeInt(nil, nil) : returns false\n    SomeInt(isEven, []int{}) : returns false\n\nSomeInt\nSomeInt64\nSomeInt32\nSomeInt16\nSomeInt8\nSomeUint\nSomeUint64\nSomeUint32\nSomeUint16\nSomeUint8\nSomeFloat64\nSomeFloat32\nSomeStr\n\nTakes three inputs:\n   A. function - takes two argument\n   B. list\n   c. initializer - optional\n Returns:\n    single value\n\n Example\n   list := []int{1, 2, 3, 4, 5}\n   ReduceInt(plusInt, list) // returns: 15\n\n   func plusInt(num1, num2 int) int {\n\t    return num1 + num2\n   }\n\nReduceInt\nReduceInt64\nReduceInt32\nReduceInt16\nReduceInt8\nReduceUint\nReduceUint64\nReduceUint32\nReduceUint16\nReduceUint8\nReduceFloat64\nReduceFloat32\nReduceStr\n\nMerge : Takes two inputs - map1 and map2 and returns new map after merging map1 and map2\n\nMergeInt - takes input1: map\u003cint,int\u003e, input2: map\u003cint, int\u003e\nMergeInt64\nMergeInt32\nMergeInt16\nMergeInt8\nMergeUint\nMergeUInt64\nMergeUint32\nMergeUint16\nMergeUint8\nMergeFloat64\nMergeFloat32\nMergeBool\nMergeStr\n\nand there are also functions available for different combination of inputs in map\n\nMergeIntStr - takes input1: map\u003cint,string\u003e, input2: map\u003cint, string\u003e\nMergeStrFloat64\n...\n\nExample:\n    map1 := map[int]int{1: 10, 2: 20, 3: 30}\n    map2 := map[int]int{4: 40, 5: 50, 3: 300}\n    MergeIntInt(map1, map2) // Returns: map[1:10 2:20 4:40 5:50 3:300]\n\n\nZip: Takes two inputs - list1 and list2 and returns new map after zipping two lists\n\nZipInt  : takes input1 - type \"int\", input2 - type \"int\"\nZipInt64 : takes input1 - type \"int64\", input2 - type \"int64\"\nZipInt32\nZipInt16\nZipInt8\nZipUint\nZipUint64\nZipUint32\nZipUint16\nZipUint8\nZipFloat64\nZipFloat32\nZipStr\nZipBool\n\nand there are also functions available for different combination of inputs,\n\nZipIntStr : takes input1 - type \"int\", input2 - type \"string\"\nZipStrFloat64 : takes input1 - type \"string\", input2 - type \"float64\"\n ...\n\n    Example:\n        list1 := []int{1, 2, 3, 4}\n        list2 := []int{10, 20, 30, 40}\n\n        ZipInt(list1, list2) // returns map[1: 10, 2: 20, 3: 30, 4: 40]\n\nSet operations: Add, Remove, Clear, GetList, NewSetInt, Join, Intersection, Minus, Subset, Superset\nSetInt\nSetIntSync\nSetInt64\nSetInt64Sync\nSetInt32\nSetInt32Sync\nSetInt16\nSetInt16Sync\nSetInt8\nSetInt8Sync\nSetUint\nSetUintSync\nSetUint64\nSetUint64Sync\nSetUint32\nSetUint32Sync\nSetUint16\nSetUint16Sync\nSetUint8\nSetUint8Sync\nSetUintFloat64\nSetUintFloat64Sync\nSetUintFloat32\nSetUintFloat32Sync\nSetStr\nSetStrSync\n```\n\n### Example1 - Map : return the list of the square of each items in the list\n```go\nsquareList := fp.MapInt(squareInt, []int{1, 2, 3}) // see the map_test.go for detail\n\nfunc squareInt(num int) int {\n\treturn num * num\n}\n\n\noutput\n-------\n[1, 4, 9]\n\n```\n\n### Example2 - Filter: filter all the even numbers in the list\n```go\nfilteredList := fp.FilterInt(isEven, []int{1, 2, 3, 4})\n\nfunc isEven(num int) bool {\n\treturn num%2 == 0\n}\n\noutput:\n[2, 4]\n\n```\n\n### Example3 - fp.FilterMap: Multiply all positive numbers in the list by 2\n```go\nfilteredList := FilterMapInt(isPositive, multiplyBy2, []int{-1, 0, 2, 4})\n\nfunc isPositive(num int) bool {\n\treturn num \u003e 0\n}\nfunc multiplyBy2(num int) int {\n\treturn num * 2\n}\n\noutput:\n[4, 8]\n```\n\n### Example4 - Every: Test if every number in the list is even\n```go\nlist := []bool{true, true, true, true}\nfp.EveryBool(fp.True, list)  // Returns true\n\nlist1 := []int{8, 2, 10, 4}\nfp.EveryInt(isEven, list1) // Returns true\n```\n\n### Example5 - Exists: Test if number presents in the list\n```go\nlist1 := []int{8, 2, 10, 4}\nfp.ExistsInt(8, list1) // returns true\n```\n\n### Example6 - Max: Get max number in the list\n```go\nlist := []int{8, 2, 10, 4}\nmax := fp.MaxInt(list) // returns 10\n```\n\n### Example7 - Min: Get min number in the list\n```go\nlist := []int{8, 2, 10, 4}\nmin := fp.MinInt(list) // returns 2\n```\n\n### Example8 - Returns a new list after dropping the given item\n```go\nnewList := fp.DropInt(1, []int{1, 2, 3, 1}) // returns [2, 3]\n\nTo drop multiple items:\nnewList := fp.DropInts([]int{1, 2}, []int{1, 2, 3, 1}) // returns [3]\n\n```\n\n### Example9 - Distinct: returns distinct list\n```go\nlist := []int{8, 2, 8, 0, 2, 0}\ndistinct := fp.DistinctInt(list) // returns [8, 2, 0]\n```\n\n### Example10 - Set : Create set objects and apply union operation\n```go\n\tmySet1 := set.NewInt([]int{10, 20, 30, 20})\n\tmySet2 := set.NewInt([]int{30, 40, 50})\n\tmySet3 := mySet1.Union(mySet2) // Returns  [10, 20, 30, 40, 50]\n```\n\n### Example11 - Range : accepts lower and end int and returns range list\n```go\n\tfp.Range(1, 5) // returns [1, 2, 3, 4]\n\tfp.Range(1, 5, 2) // returns [1, 3]\n```\n\n### Example12 - Remove :\n```go\n    NewList := RemoveInt(isEven, []int{1, 2, 3, 4}) // returns [1, 3]\n\n    func isEven(num int) bool {\n    \treturn num%2 == 0\n    }\n\n```\n\n### Example13 - DropWhileInt :\n```go\n    NewList := DropWhile(isEven, []int{4, 2, 3, 4}) // returns [3, 4]\n\n    func isEven(num int) bool {\n    \treturn num%2 == 0\n    }\n\n```\n\n### Example14 - TakeWhileInt :\n```go\n    NewList := TakeWhile(isEven, []int{4, 2, 3, 4}) // returns [4, 2]\n\n    func isEven(num int) bool {\n    \treturn num%2 == 0\n    }\n\n```\n\n### Test Coverage\n```\nTests Passed : 1217\nok  \tfunctional-go/fp\t0.015s\tcoverage: 99.7% of statements\nok  \tfunctional-go/set\t0.031s\tcoverage: 100.0% of statements\n```\n### Test Counts\n```\ngo test ./... -v | grep -c RUN\n4762\n```\n### BenchMark test:\n```\n  Model Identifier:\tMacBookPro11,5\n  Processor Name:\tIntel Core i7\n  Processor Speed:\t2.5 GHz\n  Number of Processors:\t1\n  Total Number of Cores:\t4\n  Memory:\t16 GB\n\n  Note: Bench result can vary bassed on the function passed. Check the test file for the detail.\n```\n\n```\ngoos: darwin\ngoarch: amd64\npkg: functional-go/fp\nBenchmarkFilterInt64-8                   \t 1000000\t      5030 ns/op\nBenchmarkFilterMapInt64-8                \t 1000000\t      5865 ns/op\nBenchmarkMapInt64_PassedMethod_1_Arg-8   \t 1000000\t      3597 ns/op\nBenchmarkMapInt64_PassedMethod_2_Arg-8   \t 1000000\t      3622 ns/op\nBenchmarkMapStr-8                        \t 1000000\t     49438 ns/op\nPASS\nok  \tfunctional-go/fp\t67.567s\n```\n\n### Benchmark test for PMap with fixed order and random order\n```\ngo test -benchtime=200x -bench=BenchmarkPMapInt\ngoos: darwin\ngoarch: amd64\npkg: github.com/logic-building/functional-go/fp\nBenchmarkPMapInt-8                           200             16224 ns/op\nBenchmarkPMapIntRandomOrder-8                200             10091 ns/op\nPASS\nok      github.com/logic-building/functional-go/fp      4.549s\n```\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogic-building%2Ffunctional-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flogic-building%2Ffunctional-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogic-building%2Ffunctional-go/lists"}