{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/16721","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/16721/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/16721/comments","events_url":"https://api.github.com/repos/golang/go/issues/16721/events","html_url":"https://github.com/golang/go/issues/16721","id":171324550,"number":16721,"title":"proposal: sort: add sort.Slice helper for sorting slices","user":{"login":"bradfitz","id":2621,"avatar_url":"https://avatars.githubusercontent.com/u/2621?v=3","gravatar_id":"","url":"https://api.github.com/users/bradfitz","html_url":"https://github.com/bradfitz","followers_url":"https://api.github.com/users/bradfitz/followers","following_url":"https://api.github.com/users/bradfitz/following{/other_user}","gists_url":"https://api.github.com/users/bradfitz/gists{/gist_id}","starred_url":"https://api.github.com/users/bradfitz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradfitz/subscriptions","organizations_url":"https://api.github.com/users/bradfitz/orgs","repos_url":"https://api.github.com/users/bradfitz/repos","events_url":"https://api.github.com/users/bradfitz/events{/privacy}","received_events_url":"https://api.github.com/users/bradfitz/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/golang/go/labels/Proposal","name":"Proposal","color":"ededed"}],"state":"open","locked":false,"assignee":{"login":"griesemer","id":8528975,"avatar_url":"https://avatars.githubusercontent.com/u/8528975?v=3","gravatar_id":"","url":"https://api.github.com/users/griesemer","html_url":"https://github.com/griesemer","followers_url":"https://api.github.com/users/griesemer/followers","following_url":"https://api.github.com/users/griesemer/following{/other_user}","gists_url":"https://api.github.com/users/griesemer/gists{/gist_id}","starred_url":"https://api.github.com/users/griesemer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/griesemer/subscriptions","organizations_url":"https://api.github.com/users/griesemer/orgs","repos_url":"https://api.github.com/users/griesemer/repos","events_url":"https://api.github.com/users/griesemer/events{/privacy}","received_events_url":"https://api.github.com/users/griesemer/received_events","type":"User","site_admin":false},"assignees":[{"login":"griesemer","id":8528975,"avatar_url":"https://avatars.githubusercontent.com/u/8528975?v=3","gravatar_id":"","url":"https://api.github.com/users/griesemer","html_url":"https://github.com/griesemer","followers_url":"https://api.github.com/users/griesemer/followers","following_url":"https://api.github.com/users/griesemer/following{/other_user}","gists_url":"https://api.github.com/users/griesemer/gists{/gist_id}","starred_url":"https://api.github.com/users/griesemer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/griesemer/subscriptions","organizations_url":"https://api.github.com/users/griesemer/orgs","repos_url":"https://api.github.com/users/griesemer/repos","events_url":"https://api.github.com/users/griesemer/events{/privacy}","received_events_url":"https://api.github.com/users/griesemer/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/30","html_url":"https://github.com/golang/go/milestones/Proposal","labels_url":"https://api.github.com/repos/golang/go/milestones/30/labels","id":1373555,"number":30,"title":"Proposal","description":"Proposals that are pending (not yet accepted/rejected).\r\n","creator":{"login":"rsc","id":104030,"avatar_url":"https://avatars.githubusercontent.com/u/104030?v=3","gravatar_id":"","url":"https://api.github.com/users/rsc","html_url":"https://github.com/rsc","followers_url":"https://api.github.com/users/rsc/followers","following_url":"https://api.github.com/users/rsc/following{/other_user}","gists_url":"https://api.github.com/users/rsc/gists{/gist_id}","starred_url":"https://api.github.com/users/rsc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsc/subscriptions","organizations_url":"https://api.github.com/users/rsc/orgs","repos_url":"https://api.github.com/users/rsc/repos","events_url":"https://api.github.com/users/rsc/events{/privacy}","received_events_url":"https://api.github.com/users/rsc/received_events","type":"User","site_admin":false},"open_issues":58,"closed_issues":41,"state":"open","created_at":"2015-10-24T01:40:49Z","updated_at":"2016-08-16T04:52:44Z","due_on":null,"closed_at":null},"comments":119,"created_at":"2016-08-16T04:52:44Z","updated_at":"2016-08-20T17:29:34Z","closed_at":null,"body":"I propose we make sorting slices a first class concept in Go 1.8.\r\n\r\nI think everybody appreciates the cute `sort.Interface` type at this point, but the reality is that:\r\n\r\n  * nobody really sorts anything except slices (the handful of exceptions can keep doing what they're doing)\r\n  * the Len and Swap functions are redundant. They're always the same for slices.\r\n  * naming a new type (e.g. \"widgetsByName\") is tedious to many (including me; I still loathe it after 6+ years)\r\n  * making a new type and three methods at the top-level (because it has to have methods, so it can't be a local type) is more difficult to read, since I'd prefer my `Less` function inline with my code, in context.\r\n\r\nI think we should add to package sort at least:\r\n\r\n```go\r\npackage sort\r\n\r\n// Slice sorts the provided slice using the function less.\r\n// The sort is not stable.\r\n// If slice is not a slice, Slice panics.\r\nfunc Slice(slice interface{}, less func(i, j int) bool)\r\n```\r\n\r\nAnd maybe at the same time, or in the future:\r\n\r\n```go\r\n// SliceSorter returns an sorter for the provided slice, suitable\r\n// for with Reverse or Stable.\r\n// If slice is not a slice, SliceSorter panics.\r\nfunc SliceSorter(slice interface{}, less func(i, j int) bool) Interface\r\n```\r\n\r\nThe assumption is that the user's `less` function would close over the data to be sorted.\r\n\r\nFor speed, this would not be purely reflect-based (except for one call to to get the slice length). The implementation would generate a custom swapper as needed for the type of the slice elements such that it's compatible with the GC & write barriers. I did a prototype of this which shows that it's as fast as the typical way.\r\n\r\nI think there's plenty of evidence in the Github BigQuery dataset that we're making sort way too hard for users.\r\n\r\n/cc @griesemer @robpike @ianlancetaylor @adg @broady"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/241212956","html_url":"https://github.com/golang/go/issues/16721#issuecomment-241212956","issue_url":"https://api.github.com/repos/golang/go/issues/16721","id":241212956,"user":{"login":"suyash","id":16324837,"avatar_url":"https://avatars.githubusercontent.com/u/16324837?v=3","gravatar_id":"","url":"https://api.github.com/users/suyash","html_url":"https://github.com/suyash","followers_url":"https://api.github.com/users/suyash/followers","following_url":"https://api.github.com/users/suyash/following{/other_user}","gists_url":"https://api.github.com/users/suyash/gists{/gist_id}","starred_url":"https://api.github.com/users/suyash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/suyash/subscriptions","organizations_url":"https://api.github.com/users/suyash/orgs","repos_url":"https://api.github.com/users/suyash/repos","events_url":"https://api.github.com/users/suyash/events{/privacy}","received_events_url":"https://api.github.com/users/suyash/received_events","type":"User","site_admin":false},"created_at":"2016-08-20T17:29:34Z","updated_at":"2016-08-20T17:29:34Z","body":"@bradfitz looks good, although I'd still like a `sort.SortWith` to go along with `sort.With`, as it falls more in line with `sort.Search` and the original proposal does define two methods, one that generates a `sort.Interface` and other that just sorts, but I also get @rajder's point, its a really minor thing and these days you can generate snippets for this kind of stuff in editors. Also, [my opinionated implementation](https://github.com/suyash/algo/blob/master/sort.go)"}}
{"actor":{"display_login":"suyash"}}