You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
typesetting/quad/utils-typed.rkt

29 lines
1.4 KiB
Racket

10 years ago
#lang typed/racket/base
10 years ago
(require sugar/list)
(require (for-syntax racket/syntax racket/base) racket/string racket/list sugar/debug racket/bool hyphenate racket/function math/flonum)
10 years ago
(require "quads-typed.rkt" "world-typed.rkt" "measure-typed.rkt")
;; predicate for use below
10 years ago
(: list-of-mergeable-attrs? (Any . -> . Boolean))
10 years ago
(define (list-of-mergeable-attrs? xs)
(and (list? xs) (andmap (λ(x) (or (quad? x) (quad-attrs? x) (hashable-list? x))) xs)))
;; faster than (listof pair?)
10 years ago
(: pairs? (Any . -> . Boolean))
10 years ago
(define (pairs? x) (and (list? x) (andmap pair? x)))
;; push together multiple attr sources into one list of pairs.
;; mostly a helper function for the two attr functions below.
10 years ago
(provide join-attrs)
(: join-attrs ((Listof (U Quad QuadAttrs HashableList)) . -> . (Listof QuadAttrPair)))
10 years ago
(define (join-attrs quads-or-attrs-or-lists)
10 years ago
((inst append-map QuadAttrPair QuadAttrs) (inst hash->list QuadAttrKey QuadAttrValue) (map (λ(x)
10 years ago
(cond
[(quad? x) (quad-attrs x)]
10 years ago
[(quad-attrs? x) (cast x QuadAttrs)]
10 years ago
[(hashable-list? x) (quadattrs (cast x (Listof Any)))]
10 years ago
[else (cast hash QuadAttrs)])) quads-or-attrs-or-lists)))
10 years ago
10 years ago