These are chat archives for dry-rb/chat

2nd
May 2017
Hannes Nevalainen
@kwando
May 02 2017 08:39 UTC
Damn, I wanna do stuff in Elixir but I'm missing dry-validation to much sigh
Piotr Solnica
@solnic
May 02 2017 10:03 UTC
hah yeah, once you start using such a solution it becomes an integral part of your system and the way you think about handling input so…I’m not surprised :)
Nick Sutterer
@apotonick
May 02 2017 10:49 UTC
Hahaha
BTW @solnic I want to make massive changes to Reform so that it's basically just a presenter around dry-v
Piotr Solnica
@solnic
May 02 2017 10:50 UTC
@apotonick let’s talk this through then, I’m working on dry-v + dry-schema 0.11 in May
Nick Sutterer
@apotonick
May 02 2017 10:55 UTC
Yeah, I mean all Reform does in addition to your work is: presentation object, mapping between DB structure and the form object, and, and that's what is underestimated all the time, the deserialization of the incoming document
That's where Representable comes into play
And I think we should also discuss how ROM could do the structural mapping part of Reform, as I am absolutely not interested in repeating what's been done better, before
Pablo Herrero
@pabloh
May 02 2017 11:50 UTC
When using dry-transaction, Is possible to modify the context within a step?
Nikita Shilnikov
@flash-gordon
May 02 2017 11:51 UTC
@pabloh wdym by saying "context"? A transaction just accepts arguments and returns a result, it doesn't have any mutable internal state
Pablo Herrero
@pabloh
May 02 2017 11:53 UTC
Doesn't it keep a context along the way where you can grab values?
Is not possible to store partial results somewhere there to use on subsequent steps?
Nikita Shilnikov
@flash-gordon
May 02 2017 11:55 UTC
you just pass them from one step to another
I use keyword args for passing several values at once
def my_step(value_1: , **rest)
  value_1_transformed = do_something(value_1)
  Right(value_1: value_1_transformed, **rest)
end
@pabloh like this^
Pablo Herrero
@pabloh
May 02 2017 11:59 UTC
So you need to make your result value a hash?
Nikita Shilnikov
@flash-gordon
May 02 2017 12:01 UTC
I use hashes, but it's up to you. You also can define a custom step http://dry-rb.org/gems/dry-transaction/custom-step-adapters/, but this is advanced usage :)
Pablo Herrero
@pabloh
May 02 2017 12:02 UTC
My question is do you have to put a hash besides the actual value in the result to have some kind of context?
Nikita Shilnikov
@flash-gordon
May 02 2017 12:02 UTC
can be arrays also, or you can define your own "context" object
the main point is that dry-transaction doesn't have a mutable state inside
Pablo Herrero
@pabloh
May 02 2017 12:05 UTC
I understand that, I meant "change" the context in the same way the state monad updates its "state".
Nikita Shilnikov
@flash-gordon
May 02 2017 12:12 UTC
yeah, in this sense a new type of step will be useful, atm we don't have any special "context" object
txn = define_transaction do
  custom_step_adapter 'step_1', using: :value_1
  custom_step_adapter 'step_2', using: :value_2
  map 'step_3'
end

txn.call(value_1: 1, value_2: 2)


def my_step(value_1)
  value_1 + 1
end

def my_step(value_2)
  value_2 + 1
end

def step_3(context)
  context # { value_1: 2, value_2: 3 } 
end
@pabloh for example^
Nick Sutterer
@apotonick
May 02 2017 12:17 UTC
@pabloh That's basically and exactly what a TRB operation provides (sorry for high-jacking)
Pablo Herrero
@pabloh
May 02 2017 12:29 UTC
Ok, will check it out.
Nick Sutterer
@apotonick
May 02 2017 12:36 UTC
@pabloh There a "context" object, we call it options which is basically a hash, and passed from step to step (per default) http://trailblazer.to/gems/operation/2.0/#state-and-result
Pablo Herrero
@pabloh
May 02 2017 12:40 UTC
So you just store the actual result in :model as a convention?
Pablo Herrero
@pabloh
May 02 2017 12:45 UTC
@apotonick, any reason yoy prefered that approach instead of storing the result separately?
Nick Sutterer
@apotonick
May 02 2017 12:52 UTC
@pabloh The result is stored separately! The options hash scopes, and knows who added what
However, most operations don't need that, so the "human" interface is very simple and looks "global", but it isn't. It took months to design it
Pablo Herrero
@pabloh
May 02 2017 12:55 UTC
I see, I think I could take a dive in the code in order to fully get it after I check out the docs some more.
George Millo
@georgemillo
May 02 2017 17:42 UTC
hey, when I clone the dry-types repo and run specs, I get failures for all tests that involve a maybe type
I imagine that this is something to do with dry-monads not being loaded?
how do I make the tests pass?
Nikita Shilnikov
@flash-gordon
May 02 2017 17:43 UTC
@georgemillo run with rake
George Millo
@georgemillo
May 02 2017 17:47 UTC
aha
thanks
looks like rake runs two rspec suites
what's going on there?
Nikita Shilnikov
@flash-gordon
May 02 2017 17:48 UTC
with/without monads ext
George Millo
@georgemillo
May 02 2017 17:48 UTC
oh wait, I answered my own question by looking in the Rakefile
funny how that happens