aboutsummaryrefslogtreecommitdiffhomepage
path: root/std/String.bruijn
diff options
context:
space:
mode:
authorMarvin Borner2024-03-23 19:18:16 +0100
committerMarvin Borner2024-03-23 19:18:16 +0100
commit7bfc78b122ad9cbb65eed16f7de4d4021547c2a8 (patch)
treee45a22aeddb12257a94e32083ed10dfa3a0da66e /std/String.bruijn
parentfc9980e5e19602748b8cc596cdd07c02ac2889f1 (diff)
Some Project Euler solutions
Diffstat (limited to 'std/String.bruijn')
-rw-r--r--std/String.bruijn6
1 files changed, 6 insertions, 0 deletions
diff --git a/std/String.bruijn b/std/String.bruijn
index e1f4f4b..6ffd1f4 100644
--- a/std/String.bruijn
+++ b/std/String.bruijn
@@ -110,6 +110,12 @@ number→string (map C.number→char) ∘ number→list ⧗ Number → String
:test (number→string (+123)) ("123")
+# trims whitespace from the beginning and end of a string
+trim w b (reverse ∘ (drop-while (ni? "\t\r\n "))) ⧗ String → String
+
+:test (trim " ab ") ("ab")
+:test (trim "\t\r\nab\t\r\n") ("ab")
+
# splits string by newline character
lines z [[rec]] ⧗ String → (List String)
rec build (break (B.eq? '\n') 0)