Fork me on GitHub
#test-check
<
2019-01-28
>
wilkerlucio18:01:36

hello people, I just like to share something that I done and found cool, its about how to setup complex configurable generators, in my case I did a generator setup for building random EQL queries (its like the datomic pull syntax), the way I done is by sending to generators thenselves a map environment so the user could replace parts of it when is needed, I posted some docs about it here https://github.com/edn-query-language/eql#generation. @gfredericks I would love to know what you think about this approach, its you see as a good pattern or maybe you have a better way to do it, thanks all!

gfredericks18:01:05

@wilkerlucio what's the arg to those functions that's being ignored?

wilkerlucio18:01:54

@gfredericks you mean in the default generators? if the arg is ignored it means that generator is not relying on anything that can be customised, usually the leaves in the process, makes sense?

gfredericks18:01:27

in the examples, you customize things with (fn [_] ...)

wilkerlucio18:01:52

here you can see some usages of the params

wilkerlucio18:01:05

in case you wanted to re-use something on the map, you could pull it from that argument

gfredericks18:01:20

I think you could use (constantly ...) instead of (fn [_] ...), which would be "more performant" in a maybe-doesn't-matter sense

gfredericks18:01:47

depends on if the function gets called multiple times or not

gfredericks18:01:52

which I can't tell at a glance

wilkerlucio18:01:14

interesting, I didn't knew constantly was faster, but really this is only used to build the generators, which is a rather quick operation compared to how much takes to run (and you can cache the built generator if needed to)

gfredericks18:01:18

but the general idea of passing a map of generator options down a whole tree of generators is a really good one I think, and one I've thought about for test.check

wilkerlucio18:01:44

yeah, I also found that to be a good way to control for depth, it worked quite well

gfredericks18:01:45

constantly just means that the return value gets created once, compared to a fn where it gets created every time

wilkerlucio18:01:28

ah, makes sense, so the generator will be only instantiated once per process

wilkerlucio18:01:13

at same time it would be always instantiated, even if the user doesn't use anything, seems doesn't matter much in the end :man-shrugging: