Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. (defn- minimum-required-dimensions
  2. "Find a list of minimum required dimensions for the schema.
  3.  
  4. e.g. An array of array of strings might be '(2 0 3), meaning the string must
  5. have length three, there can be zero or more strings in an array, and there
  6. must be three or more arrays of strings in the array of arrays of strings.
  7.  
  8. To simplify logic, we keep a dimension for the innermost type, even if it is
  9. an atomic type and doesn't make sense."
  10. [schema]
  11. (reduce
  12. (fn [as bs]
  13. (let [length (max (count as) (count bs))
  14. as (concat as (repeat (- length (count as)) 0))
  15. bs (concat bs (repeat (- length (count bs)) 0))]
  16. (map max as bs)))
  17. (list)
  18. (m/search schema
  19. {"minLength" (m/some ?n)} (list ?n)
  20. {"type" "array"} (list 0 0)
  21. {"items" (m/some (m/cata ?dims))} (cons 0 ?dims)
  22. {"allOf" (m/scan (m/cata ?dims))} ?dims
  23. _ (list 0))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement