From 7bfc78b122ad9cbb65eed16f7de4d4021547c2a8 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 23 Mar 2024 19:18:16 +0100 Subject: Some Project Euler solutions --- std/String.bruijn | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'std/String.bruijn') 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) -- cgit v1.2.3