summaryrefslogtreecommitdiff
path: root/com/simatime/string.scm
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2019-11-01 14:24:24 -0700
committerBen Sima <ben@bsima.me>2019-11-01 14:25:49 -0700
commit9756eb0806aef63137ed53c7f78eee13aa3db9d7 (patch)
tree0c3bf0becc08e37386109ff8c518fa442df6266b /com/simatime/string.scm
parent0a6fd40946f72e9995ca04b05d7556bf20585d4f (diff)
add buildHaskellApp nix function
Diffstat (limited to 'com/simatime/string.scm')
-rw-r--r--com/simatime/string.scm24
1 files changed, 24 insertions, 0 deletions
diff --git a/com/simatime/string.scm b/com/simatime/string.scm
new file mode 100644
index 0000000..01c5a70
--- /dev/null
+++ b/com/simatime/string.scm
@@ -0,0 +1,24 @@
+(define-module (com simatime string)
+ #:export (replace to-string str capitalize))
+
+(define (replace s match repl)
+ (let ((f (lambda (a b)
+ (let ((next-char (if (eq? a match) repl a)))
+ (string-concatenate (list b (string next-char)))))))
+ (string-fold f "" s)))
+
+(define (to-string x)
+ (format #f "~a" x))
+
+(define str
+ (case-lambda
+ (() "")
+ ((x) (to-string x))
+ ((x . rest) (string-concatenate (map str (cons x rest))))))
+
+(define (capitalize s)
+ (let ((s (to-string s)))
+ (if (< (string-length s) 2)
+ (string-upcase s)
+ (str (string-upcase (substring s 0 1))
+ (substring s 1 )))))