From 53aee56ef8fa73d8a238108d4916a9e5364344e8 Mon Sep 17 00:00:00 2001 From: toinux <26522723+itzwam@users.noreply.github.com> Date: Fri, 27 Dec 2024 15:20:15 +0100 Subject: [PATCH 1/2] Update nushell_map_functional.md - Add Nix equivalents --- book/nushell_map_functional.md | 83 +++++++++++++++++----------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/book/nushell_map_functional.md b/book/nushell_map_functional.md index d66018e3a76..05e1781e7e2 100644 --- a/book/nushell_map_functional.md +++ b/book/nushell_map_functional.md @@ -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 | `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` | +| 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[]` | +| open | with-open | | | N/A (Declarative paradigm) | +| transpose | (apply mapv vector matrix) | | transpose | Custom function | +| prepend | cons | cons, :: | :: | `[value] ++ list` | +| print | println | | putStrLn, print | `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 | `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 | `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 | `builtins.uniq` | +| where | filter, filterv, select | filter, filterMap | filter | `filter` | + From 97f4dd79e601c29a16cb6345dcb08b268e08891a Mon Sep 17 00:00:00 2001 From: toinux <26522723+itzwam@users.noreply.github.com> Date: Fri, 27 Dec 2024 15:25:25 +0100 Subject: [PATCH 2/2] Update nushell_map_functional.md Fixes some incorrect functions mapping --- book/nushell_map_functional.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/book/nushell_map_functional.md b/book/nushell_map_functional.md index 05e1781e7e2..047ae55be61 100644 --- a/book/nushell_map_functional.md +++ b/book/nushell_map_functional.md @@ -8,7 +8,7 @@ Note: this table assumes Nu 0.43 or later. | ------------ | ---------------------------- | ------------------------------- | ------------------------ | ------------------------------ | | append | conj, into, concat | append, (++), concat, concatMap | (++) | `builtins.concatLists` | | into binary | Integer/toHexString | | showHex | `toString (toHex value)` | -| count | count | length, size | length, size | `length` | +| 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` | @@ -24,18 +24,18 @@ Note: this table assumes Nu 0.43 or later. | open | with-open | | | N/A (Declarative paradigm) | | transpose | (apply mapv vector matrix) | | transpose | Custom function | | prepend | cons | cons, :: | :: | `[value] ++ list` | -| print | println | | putStrLn, print | `trace` | +| 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 | `length` | +| 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 | `splitString` | +| 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 | @@ -43,6 +43,6 @@ Note: this table assumes Nu 0.43 or later. | 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 | `builtins.uniq` | +| uniq | set | Set.empty | Data.Set | `lib.unique` | | where | filter, filterv, select | filter, filterMap | filter | `filter` |