diff --git a/racket/typed/examples/roles/flink-support.rkt b/racket/typed/examples/roles/flink-support.rkt new file mode 100644 index 0000000..c26d79f --- /dev/null +++ b/racket/typed/examples/roles/flink-support.rkt @@ -0,0 +1,32 @@ +#lang racket + +(provide string->words + split-at/lenient-) + +(require (only-in racket/list + split-at)) +(module+ test + (require rackunit)) + +(define (string->words s) + (map (lambda (w) (string-trim w #px"\\p{P}")) (string-split s))) + +(module+ test + (check-equal? (string->words "good day sir") + (list "good" "day" "sir")) + (check-equal? (string->words "") + (list)) + (check-equal? (string->words "good eve ma'am") + (list "good" "eve" "ma'am")) + (check-equal? (string->words "please sir. may I have another?") + (list "please" "sir" "may" "I" "have" "another")) + ;; TODO - currently fails + #;(check-equal? (string->words "but wait---there's more") + (list "but" "wait" "there's" "more"))) + +;; (Listof A) Nat -> (List (Listof A) (Listof A)) +;; like split-at but allow a number larger than the length of the list +(define (split-at/lenient- lst n) + (define-values (a b) + (split-at lst (min n (length lst)))) + (list a b))