These are chat archives for dry-rb/chat

6th
Oct 2017
Peter Leitzen
@splattael
Oct 06 2017 10:40
Is Types.Instance(Foo) basically saying that I want this value to be strictly instance of Foo? If so, would it make sense to alias it toTypes.Strict(Foo)?
Gustavo Caso
@GustavoCaso
Oct 06 2017 10:42
Build a type which values are instances of a given class
Peter Leitzen
@splattael
Oct 06 2017 11:21
@GustavoCaso Ok, sure. My question was if Types.Instance could also be named Types.Strict?
Gustavo Caso
@GustavoCaso
Oct 06 2017 11:22
Sorry I had to leave my computer
Maybe the difference strict raise an exception
I have to check
Nikita Shilnikov
@flash-gordon
Oct 06 2017 11:36
@splattael good point, we need an alias
Peter Leitzen
@splattael
Oct 06 2017 11:37
@flash-gordon "need" is a strong word ;) I just wanted to sort by brain a bit %)
Is there a way to access the registered types after included into a custom module?
Example:
module MyTypes
  include Dry::Types.module
end

MyTypes['strict.int'] # ?
(as you may have noticed, we will finally use all dry-* awesomeness in one of our project)
\o/
Nikita Shilnikov
@flash-gordon
Oct 06 2017 11:42
Awesome :)
Dry-types does export a container so no, [] are not there
Markus Unterwaditzer
@untitaker
Oct 06 2017 11:44
How does dry-initializer work with optional options/params + types? Right now I need to do option :foo, MyType.optional, optional: true, which seems to be past the point.
if I remove .optional, the type can't "swallow" the nil it gets sent, if I leave out optional: true, I need to pass nil everytime.
also the naming seems completely broken to me... options are usually called options because they're optional...
Peter Leitzen
@splattael
Oct 06 2017 11:52
@flash-gordon Ok, got it. So the only we is to use MyTypes::Strict::String, right?
Gustavo Caso
@GustavoCaso
Oct 06 2017 11:55
@splattael Here some output maybe is helpful
type = Types.Instance(String)
type[nil] #=>  nil violates constraints (type?(String, nil) failed) (Dry::Types::ConstraintError)

Types::Strict::String[nil] #=> *** Dry::Types::ConstraintError Exception: nil violates constraints (type?(String, nil) failed)
As far as looks like they are the same type
Hope that helps
Peter Leitzen
@splattael
Oct 06 2017 12:14
@GustavoCaso Awesome, thank you!
Nikita Shilnikov
@flash-gordon
Oct 06 2017 17:00
@splattael yes