These are chat archives for dry-rb/chat

10th
Apr 2017
James Ottaway
@jamesottaway
Apr 10 2017 03:51
any tips on turning a Dry::Validation::Result into an Either? i've just written a refinement, but I'm wondering whether there's potential for it to be a first-class method
Tim Riley
@timriley
Apr 10 2017 05:01
@jamesottaway here you go:
Dry::Validation.load_extensions(:monads)

sch = Dry::Validation.Schema do
  required(:greeting)
end

sch.(greeting: "hi").to_either
# => Right({:greeting=>"hi"})
James Ottaway
@jamesottaway
Apr 10 2017 06:40
@timriley amazing, thanks!
now, where to put that .load_extensions call…
also, I just invented #ftap :grin:
require "dry-monads"

module Refinements
  module DryMonads
    refine Dry::Monads::Either::Right do
      def ftap
        yield value
        self
      end
    end

    refine Dry::Monads::Either::Left do
      def ftap
        self
      end
    end
  end
end
Tim Riley
@timriley
Apr 10 2017 06:47
heh
The right place to put that load_extensions call would be something that gets run just once when your app boots, usually
Alexander Gräfe
@rickenharp
Apr 10 2017 06:51
Hello. I've been trying out dry-transaction, and it works great for our use case. But while trying to add logging through step notifications, I noticed that I can't seem to get at the initial step args in the *_success method. Is that by design?
Gustavo Caso
@GustavoCaso
Apr 10 2017 06:55
Did you subscribe with your Listener ?
Alexander Gräfe
@rickenharp
Apr 10 2017 06:55
Yes, I am looking at the code right now, and on success, you only get the return value of the step
Gustavo Caso
@GustavoCaso
Apr 10 2017 06:56
Uhh
Would you need to return something else ?
Tim Riley
@timriley
Apr 10 2017 06:57
@rickenharp Feel free to file a GH issue with some details and we can have a discussion about it.
Alexander Gräfe
@rickenharp
Apr 10 2017 06:57
Okay.