Dear Russian friends, please watch President Zelenskyy's speech addressed to you. 🇺🇦Help our brave mates in Ukraine with a donation.


Predicate logic and rule composition used by:


require 'dry/logic'
require 'dry/logic/predicates'

include Dry::Logic

# Rule::Predicate will only apply its predicate to its input, that’s all

# require input to have the key :user
user_present =[:key?]).curry(:user)
# curry allows us to prepare predicates with args, without the input

# require value to be greater than 18
min_18 =[:gt?]).curry(18)

# use the min_18 predicate on the value of user[:age]
has_min_age =, name: [:user, :age])

user_rule = user_present & has_min_age

user_rule.(user: { age: 19 }).success?
# => true

user_rule.(user: { age: 18 }).success?
# => false

user_rule.(user: { age: 'seventeen' })
# => ArgumentError: comparison of String with 18 failed

user_rule.(user: { })
# => NoMethodError: undefined method `>' for nil:NilClass

# => false

octocatEdit on GitHub