-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Related problem
It is not easy to group/sort data with sub-keys.
Consider the following data structure storing Twitter tweets.
let tweets = [
{
"author": {
"id": 1,
"username": "mon-jai"
},
"created": 1677877558
"caption": "Hello world",
"comments": [{}, {}, {}]
},
# ...
]
In today's Nushell,
What if I want to group tweets by author?
$tweets | each {|$it| insert author_username { $it | get author.username } } | group-by author_username
What if I want to sort tweets by comments count?
$tweets | each {|$it| insert comments_count { $it | get comments | length } } | sort-by comments_count
The solution requires us to process the data beforehand and is not straight forward.
Describe the solution you'd like
By supporting sub-record keys and closures in group-by
/sort-by
, we can process the data more conveniently.
Sub-record keys
$tweets | group-by author.username
Closures
$tweets | sort-by { get comments | length }
Describe alternatives you've considered
No response
Additional context and details
No response
m0lentum and cablehead
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request