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

Ensure all examples work without sci unless mentioned otherwise #733

Merged
merged 3 commits into from
Aug 4, 2022

Conversation

vharmain
Copy link
Member

Closes #723

@vharmain vharmain added the documentation Documentation improvemen label Jul 30, 2022
@vharmain vharmain mentioned this pull request Jul 30, 2022
Copy link
Member

@ikitommi ikitommi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would not require sci:

;; portable :gen/fmap
(mg/generate
  [:and {:gen/fmap (partial str "kikka_")} string?]
  {:seed 10, :size 10})
;; => "kikka_WT3K0yax2"

if you think so, we could add both examples for clarity. anyway 👍

@vharmain
Copy link
Member Author

vharmain commented Jul 31, 2022

Good point! I adjusted it so that there are now both examples, first the "simple one" and then the portable one.

;; :gen/fmap 
(mg/generate
  [:and {:gen/fmap (partial str "kikka_")} string?]
  {:seed 10, :size 10})
;; => "kikka_WT3K0yax2"

;; portable :gen/fmap (requires `org.babashka/sci` dependency to work)
(mg/generate
  [:and {:gen/fmap '(partial str "kikka_")} string?]
  {:seed 10, :size 10})
;; => "kikka_nWT3K0ya7"

I hope it's clear enough that the first one will only work on the particular runtime and the quoted one can be serialized. 🤔 (I also hope that I got it right 😉)

@vharmain
Copy link
Member Author

vharmain commented Jul 31, 2022

Hmm I think there's similar gotcha in Multi schemas section:

Any (serializable) function can be used for :dispatch:

(m/validate
  [:multi {:dispatch 'first}
   [:sized [:tuple keyword? [:map [:size int?]]]]
   [:human [:tuple keyword? [:map [:name string?] [:address [:map [:country keyword?]]]]]]]
  [:human {:name "seppo", :address {:country :sweden}}])
; true

I guess also here unquoted first would work similarly.

@vharmain
Copy link
Member Author

vharmain commented Jul 31, 2022

Actually, @ikitommi we should probably clarify in the README what are the limitations to functions in general

  • when serialization is needed (sci)
  • when no serialization is needed (will just about any function work..?)

If you think this is a good idea I could make a separate issue + PR about it.

@ikitommi
Copy link
Member

Yes, all examples besides a specific sci-part could be without sci. Any function works in all places. Quoting is just a trick to get 'em serialized.

Feel free to tune the README however it's better.

@vharmain vharmain changed the title Add info that :gen/fmap example requires sci Ensure all examples work without sci unless mentioned otherwise Aug 4, 2022
@vharmain
Copy link
Member Author

vharmain commented Aug 4, 2022

I went through all the examples in README.md and changed them to work without sci when appropriate. Also fixed a couple small other things while going through.

I also lifted commonly used Address schema to its own section because it's assumed in many examples across the README and earlier it was defined in a bit random place.

@vharmain vharmain requested a review from ikitommi August 4, 2022 15:03
Copy link
Member

@ikitommi ikitommi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so good.

@vharmain vharmain merged commit cb48907 into master Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation improvemen
Projects
None yet
Development

Successfully merging this pull request may close these issues.

generator sample error
2 participants