These are chat archives for dry-rb/chat

10th
Nov 2016
Ramon Tayag
@ramontayag
Nov 10 2016 00:13
I see - thanks @solnic
Ramon Tayag
@ramontayag
Nov 10 2016 03:17

Given

schema = Dry::Validation.Schema do
  required(:age)
end

I expect to see an error that the key is missing when I do schema.({}).errors. Am I understanding right?

Soumya Ray
@soumyaray
Nov 10 2016 05:55

I'm playing around with dry-monads for the first time, and I'm not sure if I'm using it as expected. Here's an example of a simple service object that I'm trying to make using it:

class FindGroup
  extend Dry::Monads::Either::Mixin

  def self.call(params)
    Right(params[:id]).bind do |group_id|
      group = Group.find(id: group_id)
      if group
        Right(group)
      else
        Left(Error.new(:not_found, 'Group not found'))
      end
    end
  end
end

Does this look right? Should I be using dry-transactions or something else over this?

The thing that is bothering me most right now is that this style of coding very quickly becomes hard to read with more complex examples.

Nikita Shilnikov
@flash-gordon
Nov 10 2016 08:06
@soumyaray more or less, could be simplified ```
  def self.call(params)
    group = Group.find(id: params[:group_id])
    if group
      Right(group)
    else
      Left(Error.new(:not_found, 'Group not found'))
    end
  end
monads are just some sort of containers
they are giving you a unified interface for dealing with things, but nothing more
dry-transaction is an example of what you can do next by gluing your monads together :)
@soumyaray we often recommend this video to watch http://fsharpforfunandprofit.com/rop/
Soumya Ray
@soumyaray
Nov 10 2016 08:13

@flash-gordon i agree! i was a influenced by the documentation of dry-monads, which has this:

    i = Integer(input)

    Right(i).bind do |value|
      if value > 1
        Right(value + 3)
      else
        Left("value was less than 1")
      end
    end.bind do |value|
      if value % 2 == 0
        Right(value * 2)
      else
        Left("value was not even")
      end
    end

I'll sit and give that video a watch. Like with many things that are new to Ruby (concurrency paradigms, monads, etc.), it really hard for those of use who haven't seen those used in another language.

Many thanks for your input!
Nikita Shilnikov
@flash-gordon
Nov 10 2016 08:15
yeah, docs can be too brief or shallow for giving you a sense of what's this all about
Nick Sutterer
@apotonick
Nov 10 2016 09:26
@timriley you around?
i'm trying to integrate your auto_inject code
Nick Sutterer
@apotonick
Nov 10 2016 09:35
...and i'm successful! i want you to commit that file, though
Martin Komara
@scare21410
Nov 10 2016 14:17
Hey guys, is there any reason why TRUE_VALUES miss Y in Dry::Types::Coercions::Form? There are 1 on On ON t true True TRUE T y yes Yes YES and I think Y should be there too. Same for N and FALSE_VALUES
Tim Riley
@timriley
Nov 10 2016 20:12
@apotonick commit the file? I don't think it'd make sense to ship with dry-auto_inject itself, since its such a specialized use case. Could you ship it as part of your operations gem?
@scare21410 I'm sure it's just an oversight - submit a PR and I'm sure we'll pull it in :)
Piotr Solnica
@solnic
Nov 10 2016 22:50
:+1: for Y and N
Fran Worley
@fran-worley
Nov 10 2016 22:59
@solnic :+1: from me too for what it's worth!
Piotr Solnica
@solnic
Nov 10 2016 23:01
we’re the guardians of the TRUE_VALUES
“who are you to decide what’s true or not?!”
“well, I’m on the core team”
“ah ok, fair enough”
:laughing:
Fran Worley
@fran-worley
Nov 10 2016 23:02
:hamster:
Piotr Solnica
@solnic
Nov 10 2016 23:02
omg hamster emoji, I had no idea :D
Fran Worley
@fran-worley
Nov 10 2016 23:03
That was a happy mistake! Emojis have no bounds! It's officially the fastest growing language!
Piotr Solnica
@solnic
Nov 10 2016 23:07
:hamster:
that was on purpose :)
Fran Worley
@fran-worley
Nov 10 2016 23:11
Amazing. The new dry-be mascot. No one will understand the reason!
Piotr Solnica
@solnic
Nov 10 2016 23:26
I'm ok with but I think ember got a hamster already :(