Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nushell_map_functional.md - Add Nix equivalents #1711

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 42 additions & 41 deletions book/nushell_map_functional.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,45 @@ The idea behind this table is to help you understand how Nu builtins and plugins

Note: this table assumes Nu 0.43 or later.

| Nushell | Clojure | Tablecloth (Ocaml / Elm) | Haskell |
| ------------ | ---------------------------- | ------------------------------- | ------------------------ |
| append | conj, into, concat | append, (++), concat, concatMap | (++) |
| into binary | Integer/toHexString | | showHex |
| count | count | length, size | length, size |
| date | java.time.LocalDate/now | | |
| each | map, mapv, iterate | map, forEach | map, mapM |
| exit | System/exit | | |
| first | first | head | head |
| format | format | | Text.Printf.printf |
| group-by | group-by | | group, groupBy |
| help | doc | | |
| is-empty | empty? | isEmpty | |
| last | last, peek, take-last | last | last |
| lines | | | lines, words, split-with |
| match | | match (Ocaml), case (Elm) | case |
| nth | nth | Array.get | lookup |
| open | with-open | | |
| transpose | (apply mapv vector matrix) | | transpose |
| prepend | cons | cons, :: | :: |
| print | println | | putStrLn, print |
| range, 1..10 | range | range | 1..10, 'a'..'f' |
| reduce | reduce, reduce-kv | foldr | foldr |
| reverse | reverse, rseq | reverse, reverseInPlace | reverse |
| select | select-keys | | |
| shuffle | shuffle | | |
| size | count | | size, length |
| skip | rest | tail | tail |
| skip until | drop-while | | |
| skip while | drop-while | dropWhile | dropWhile, dropWhileEnd |
| sort-by | sort, sort-by, sorted-set-by | sort, sortBy, sortWith | sort, sortBy |
| split row | split, split-{at,with,lines} | split, words, lines | split, words, lines |
| str | clojure.string functions | String functions | |
| str join | join | concat | intercalate |
| str trim | trim, triml, trimr | trim, trimLeft, trimRight | strip |
| sum | apply + | sum | sum |
| take | take, drop-last, pop | take, init | take, init |
| take until | take-while | takeWhile | takeWhile |
| take while | take-while | takeWhile | takeWhile |
| uniq | set | Set.empty | Data.Set |
| where | filter, filterv, select | filter, filterMap | filter |
| Nushell | Clojure | Tablecloth (Ocaml / Elm) | Haskell | Nix |
| ------------ | ---------------------------- | ------------------------------- | ------------------------ | ------------------------------ |
| append | conj, into, concat | append, (++), concat, concatMap | (++) | `builtins.concatLists` |
| into binary | Integer/toHexString | | showHex | `toString (toHex value)` |
| count | count | length, size | length, size | `builtins.length` |
| date | java.time.LocalDate/now | | | `builtins.time` |
| each | map, mapv, iterate | map, forEach | map, mapM | `map` |
| exit | System/exit | | | `throw` |
| first | first | head | head | `builtins.head` |
| format | format | | Text.Printf.printf | `builtins.toString` |
| group-by | group-by | | group, groupBy | Custom function with `map` |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This table should help folks quickly find the relevant Nushell command or construct if they have a particular language construct or idiom from other languages in mind or understand the meaning at a glance, so it should probably be left blank if you would have to come up with something custom in the other language. Its docs for Nushell not for Nix.

| help | doc | | | N/A (Check Nix docs) |
| is-empty | empty? | isEmpty | | `length == 0` |
| last | last, peek, take-last | last | last | `builtins.last` |
| lines | | | lines, words, split-with | `splitString ""` |
| match | | match (Ocaml), case (Elm) | case | N/A (Custom logic) |
| nth | nth | Array.get | lookup | `list[<index>]` |
| open | with-open | | | N/A (Declarative paradigm) |
| transpose | (apply mapv vector matrix) | | transpose | Custom function |
| prepend | cons | cons, :: | :: | `[value] ++ list` |
| print | println | | putStrLn, print | `builtins.trace` |
| range, 1..10 | range | range | 1..10, 'a'..'f' | `builtins.genList` |
| reduce | reduce, reduce-kv | foldr | foldr | Custom function with `fold` |
| reverse | reverse, rseq | reverse, reverseInPlace | reverse | `builtins.reverse` |
| select | select-keys | | | Custom function with `attr` |
| shuffle | shuffle | | | N/A (Write custom logic) |
| size | count | | size, length | `builtins.length` |
| skip | rest | tail | tail | `builtins.tail` |
| skip until | drop-while | | | Custom function with `filter` |
| skip while | drop-while | dropWhile | dropWhile, dropWhileEnd | Custom function with `filter` |
| sort-by | sort, sort-by, sorted-set-by | sort, sortBy, sortWith | sort, sortBy | Custom sort logic |
| split row | split, split-{at,with,lines} | split, words, lines | split, words, lines | `lib.splitString` |
| str | clojure.string functions | String functions | | `builtins.toString` |
| str join | join | concat | intercalate | `builtins.concatStringsSep` |
| str trim | trim, triml, trimr | trim, trimLeft, trimRight | strip | Custom function |
| sum | apply + | sum | sum | Custom fold logic |
| take | take, drop-last, pop | take, init | take, init | `builtins.slice` |
| take until | take-while | takeWhile | takeWhile | Custom function |
| take while | take-while | takeWhile | takeWhile | Custom function |
| uniq | set | Set.empty | Data.Set | `lib.unique` |
| where | filter, filterv, select | filter, filterMap | filter | `filter` |