Last active
February 12, 2026 18:21
-
-
Save ErichDonGubler/80b622e97bc275b90da613128f83a8f7 to your computer and use it in GitHub Desktop.
collate-front-and-back-feed-scans
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # "Zip"/collate an even number of items such that every other item is pulled from the back. | |
| # | |
| # This is appropriate for scans of a stack of documents that run all front sides, then all back | |
| # sides. | |
| # | |
| # # Examples | |
| @example "reorder page numbers from a feed scanner" { [1 3 4 2] | collate-front-and-back-feed-scans } --result [1 2 3 4] | |
| export def "main" [ | |
| ]: list<any> -> list<any> { | |
| mut input = $in | |
| mut output = [] | |
| if ($input | length | $in mod 2) != 0 { | |
| error make { | |
| msg: "provided list's length is not divisible by 2" | |
| label: { | |
| span: (metadata $input).span | |
| } | |
| } | |
| } | |
| while ($input | is-not-empty) { | |
| let front = $input | first --strict | |
| let back = $input | last --strict | |
| $output = $output | append [$front, $back] | |
| $input = $input | slice 1..-2 | |
| } | |
| $output | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment