These are chat archives for dry-rb/chat

29th
Oct 2016
George Millo
@georgemillo
Oct 29 2016 13:46
@solnic is there any update on this issue? dry-rb/dry-validation#213
a matcher like this would be extremely useful. such a common use case
(I'm currently digging around in the dry-logic/dry-v source code trying to figure out how I could add it myself)
I don't like the name filled_str? though... But I'm not sure what the alternative could be
Piotr Solnica
@solnic
Oct 29 2016 14:17
@georgemillo we can add it in the next version
I won’t have time to work on dry-v in the upcoming weeks though
George Millo
@georgemillo
Oct 29 2016 14:51
next version = 1.0.0?
so possibility of breaking changes?
I'd argue that filled? should cover this case anyway. Intuitively it seems like a 'filled' string would be one that contains characters other than whitespace
but then I suppose if would also be confusing if filled?({}) == !{}.empty? but filled?(" ") != " ".empty?
Piotr Solnica
@solnic
Oct 29 2016 16:36
@georgemillo no, next version as in next version, whatever it’s going to be :) probably 0.10.x or 0.11
although I’d prefer to have 1.0.0.beta as the next one, but it depends on how much time I will have
George Millo
@georgemillo
Oct 29 2016 16:47
@solnic well here's my attempt at a PR for the above macro ;) dry-rb/dry-logic#25
hope you like it
George Millo
@georgemillo
Oct 29 2016 17:05
On another note... and I realise I may be bikeshedding here:
George Millo
@georgemillo
Oct 29 2016 17:10
        def empty?(input)
          case input
          when String, Array, Hash then input.empty?
          when nil then true
          else
            false
          end
        end

Wouldn't it be better to use duck-typing on input rather than explicitly testing its class? So the above could be rewritten as:

        def empty?(input)
          return true if input.nil?
          input.respond_to?(:empty?) ? input.empty? : false
        end

That doesn't break the existing test suite, but it could break code where people are using custom classes that respond to empty?. But if you have a custom class that responds to empty? you'd expect the empty? predicate to return true for it, so the current behaviour is "wrong"

Piotr Solnica
@solnic
Oct 29 2016 18:31
@georgemillo the intention was to make this work exclusively with “data” types, even though it’s against duck-typing. This predicate needs some discussion, I’ll report an issue about it so more people can chime in. We gotta sort it out prior 1.0.0 final
re breaking changes in 1.0.0, we may have some of those, but nothing major
George Millo
@georgemillo
Oct 29 2016 18:38
ah right
Nikita Shilnikov
@flash-gordon
Oct 29 2016 19:27
@solnic FYI Sum type raise an error even if both left and right types are non-strict
2.3.1 :001 > Types::Bool.left[nil]
 => nil
2.3.1 :002 > Types::Bool.right[nil]
 => nil
2.3.1 :003 > Types::Bool[nil]
Dry::Types::ConstraintError: nil violates constraints (nil must be an instance of FalseClass failed)
    from /Users/gordon/dev/dry-types/lib/dry/types/sum.rb:48:in `block in call'
    from /Users/gordon/dev/dry-types/lib/dry/types/sum.rb:61:in `try'
    from /Users/gordon/dev/dry-types/lib/dry/types/sum.rb:47:in `call'
    from (irb):3
    from ./bin/console:18:in `<main>'
we're using Types::Bool for booleans in rom-sql atm, that's why hanami fails a spec against rom-sql's master
I think we should use another type type in rom-sql for this
Piotr Solnica
@solnic
Oct 29 2016 20:51
Seems like a bug