{"id":13367363,"url":"https://github.com/alxrm/uGo","last_synced_at":"2025-03-12T18:32:30.972Z","repository":{"id":57496983,"uuid":"51949955","full_name":"alxrm/ugo","owner":"alxrm","description":"Simple and expressive toolbox written in Go","archived":true,"fork":false,"pushed_at":"2016-06-30T19:18:16.000Z","size":59,"stargazers_count":27,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-27T05:34:20.563Z","etag":null,"topics":["collections","fluent-interface","functional","slice","underscore"],"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/alxrm.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}},"created_at":"2016-02-17T19:41:57.000Z","updated_at":"2023-03-05T01:02:37.000Z","dependencies_parsed_at":"2022-09-03T23:50:48.718Z","dependency_job_id":null,"html_url":"https://github.com/alxrm/ugo","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/alxrm%2Fugo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alxrm%2Fugo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alxrm%2Fugo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alxrm%2Fugo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alxrm","download_url":"https://codeload.github.com/alxrm/ugo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243271625,"owners_count":20264489,"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":["collections","fluent-interface","functional","slice","underscore"],"created_at":"2024-07-30T00:01:45.803Z","updated_at":"2025-03-12T18:32:30.696Z","avatar_url":"https://github.com/alxrm.png","language":"Go","readme":"[![GoDoc](https://godoc.org/github.com/alxrm/ugo?status.svg)](https://godoc.org/github.com/alxrm/ugo)\n[![Go Report Card](https://goreportcard.com/badge/github.com/alxrm/ugo)](https://goreportcard.com/report/github.com/alxrm/ugo)\n[![Travis CI](https://travis-ci.org/alxrm/ugo.svg?branch=master)](https://travis-ci.org/alxrm/ugo)\n\n# ugo\n\nSimple and expressive toolbox written with love and care in Go.\n\nDeeply inspired by [underscore.js](http://underscorejs.org/) and has the same syntax and behaviour\n\nFully covered with tests, no surprises\n\n### Quick start\n\n__Installation__\n\n```\ngo get -u  github.com/alxrm/ugo\n```\n\n__Import__\n\n``` GO\nimport (\n\tu \"github.com/alxrm/ugo\"\n)\n```\n\n### Usage\n\nIt works with some special type, named `Seq`, which is an alias for `[]interface{}`\n\nSo let's make some\n\n```GO\n\t\n// creates the new string Seq\nstrSeq := u.Seq{ \"nineteen\", \"eigth\", \"four\" } // [\"nineteen\" \"eigth\" \"four\"]\n\t\n// creates the new Seq with given length\nemptySeq := u.NewSeq(0); // []\n\t\n// copies reflectively all of the values from int slice to Seq\nintSlc := []int{ 4, 6, 2, 7, 8, 10, 9, 9, 120, 10, 2, 17 }\nintSeq := u.From(intSlc, len(intSlc)) // [4 6 2 7 8 10 9 9 120 10 2 17]\n\n```\n\n_Actually reflection approach in `u.From` can have an impact on performance :snail: so use it with care._\n\nOkay, now we have some Seq's, \n\nWhat if I want to leave only unique elements in my int slice?\n\nGo and get it :zap:\n\n```Go\n\ninitialSeq := u.Seq{ 4, 6, 2, 7, 8, 10, 9, 9, 120, 10, 2, 17 }\nuniquedSeq := u.Uniq(initial, func(l, r u.Object) int { return l.(int) - r.(int) })\n\nfmt.Println(uniquedSeq) // [4 6 2 7 8 10 9 120 17]\n\n```\n\nAnd I want to leave only odd ones\n\nNice choice! :fire:\n\n```Go\noddsSeq := u.Filter(uniquedSeq, func(cur, _, _ u.Object) bool { return cur.(int) % 2 != 0 })\n\nfmt.Println(oddsSeq) // [7 9 17]\n```\n\nWell, sometimes you may want to use many method one by one, and it can be a bit ugly\n\nHere we are, fluent syntax, just like in _underscore.js_ :rocket:\n\n```Go\ninitialSeq := u.Seq{ 4, 6, 2, 7, 8, 10, 9, 9, 120, 10, 2, 17 }\n\nres := u.Chain(initialSeq).Uniq(func(l, r u.Object) int {\n\treturn l.(int) - r.(int)\n}).Filter(func(cur, _, _ u.Object) bool {\n\treturn cur.(int) % 2 != 0\n}).Value()\n\nfmt.Println(res) // [7 9 17]\n```\n\n### Try it by yourself! \n\nExplore all of the features and get your slice routine done faster\n\n### Contribute\n\nWe highly appreciate any of your pull requests and issues!\n\nBe welcome :coffee:\n\n\n__Some of the TODOs:__\n\n- [x] Aliases from underscore\n- [x] Chaining like map(...).uniq(...).result()\n- [ ] Better documentation \n\n\n### License \n\n\tThe MIT License (MIT)\n\n\tCopyright (c) 2016 Alexey Derbyshev\n\t\n\tPermission is hereby granted, free of charge, to any person obtaining a copy\n\tof this software and associated documentation files (the \"Software\"), to deal\n\tin the Software without restriction, including without limitation the rights\n\tto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n\tcopies of the Software, and to permit persons to whom the Software is\n\tfurnished to do so, subject to the following conditions:\n\t\n\tThe above copyright notice and this permission notice shall be included in all\n\tcopies or substantial portions of the Software.\n\t\n\tTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n\tIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n\tFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n\tAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n\tLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n\tOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n\tSOFTWARE.\n","funding_links":[],"categories":["实用工具","實用工具"],"sub_categories":["高级控制台界面","高級控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falxrm%2FuGo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falxrm%2FuGo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falxrm%2FuGo/lists"}