dry-rb / dry-logic

Predicate logic with rule composition
https://dry-rb.org/gems/dry-logic/
MIT License
179 stars 66 forks source link

Extend documentation for predicates and operations #79

Closed oleander closed 3 years ago

oleander commented 3 years ago

I have this documentation laying around for dry-logic I used internally for the company I'm currently working for. I thought it might be useful for others, besides me and my colleagues.

To verify that examples I wrote for the documentation actually worked I decided to write a simple predicate/operation builder. I'm not sure how this could be incorporated into the documentation or if it belongs elsewhere (maybe as an extension?) but I decided to include it here as the documentation is written around it. We might want to polish the documentation further before we decided to merge it–if we decide to merge it.

The so called "builder" found in docs/builder.html.md defines a DSL for operations and predicates and was written to make the documentation less verbose.

extend Build

is_num = build do
  int? | float? | number?
end

is_num.call(10).success? # => true
is_num.call('ten').success? # => false

Let me know if this can be useful and what changes you would like to see.

The pull request contains

oleander commented 3 years ago

Split this PR into #81 and #80 as suggested by @solnic