(define-module (uniseg graphemes stream) #:use-module (uniseg graphemes iterator) #:use-module (ice-9 textual-ports) #:use-module (srfi srfi-41) #:export (string->grapheme-stream input->grapheme-stream)) (define (string->grapheme-stream str) "Given a string, create a (lazy) stream of graphemes." (call-with-input-string str input->grapheme-stream)) (define (input->grapheme-stream port) "Given an input port, create a (lazy) stream of graphemes." (define grapheme-iterator (make-grapheme-iterator)) (define-stream (grapheme-stream) (define grapheme (grapheme-iterator (get-char port))) (if grapheme (stream-cons grapheme (grapheme-stream)) stream-null)) (grapheme-stream))