These are chat archives for dry-rb/chat

8th
Jun 2016
Tanner Donovan
@ttdonovan
Jun 08 2016 07:52
I’ve posted a comment about this early but did not appear to get any responses. I’m just wondering what people’s thoughts of Crystal are and if there are opportunities to port a few of the dry-rb gems to Crsytal shards. If someone where to do a port how closely would everyone want it tied back to the dry-rb ecosystem. Crystal is vey new to me but seems like it could gather a lot of attention of Ruby developers since the syntax is very similar. Here is an example of some work I’ve done over the weekend. https://github.com/ttdonovan/dry-monads.cr
Andy Holland
@AMHOL
Jun 08 2016 08:36
@ttdonovan that's cool, could create a dry-cr organisation on Github? If the concepts translate why not :)
Tim Riley
@timriley
Jun 08 2016 09:02
Yeah, Andy's idea sounds good to me.
Maciej Mensfeld
@mensfeld
Jun 08 2016 09:40
key(:stdout) { str? | array? | hash? }
`instance_eval': wrong number of arguments (given 0, expected 1..3) (ArgumentError)
any idea?
works that way: key(:stderr) { str? | array? | type?(Hash) }
Maciej Mensfeld
@mensfeld
Jun 08 2016 09:51
@solnic I think this should be fixed somewhere down the road
Fran Worley
@fran-worley
Jun 08 2016 09:52
@mensfeld you should put your example in here dry-rb/dry-validation#181
correction it is in there. With @solnic 's idea you can just do key(:stderr).type(:str?, :array?, :hash?)
Maciej Mensfeld
@mensfeld
Jun 08 2016 09:53
@fran-worley 2 late - already added ;)
Fran Worley
@fran-worley
Jun 08 2016 09:54
No worries. Essentially when @solnic has applied that change you will be able to use that new syntax which will improve things muchly!
Piotr Solnica
@solnic
Jun 08 2016 10:33
uhm, ok ;)
Tim Riley
@timriley
Jun 08 2016 10:35
What does “Pivorak” actually mean, @solnic?
Piotr Solnica
@solnic
Jun 08 2016 10:35
@timriley no idea, but I suspect it has sth to do with beer, since pivo is probably “beer” in ukrainian
fwiw it’s piwo in polish so…
Tim Riley
@timriley
Jun 08 2016 10:37
Ah :)
Will your talk be recorded?
Piotr Solnica
@solnic
Jun 08 2016 10:41
yes
I’m planning to just steal your talk :laughing: #notreally
Tim Riley
@timriley
Jun 08 2016 10:43
hehe
Just remember to update hte second slide where you introduce yourself
Piotr Solnica
@solnic
Jun 08 2016 10:44
haha
btw it’s on June 24th, and yours?
nevermind, it’s also 24th, how about that :)
Tim Riley
@timriley
Jun 08 2016 10:46
I’m actually 23rd
But I like how coordinated this is :)
Piotr Solnica
@solnic
Jun 08 2016 10:49
ohhh :)
sorry, still in the middle of my “morning” coffee
@fran-worley hey you there?
Fran Worley
@fran-worley
Jun 08 2016 10:50
@solnic Yeah hey :)
Piotr Solnica
@solnic
Jun 08 2016 10:50
@fran-worley you didn’t let it go from what I can tell :D
Fran Worley
@fran-worley
Jun 08 2016 10:51
Nope. I think that is much better than the last attempt. FYI I had to add the guard against NIL as a load of DRY-v specs were failing because predicate seemed to be nil in some cases
Piotr Solnica
@solnic
Jun 08 2016 10:51
that’s a bug
it cannot be nil, I will look into that now
Fran Worley
@fran-worley
Jun 08 2016 10:51
If you take out that commit and run the dry-rb specs again that version of dry logic you'll see where it blows up
Piotr Solnica
@solnic
Jun 08 2016 10:52
nil ໒( ˵ ° ۝ ° ˵ )७
Fran Worley
@fran-worley
Jun 08 2016 10:52
:smirk:
Piotr Solnica
@solnic
Jun 08 2016 10:54
@fran-worley did you push changes to dry-v too?
Fran Worley
@fran-worley
Jun 08 2016 10:55
@solnic not made any to Dry-v. Didn't want to until you'd looked at dry-logic. I was just playing locally
Piotr Solnica
@solnic
Jun 08 2016 10:56
please push your changes to our WIP branch in dry-v
I’ll take a look at these nil predicates
Fran Worley
@fran-worley
Jun 08 2016 10:57
Ok will do. Shall I reverse my 'nil' hack ?
Piotr Solnica
@solnic
Jun 08 2016 10:58
yeah that should not be needed
just push what you have w/o that nil check and I’ll see why specs in dry-v are failing
Fran Worley
@fran-worley
Jun 08 2016 11:00
Done.
I was wondering whether to keep this ast change separate to dry-rb/dry-validation#180 I know that it depends upon it but it is going to add a load of changes to the error and hint compilers that might be easier to deal with seperately
Piotr Solnica
@solnic
Jun 08 2016 11:03
we can separate the PRs later, I just need to make it work now :)
@fran-worley so I should just use dry-v from rework-predicates-handling?
Fran Worley
@fran-worley
Jun 08 2016 11:04
Yeah, I'll just change it to use the new dry-logic branch and then you'll see what blows up
Piotr Solnica
@solnic
Jun 08 2016 11:05
ok
so failures like that:
1) Predicates: Included In as macro with optional with maybe with invalid input is not successful
     Failure/Error: expect(result).to be_failing ['must be one of: 1, 3, 5']
       expected that #<Dry::Validation::Result output={:foo=>”4”} messages={:foo=>["must be one of: list, 1, 3, 5", "must be one of: 1, 3, 5"]}> would be failing (["must be one of: 1, 3, 5"])
are expected now right?
Fran Worley
@fran-worley
Jun 08 2016 11:06
yeah, and missing keys will be there when trying to fetch messages
Piotr Solnica
@solnic
Jun 08 2016 11:06
can you point me to one of the specs where that nil thing happens?
Fran Worley
@fran-worley
Jun 08 2016 11:07
 611) Dry::Validation::Schema defining schema using dry types fails when sum-type rule did not pass
       Failure/Error: hash[name] = rule.(input)

       NoMethodError:
         undefined method `curry' for nil:NilClass
Nikita Shilnikov
@flash-gordon
Jun 08 2016 11:08
@timriley @solnic pivo is beer and rak is crayfish :)
Piotr Solnica
@solnic
Jun 08 2016 11:09
in polish pivo is piwo and rak is rak
:D
and yet I can’t speak ukrainian :)
@fran-worley thanks, looking into it now
Tim Riley
@timriley
Jun 08 2016 11:10
@flash-gordon that is an interesting pairing!
Fran Worley
@fran-worley
Jun 08 2016 11:10
@solnic also check out form/includes_spec and excludes_spec
Piotr Solnica
@solnic
Jun 08 2016 11:11
(byebug) schema.rules.values.select { |r| r.predicate.nil? }.size
4
ooops
DAMN YOU DYNAMIC TYPING ;)
oooooh it’s because these are composite rules…so they have left/right and their predicate is nil, damn that’s a design flaw in dry-logic
Fran Worley
@fran-worley
Jun 08 2016 11:14
That's what I thought. Should I declare a special curry method for composite rules?
Piotr Solnica
@solnic
Jun 08 2016 11:15
dunno yet, gimme a few minutes
Piotr Solnica
@solnic
Jun 08 2016 11:26
@fran-worley ok so in Value#call we use curry so that we get a predicate with all its args, right?
Fran Worley
@fran-worley
Jun 08 2016 11:26
Yeah, the result then contains the completed rule
It kinda revealed a load of bugs as before you didn't seem to actually be able to curry a rule...
Piotr Solnica
@solnic
Jun 08 2016 11:27
ok so the trick is to figure out what to do when it’s a composite
Fran Worley
@fran-worley
Jun 08 2016 11:27
I guess we should curry the left and right.
E.g. https://github.com/dry-rb/dry-logic/blob/master/lib/dry/logic/rule/composite.rb#L28 should return a result with the two sides curried
Piotr Solnica
@solnic
Jun 08 2016 11:33
yeah gimme a sec, writing a spec for this use case
@fran-worley I think that is ok: dry-rb/dry-logic@31b8e45
Piotr Solnica
@solnic
Jun 08 2016 11:38
@fran-worley maybe we could provide Rule#[] that behaves like Proc so that we can simplify curried_predicate?
also, seems like arity should be our required interface and all rules should respond to it…
basically curried_predicate should boil down to predicate[*args] without these if/else checks
Fran Worley
@fran-worley
Jun 08 2016 11:42
so we do away with currying all together?
@solnic I don't think dry-rb/dry-logic@31b8e45 fixed everything. Still getting
Failure/Error: hash[name] = rule.(input)

       NoMethodError:
         undefined method `curry' for nil:NilClass

./spec/integration/form/predicates/includes_spec.rb:29
Piotr Solnica
@solnic
Jun 08 2016 11:44
on it
@fran-worley hmm this spec passes for me
make sure you git-pulled :)
dry-rb/dry-validation (master«) % be rspec spec/integration/form/predicates/includes_spec.rb:29
Run options: include {:locations=>{"./spec/integration/form/predicates/includes_spec.rb"=>[29]}}

Randomized with seed 41653
.

Finished in 0.00476 seconds (files took 0.22567 seconds to load)
1 example, 0 failures

Randomized with seed 41653
see? :D
Fran Worley
@fran-worley
Jun 08 2016 11:47
Whoops !
Piotr Solnica
@solnic
Jun 08 2016 11:48
yeah so it seems like now we just gotta update error compilers to handle extended predicate ast with param names! :)
…and fix gazilion failures in specs by doing so haha
Fran Worley
@fran-worley
Jun 08 2016 11:48
indeed :) I'm on it!
Piotr Solnica
@solnic
Jun 08 2016 11:49
oh fantastic
Fran Worley
@fran-worley
Jun 08 2016 11:49
big big thanks to @jodosha for the integration specs. I dread to think what a mess we could have made trying to do this before!
@solnic here (https://github.com/dry-rb/dry-validation/blob/master/lib/dry/validation/schema/rule.rb#L143-L156) can we access the predicate to correctly generate args for the ast?
Piotr Solnica
@solnic
Jun 08 2016 11:53
yes these specs are outstanding
@fran-worley yeah target.registry[predicate].to_ast would return everything we need
let’s start with that and figure out what to do with types/schemas later
later as in as the second step
Piotr Solnica
@solnic
Jun 08 2016 12:04
that registry bit is the new thing I added in pr 180
Piotr Solnica
@solnic
Jun 08 2016 12:16
(byebug) target.registry[predicate]
#<Dry::Logic::Predicate id=:filled? args=[]>
(byebug) target.registry[predicate].to_ast
[:predicate, [:filled?, [[:input, nil]]]]
@fran-worley really nice to see this ^ :)
Fran Worley
@fran-worley
Jun 08 2016 12:16
@solnic yup :) just found it :)
Piotr Solnica
@solnic
Jun 08 2016 12:16
this is such a fantastic improvement, i’m really excited about this
Fran Worley
@fran-worley
Jun 08 2016 12:28
@solnic can you help me find where dry-v passes the predicate ast args back to dry-logic?
Fran Worley
@fran-worley
Jun 08 2016 12:39
I've got dry-v now creating the correct predicate ast, but it now blows up everywhere as my predicate args are being set as per the ast...
Piotr Solnica
@solnic
Jun 08 2016 12:40
@fran-worley sure, just tell me what dry-v passes the predicate ast args back to dry-logic means
we create rule ast nodes in a couple of places in the dsl
is that what you’re asking?
Fran Worley
@fran-worley
Jun 08 2016 12:41
No, I've changed all those, its just that somewhere we must grab the args from the ast and use them to curry the predicates

so I end up with rules like this:

#<Dry::Logic::Rule::Implication left=#<Dry::Logic::Rule::Value predicate=#<Dry::Logic::Predicate id=:key? args=[[:name, :foo], [:input, nil]]> options={}> right=#<Dry::Logic::Rule::Key predicate=#<Dry::Logic::Predicate id=:included_in? args=[[:list, [1, 3, 5]], [:input, nil]]> options={:evaluator=>#<Dry::Logic::Evaluator::Key path=[:foo]>, :name=>:foo}>>

instead of:

#<Dry::Logic::Rule::Implication left=#<Dry::Logic::Rule::Value predicate=#<Dry::Logic::Predicate id=:key? args=[:foo]> options={}> right=#<Dry::Logic::Rule::Key predicate=#<Dry::Logic::Predicate id=:included_in? args=[[1, 3, 5]]> options={:evaluator=>#<Dry::Logic::Evaluator::Key path=[:foo]>, :name=>:foo}>>
Fran Worley
@fran-worley
Jun 08 2016 12:50
Piotr Solnica
@solnic
Jun 08 2016 12:54
@fran-worley yeah the compiler must be updated to reflect the extended ast :)
Fran Worley
@fran-worley
Jun 08 2016 12:56
@solnic we should probably add some more specs into dry-logic
Piotr Solnica
@solnic
Jun 08 2016 12:56
yeah
I’m planning to narrow down the API and add robust specs
I’ve been developing both libs side-by-side, lots of experimentation so the spec suite in dry-logic is so-so
remember that dry-logic was extracted from dry-validation
so these are the results :)
Tim Riley
@timriley
Jun 08 2016 12:58
solnic was born with 1 giant repo. Everything is an extraction.
Piotr Solnica
@solnic
Jun 08 2016 12:58
:D
yeah I don’t like bottom-up approach, better to start with a monolith and extract later when APIs are shaping up
Fran Worley
@fran-worley
Jun 08 2016 12:59
@solnic I'm really sorry but I'm going to have to put this down for now. I've now managed to make pretty much every single spec break and I've got a load of other stuff to get done!
Piotr Solnica
@solnic
Jun 08 2016 12:59
@fran-worley no worries :)
Fran Worley
@fran-worley
Jun 08 2016 13:00
plus you'll be able to fix stuff much quicker as you know how dry-v works :smiley:
Luca Guidi
@jodosha
Jun 08 2016 13:02
@fran-worley Happy to be helpful :)
Piotr Solnica
@solnic
Jun 08 2016 13:06
@fran-worley this is fine really, you’ve helped a lot already, I’ll try to wrap it up
Fran Worley
@fran-worley
Jun 08 2016 13:06
@solnic do you want me to push what I've got so far on dry-v or shall I just leave it local?
Piotr Solnica
@solnic
Jun 08 2016 13:07
@fran-worley yes pls
Fran Worley
@fran-worley
Jun 08 2016 13:10
All yours! I'm taking a break this weekend so won't be available till Monday
Piotr Solnica
@solnic
Jun 08 2016 13:11
me too, but I should have some time tomorrow
Fran Worley
@fran-worley
Jun 08 2016 13:17
Ah see I'm in France from about 7am tomorrow :)
Tim Riley
@timriley
Jun 08 2016 13:21
Wowwww
:croissant:
Fran Worley
@fran-worley
Jun 08 2016 13:22
Friend picked the best weekend to get married. England's first match in the Euros :angry:
Piotr Solnica
@solnic
Jun 08 2016 13:46
@fran-worley all predicates specs passing already :D
Fran Worley
@fran-worley
Jun 08 2016 13:47
@solnic nicely done :)
Piotr Solnica
@solnic
Jun 08 2016 13:47
I’ll wrap this up tomorrow
Luca Guidi
@jodosha
Jun 08 2016 15:52
Folks, I was thinking that probably we need an easy way to iterate through dry-v messages.
Right now I have this test application:
        html.ul do
          messages.each do |_, msgs|
            msgs.each do |message|
              li message
            end
          end
        end
These are the values:
original = result.messages(full: true) # => {:project=>{:name=>["name must be filled"]}}
messages = original.fetch(:project) # => {:name=>["name must be filled"]}
This is a very simple case and yet, the code to unwrap these values is convoluted.
To solve this we can make full: true, to return a flat array of messages. wdyt? /cc @solnic @timriley @fran-worley
Piotr Solnica
@solnic
Jun 08 2016 16:00
@jodosha yeah we could do that
Tanner Donovan
@ttdonovan
Jun 08 2016 16:02
@AMHOL and @timriley Good - glad to hear the idea about porting useful libraries was well receieved. Would someone from the dry-rb ogranization like to create dry-cr to secure the namespace? Also not sure about project naming connventions - should they all have a suffix of “.cr” i.g. here is what @mperham did with Sidekiq https://github.com/mperham/sidekiq.cr
Andy Holland
@AMHOL
Jun 08 2016 16:03
I think that's just because he has the sidekiq repository already
But in this case the -cr will differentiate it from -rb
solnic @solnic needs to play with Crystal
Andy Holland
@AMHOL
Jun 08 2016 16:04
I probably won't get into Crystal anytime soon either, so am not capable of contributing, probably better if you create it?
Tanner Donovan
@ttdonovan
Jun 08 2016 16:06
I can create it but the “dry-*” is this communities branding just thought maybe you guys would want to control ownership
I don’t want to be thought of a theif :)
Andy Holland
@AMHOL
Jun 08 2016 16:07
Not at all :)
Cool to see you taking this stuff to another language
Tim Preston
@tehpeh
Jun 08 2016 18:08
Hi everyone
Is there any guidance on reloading containers in Rails’ dev environment? Or is that a path best avoided? (I’m using dry-component)
Piotr Solnica
@solnic
Jun 08 2016 18:51
@tehpeh hey (: I’m not sure if anybody tried that before, I suspect this will need some integration with rails
as in there should be a railtie which controls it
Tim Preston
@tehpeh
Jun 08 2016 18:52
@solnic thanks for the hint :) I’ll check that out.
Piotr Solnica
@solnic
Jun 08 2016 18:55
also keep in mind that these are early days of dry-component so things will be changing
Tim Preston
@tehpeh
Jun 08 2016 19:00
Sure. I’ve already found value in it with a project I’m working on.. so thanks to you and contributors
Piotr Solnica
@solnic
Jun 08 2016 19:13
oh that’s cool to know thank you :)
Tim Riley
@timriley
Jun 08 2016 20:42
Hey @tehpeh! Nice to see you here.
Tim Preston
@tehpeh
Jun 08 2016 20:42
@timriley good morning!
I’ve been lurking for a couple of weeks. Your blog series brought me here, it’s really good!
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 08 2016 21:02
@solnic Should I close dry-rb/dry-validation#170 it was fixed with the latest releases on master.
Piotr Solnica
@solnic
Jun 08 2016 21:05
@mrbongiolo if you can confirm that it's fixed then yeah
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 08 2016 21:05
The specs I added on dry-rb/dry-validation#172 are passing, so it's fixed
not sure if you want to merge those specs or not
Piotr Solnica
@solnic
Jun 08 2016 21:27
I just did
Tim Riley
@timriley
Jun 08 2016 21:29
@tehpeh nice! Glad it helped. Feel free to ask questions here :)
Tim Preston
@tehpeh
Jun 08 2016 21:30
will do :+1:
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 08 2016 21:36
@timriley any reason why you didn't used dry-result_matcher for dry-transaction?
Tim Riley
@timriley
Jun 08 2016 21:37
@mrbongiolo dry-transaction was written first. The idea for the result matched came out of it, but so far it only exists for the simplest case. I'd like to add support for configurable pattern matching so that dry-transaction can use it :)
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 08 2016 21:37
Ah I see :)
What kind of pattern matching?
Piotr Solnica
@solnic
Jun 08 2016 21:40
@mrbongiolo we have stuff like r.failure { |e| e.on(:validation) { ... } }
Tim Riley
@timriley
Jun 08 2016 21:41
Yeah, that :)
Piotr Solnica
@solnic
Jun 08 2016 21:41
so you can match on specific failure type
awesome I know ;)
I actually thought result_matcher has that already and it's used by transaction O_o
maybe let's report an issue with help-wanted label
Tim Riley
@timriley
Jun 08 2016 21:42
Yeah. It's so obvious that's the way it should be.
Yes, let's.
Piotr Solnica
@solnic
Jun 08 2016 21:42
gimme a sec
I'll do it NAU
dry-rb/dry-transaction#31 #help-wanted
Tim Riley
@timriley
Jun 08 2016 21:45
Thanks, I'm walking to work right now 🚶🏻
Piotr Solnica
@solnic
Jun 08 2016 21:45
walking? nice :)
I walk to work too, but it's literally 1 minute 17 seconds, not much walking O_o
Tim Riley
@timriley
Jun 08 2016 21:48
25 minutes and a ☕️ en route :)
Piotr Solnica
@solnic
Jun 08 2016 21:55
perfect, sounds like my 5k steps limit that I often fail to reach O_o
Tim Riley
@timriley
Jun 08 2016 22:00
Hehe. Yeah, it's a nice time period to start/end the day
You need to walk around the block a few times, @solnic ;)
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 08 2016 22:09
@solnic in my case I just use the default failure matcher and then check the kind of error that was raised, I added some custom errors like UnprocessableEntity and EntityNotFound that I raise from a step if something goes wrong
Piotr Solnica
@solnic
Jun 08 2016 22:50
no need for exceptions man, just do Left(:entity_not_found)
Tim Riley
@timriley
Jun 08 2016 22:51
Yeah, that’s much nicer. Eventually with a more flexible result_matcher, we could even match on things like that.
Piotr Solnica
@solnic
Jun 08 2016 22:51
not just nicer, it's faster too, rescuing from exception is slower
Tim Riley
@timriley
Jun 08 2016 22:52
I discovered that one time, years ago, when I was using virtus :grimacing:
Piotr Solnica
@solnic
Jun 08 2016 22:52
what's virtus?

badjoke

geeez
I better go to sleep already
Tim Riley
@timriley
Jun 08 2016 22:54
haha!
Joe Van Dyk
@joevandyk
Jun 08 2016 23:47
@timriley thanks!
(for dry-monads release)
Tim Riley
@timriley
Jun 08 2016 23:47
You’re welcome :)
Joe Van Dyk
@joevandyk
Jun 08 2016 23:49
@timriley http://dry-rb.org/gems/dry-result_matcher/ should be updated i think?
dry-result_matcher is an expressive, all-in-one API for operating on Kleisli Either results.
Tim Riley
@timriley
Jun 08 2016 23:50
yeah, it should! Mind making the change? I can deploy it right away.