Type union-products.

This commit is contained in:
Sergiu Ivanov 2023-08-10 01:07:41 +02:00
parent c944841dc6
commit b29f98105f
2 changed files with 33 additions and 1 deletions

22
rs.rkt
View file

@ -5,7 +5,7 @@
(provide
Species (struct-out reaction) Reaction ReactionName ReactionSystem
make-reaction enabled? list-enabled)
make-reaction enabled? list-enabled union-products)
(module+ test
(require typed/rackunit))
@ -57,6 +57,26 @@
'b (make-reaction '(x y) '() '(z))))
(check-equal? (list-enabled rs (set 'x 'y)) '(b))
(check-equal? (list-enabled rs (set 'x)) '(a))))
(: union-products (-> ReactionSystem (Listof ReactionName) (Setof Species)))
(define (union-products rs as)
(cond
[(empty? as) (set)]
[else (define products (for/list : (Listof (Setof Species))
([a as])
(reaction-products (hash-ref rs a))))
(apply set-union (assert-type products (NonemptyListof (Setof Species))))]))
(module+ test
(test-case "union-products"
(define rs (hash 'a (make-reaction '(x) '(y) '(z))
'b (make-reaction '(x y) '() '(t))))
(check-equal? (union-products rs '(a b))
(set 't 'z))
(check-equal? (union-products rs '(a))
(set 'z))
(check-equal? (union-products rs '())
(set))))
)
(require graph "utils.rkt" "generic.rkt")

View file

@ -99,6 +99,18 @@ Returns the list of the names of reactions of @racket[rs] enabled on
(list-enabled rs (set 'x))))
]}
@defproc[(union-products [rs ReactionSystem] [as (Listof ReactionName)])
(Setof Species)]{
Returns the union of the product sets of the given reactions listed in
@racket[as] in @racket[rs]. If no reactions are supplied, returns the
empty set.
@ex[
(union-products (hash 'a (make-reaction '(x) '(y) '(z))
'b (make-reaction '(x y) '() '(z)))
'(a b))
]}
@section{Org-mode interaction}