From 5dfec11d7e7e7b4a415396cd956734ab6a0454a2 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 13 Oct 2013 14:46:24 -0700 Subject: [PATCH] add stringish --- readability.rkt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/readability.rkt b/readability.rkt index 0efaafb..47e1adf 100644 --- a/readability.rkt +++ b/readability.rkt @@ -232,10 +232,18 @@ (check-false ("F" . in? . #\F))) +;; stringish: data type that can be trivially converted to string +;; todo: merge this with pathish +(define/contract (stringish? x) + (any/c . -> . boolean?) + (->boolean (or path? string? symbol?))) + ;; python-style string testers (define/contract (starts-with? str starter) - (string? string? . -> . boolean?) - (and (<= (len starter) (len str)) (equal? (get str 0 (len starter)) starter))) + (stringish? stringish? . -> . boolean?) + (let ([str (->string str)] + [starter (->string starter)]) + (and (<= (len starter) (len str)) (equal? (get str 0 (len starter)) starter)))) (module+ test (check-true ("foobar" . starts-with? . "foo")) @@ -259,7 +267,7 @@ (dropf-right (dropf items test-proc) test-proc)) (module+ test -; (check-equal? (trim (list "\n" " " 1 2 3 "\n") whitespace?) '(1 2 3)) + ; (check-equal? (trim (list "\n" " " 1 2 3 "\n") whitespace?) '(1 2 3)) (check-equal? (trim (list 1 3 2 4 5 6 8 9 13) odd?) '(2 4 5 6 8)))