~jojo/Carth

8cf0fde4da215a51261906898ec8da20a077fa99 — JoJo 1 year, 2 months ago 90ccdf3
std: Add `lines` to iterate over string lines (\n)
1 files changed, 11 insertions(+), 0 deletions(-)

M std/string.carth
M std/string.carth => std/string.carth +11 -0
@@ 56,3 56,14 @@
  (if (= n 0)
      "0x0"
    (str-append "0x" (Str (array/collect (reverse (it n)))))))

(define: (lines (Str s))
    (Fun Str (Iter Str))
  (define (lines' s)
    (Iter (fun (Unit) (maybe/map (fun (i) (map-two Str
                                                   (<o lines' (array/skip 1))
                                                   (unwrap! (array/split i s))))
                                 (array/find = (cast ascii-newline) s)))))
  (lines' s))

(define: ascii-newline Nat8 (cast 0xA))