{"id":16265281,"url":"https://github.com/glours/go2funk","last_synced_at":"2025-09-22T08:32:38.084Z","repository":{"id":43068794,"uuid":"296165381","full_name":"glours/go2funk","owner":"glours","description":"Simple Golang API to use functional types in Golang, such as immutable List, Options, Try, Either...","archived":false,"fork":false,"pushed_at":"2023-07-22T20:06:49.000Z","size":60,"stargazers_count":7,"open_issues_count":8,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-12-29T13:23:05.480Z","etag":null,"topics":["functional","functional-programming","generics","go","golang","program"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/glours.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-09-16T22:59:39.000Z","updated_at":"2022-04-28T05:44:02.000Z","dependencies_parsed_at":"2024-10-27T21:37:52.286Z","dependency_job_id":"0dfb4a82-f881-4790-b2cd-67ae76bf3179","html_url":"https://github.com/glours/go2funk","commit_stats":{"total_commits":25,"total_committers":2,"mean_commits":12.5,"dds":"0.040000000000000036","last_synced_commit":"504ce88dffbab8824f96df96b9c04ce540fb2773"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glours%2Fgo2funk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glours%2Fgo2funk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glours%2Fgo2funk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glours%2Fgo2funk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glours","download_url":"https://codeload.github.com/glours/go2funk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233660121,"owners_count":18710026,"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","functional-programming","generics","go","golang","program"],"created_at":"2024-10-10T17:07:59.621Z","updated_at":"2025-09-22T08:32:32.771Z","avatar_url":"https://github.com/glours.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go2Funk\n\nGo2Funk is a pet project to test Go2 Generics and see how this new feature help us to implement some functional\nstructures easily.  \nThe idea is to keep this repo as much as possible dependency free.\n\n## How to compile\nGolang `1.18` has been release with type parameters.   \nYou can now, compile and test your code as usual (`go build`, `go test` ...)\n\nYou can also use Docker Dev Environments to develop this project:\n* Open Docker Desktop\n* Go to Dev Environments view\n* Copy/Paste the git repo URL to start working!   \n  \nCheck the configuration of the base image in the `.docker/config.json` config file\n\n\n## Build\n\nuse `go build  ./...` or if you\nuse [Goland then configure external tools](https://www.jetbrains.com/help/go/how-to-use-type-parameters-for-generic-programming.html)\n\n## Run tests\n\nuse `go test -v ./...` or if you\nuse [Goland then configure external tools](https://www.jetbrains.com/help/go/how-to-use-type-parameters-for-generic-programming.html)\n\n## Usage\n\n### Collection types\n\n#### List\n\n```go\nmyIntArray := []int{1, 2, 3, 4, 5}\nmyList := OfSlice[int](myIntArray)\n\nmyList = myList.Append(6)\nfmt.Println(myList.Length())\n\nvar mapper = func (value int) string { return strconv.Itoa(value) }\n\nvar evenPredicate = func (value int) bool { return value % 2 == 0 }\n\nmyList = MapList[int, string](myList.Filter(evenPredicate), mapper); \n```\n\nFor more usage details check [tests](./api/collection/list_test.go).\n\n### Control types\n\n#### Option\n\n```go\nempytOption := Empty[int]()\nsomeOption := Of[int](10)\n\nfmt.Println(emptyOption.GetOrElse(5)) // Print 5\nfmt.Println(someOption.GetOrElse(5)) // Print 10\n\nvar evenPredicate = func (value int) bool { return value % 2 == 0 }\nfmt.Println(some.Filter(eventPredicate).IsEmpty()) #Print false\n\nvar mapper = func (value int) string { return strconv.Itoa(value) }\nfmt.Println(MapOption(someOption, mapper)) // Print \"10\"\n```\n\nFor more usage details check [tests](./api/control/option_test.go).\n\n#### Try\n\n```go\ndefaultTryError := errors.New(\"default Try error\")\n\nfailure := FailureOf[int](defaultTryError)\nsuccess := SuccessOf[int](10)\n\nfmt.Println(failure.GetOrElse(5)) // Print 5\nfmt.Println(someOption.GetOrElse(5)) // Print 10\n\nfmt.Println(failure.GetOrElseCause()) // Print \"default Try error\"\nfmt.Println(someOption.GetOrElseCause()) // Print 10\n\nsuccessLambda := func ()(int, error) { return 10, nil})\nfailureLambda := func ()(int, error) {return 0, defaultTryError }\n\nfmt.Println(TryOf(failureLambda).IsFailure()) // Print true\nfmt.Println(TryOf(successLambda).IsFailure()) // Print false\n```\n\nFor more usage details check [tests](./api/control/try_test.go).\n\n#### Either\n\n```go\ndefaultEitherError = errors.New(\"default Either error\")\nright = RightOf[error, int](10)\nleft = LeftOf[error, int](defaultEitherError)\n\nfmt.Println(right.GetOrElse(20)) // Print 10\nfmt.Println(left.GetOrElse(20)) // Print 20\n\nfmt.Println(right.GetLeftOrElse(error.New(\"new error\"))) // Print \"new error\"\nfmt.Println(left.GetOrElse(error.New(\"new error\"))) // Print \"default Either error\"\n\nvar mapper = func (value int) string { return strconv.Itoa(value) }\nvar mapRight Either[error, string] = MapEither(right, mapper)\nfmt.Println(mapRight.GetOrElse(\"good\")) // Print \"10\"\n```\n\nFor more usage details check [tests](./api/control/either_test.go).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglours%2Fgo2funk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglours%2Fgo2funk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglours%2Fgo2funk/lists"}