From c944841dc68252ae3da9d8094ad691bad4fcb027 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Wed, 9 Aug 2023 23:15:33 +0200 Subject: [PATCH] Add NonemptyListof. --- scribblings/utils.scrbl | 6 ++++++ utils.rkt | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/scribblings/utils.scrbl b/scribblings/utils.scrbl index 6326dfc..b177ec9 100644 --- a/scribblings/utils.scrbl +++ b/scribblings/utils.scrbl @@ -45,6 +45,12 @@ the variables. } +@defform[(NonemptyListof a)]{ + +A @racket[(Listof a)] which contains at least one element. + +} + @section{Type utilities} Typed Racket's @racket[cast] should only be used as a last resort, because it diff --git a/utils.rkt b/utils.rkt index a9ca75d..4f1a7ae 100644 --- a/utils.rkt +++ b/utils.rkt @@ -4,7 +4,7 @@ (for-syntax syntax/parse racket/syntax racket/list)) (provide - Variable VariableMapping GeneralPair + Variable VariableMapping GeneralPair NonemptyListof assert-type for/first/typed for*/first/typed define/abstract/error relax-arg-type/any @@ -28,6 +28,8 @@ (define-type Variable Symbol) (define-type (VariableMapping A) (Immutable-HashTable Variable A)) +(define-type (NonemptyListof a) (Pairof a (Listof a))) + (define-syntax-parse-rule (assert-type e:expr type:expr) (assert e (make-predicate type)))