mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 06:30:08 +02:00
Add zip-into-record
to std iter (#9395)
# Description Adds a new iter feature `zip-into-record` (#9380) # User-Facing Changes User can use `[1 2] | iter zip-into-record [3 4]` to create a table `[[1 2]; [3 4]]` # Tests + Formatting I noticed trailing spaces in std library that may wish to be cleaned in the future. Co-authored-by: amtoine <stevan.antoine@gmail.com>
This commit is contained in:
@ -197,3 +197,26 @@ export def zip-with [ # -> list<any>
|
||||
reduce {|it, acc| do $fn $acc $it }
|
||||
}
|
||||
}
|
||||
|
||||
# Zips two lists and returns a record with the first list as headers
|
||||
#
|
||||
# # Example
|
||||
# ```nu
|
||||
# use std ["assert equal" "iter iter zip-into-record"]
|
||||
#
|
||||
# let res = (
|
||||
# [1 2 3] | iter zip-into-record [2 3 4]
|
||||
# )
|
||||
#
|
||||
# assert equal $res [
|
||||
# [1 2 3];
|
||||
# [2 3 4]
|
||||
# ]
|
||||
# ```
|
||||
export def zip-into-record [ # -> table<any>
|
||||
other: list # the values to zip with
|
||||
] {
|
||||
into record
|
||||
| append ($other | into record)
|
||||
| headers
|
||||
}
|
Reference in New Issue
Block a user