{"id":16092293,"url":"https://github.com/alecthomas/gorx","last_synced_at":"2025-03-16T08:32:20.970Z","repository":{"id":66600202,"uuid":"42970286","full_name":"alecthomas/gorx","owner":"alecthomas","description":"A package and tool providing Reactive eXtensions for Go.","archived":false,"fork":false,"pushed_at":"2024-01-01T13:45:00.000Z","size":324,"stargazers_count":94,"open_issues_count":0,"forks_count":8,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-02-27T05:51:32.530Z","etag":null,"topics":[],"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/alecthomas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","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":"2015-09-23T01:10:42.000Z","updated_at":"2022-07-30T20:45:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"fe2a3443-5753-434e-bc1e-0c743e9e5d18","html_url":"https://github.com/alecthomas/gorx","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fgorx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fgorx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fgorx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecthomas%2Fgorx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alecthomas","download_url":"https://codeload.github.com/alecthomas/gorx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243806070,"owners_count":20350775,"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-10-09T16:06:48.522Z","updated_at":"2025-03-16T08:32:20.588Z","avatar_url":"https://github.com/alecthomas.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Reactive eXtensions for Go [![](https://godoc.org/github.com/alecthomas/gorx?status.png)](http://godoc.org/github.com/alecthomas/gorx) [![Build Status](https://travis-ci.org/alecthomas/gorx.png)](https://travis-ci.org/alecthomas/gorx)\n\nThis is a package and tool providing [Reactive eXtensions](http://reactivex.io) for Go.\n\nThe main package provides Rx operators for common Go builtin types, and the\ntool generates Go code for arbitrary types.\n\n# Why?\n\nYes, good question. Mostly as an exercise to see if it was feasible/possible.\nIt is, largely, except for operators that produce sequence types (ie. arrays\nor observables of T).\n\nThat said, the Rx operators *do* provide some nice functionality that would\notherwise have to be implemented by hand.\n\n# Installation\n\n```\ngo get github.com/alecthomas/gorx github.com/alecthomas/gorx/cmd/gorx\n```\n\n# Usage\n\nTo use the package:\n\n```go\nimport \"github.com/alecthomas/gorx\"\n\ngorx.\n  FromTimeChannel(time.Tick(time.Second)).\n  Take(5).\n  Do(func(t time.Time) { fmt.Printf(\"%s\\n\", t) }).\n  Wait()\n```\n\nTo generate Rx operators for custom types:\n\n```\ngorx --import=gopkg.in/alecthomas/kingpin.v2 kingpinrx '*kingpin.CmdClause' '*kingpin.FlagClause'\n```\n\n# Examples\n\nA very basic example creating an observable from a set of strings and printing\nthem:\n\n```go\ngorx.FromStrings(\"Ben\", \"George\").Do(func(s string) { fmt.Println(s) }).Wait()\n```\n\nA more [complex example](examples/complex/main.go). Try retrieving article from cache, otherwise fetch\noriginal from Wikipedia, all with a timeout.\n\n```go\nfunc GetCached(url string) *ResponseStream {\n  fmt.Printf(\"No cache entry for %s\\n\", url)\n  return ThrowResponse(errors.New(\"not implemented\"))\n}\nfunc SetCached(response *http.Response) {\n  fmt.Printf(\"Caching %s\\n\", response.Request.URL)\n}\n\nfunc Get(url string) *ResponseStream {\n  return StartResponse(func() (*http.Response, error) {\n    response, err := http.Get(url)\n    if err == nil \u0026\u0026 (response.StatusCode \u003c 200 || response.StatusCode \u003e 299) {\n      return nil, errors.New(http.StatusText(response.StatusCode))\n    }\n    return response, err\n  })\n}\n\nfunc URLForArticle(article string) string {\n  return \"http://en.wikipedia.org/wiki/\" + article\n}\n\nfunc LogError(err error) {\n  fmt.Printf(\"error: %s\\n\", err)\n}\n\nfunc GetWikipediaArticles(timeout time.Duration, articles ...string) *ResponseStream {\n  // Try cached URL first, then recover with remote URL and\n  // finally recover with an empty stream.\n  return FromStringArray(articles).\n    Map(URLForArticle).\n    FlatMapResponse(func(url string) ResponseObservable {\n      remote := Get(url).\n        Timeout(timeout).\n        Do(SetCached).\n        DoOnError(LogError).\n        Catch(EmptyResponse())\n      return GetCached(url).\n        Catch(remote)\n    })\n}\n```\n\n# Operators\n\nFollowing are a list of the core operators as [defined by reactivex.io](http://reactivex.io/documentation/operators.html) that have been implemented and will (probably) be implemented soon:\n\n## Create operators\n\n- Create\n- Empty\n- Never\n- Throw\n- Just\n- Range\n- Repeat\n- Start\n\nNot implemented:\n\n- Defer\n- Timer\n\n## Transformations\n\n- Map\n- Reduce\n- Scan\n- FlatMap\n\nNot implemented:\n\n- Buffer\n- GroupBy\n- Window\n\nNote: These operators are currently not implemented because each distinct\nobservable type requires quite a lot of boilerplate code, and these operators\nproduce new types. eg. `.Buffer(2)` would transform `T` to a stream of `[]T`,\n`.FlatMap(f)` would transform `T` to a `TStreamStream`, etc. One \"solution\" is\nto only generate these operators if the user explicitly requests these\nresultant types.\n\n## Filters\n\n- Distinct\n- ElementAt\n- Filter\n- First\n- Last\n- Skip\n- SkipLast\n- Take\n- TakeLast\n- IgnoreElements\n- Sample\n- Debounce\n\n# Combining\n\n- Merge\n- MergeDelayError\n\nNot implemented:\n\n- CombineLatest\n- And / Then / When\n- Zip\n- Join\n- StartWith\n- Switch\n- Zip\n\nNote: See note above for Transformations for why these are not implemented.\n\n# Error handling\n\n- Catch\n- Retry\n\n# Mathematics and Aggregation\n\n- Concat\n- Average\n- Count\n- Min\n- Max\n- Reduce\n- Sum\n\n# Utility\n\n- Do\n- Subscribe\n\nNot implemented:\n\n- Delay\n- Timeout\n- Timestamp\n- Materialize / Dematerialize\n- Serialize\n- TimeInterval\n\n# Conditional and Boolean\n\nNot implemented:\n\n- All\n- Amb\n- Contains\n- DefaultIfEmpty\n- SequenceEqual\n- SkipUntil\n- SkipWhile\n- TakeUntil\n- TakeWhile\n\n# Conversion\n\n- To (one, array, channel)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falecthomas%2Fgorx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falecthomas%2Fgorx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falecthomas%2Fgorx/lists"}