Fork me on GitHub

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 @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!


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


@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?


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


here you can see some usages of the params


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


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


depends on if the function gets called multiple times or not


which I can't tell at a glance


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)


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


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


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


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


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: