Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion to implementation of coercion string->ratio in clojure #209

Closed
wandersoncferreira opened this issue Jan 15, 2020 · 0 comments
Closed
Milestone

Comments

@wandersoncferreira
Copy link
Contributor

wandersoncferreira commented Jan 15, 2020

It makes sense to have this kind of solution to provide a coercion to ratio in spec-tools?

(defn string->ratio [x]
  (let [x' (clojure.edn/read-string x)]
    (if (ratio? x')
      x'
      x)))

Only the core of the function, all the safeguards would be provided. The question is more related to the safety of using a read-string function to evaluate arbitrary string values. As noted by Clojure.docs read-string clojure.edn would be appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants