dry-rb / dry-types

Flexible type system for Ruby with coercions and constraints
https://dry-rb.org/gems/dry-types
MIT License
860 stars 134 forks source link

Support of Set #356

Open dnesteryuk opened 5 years ago

dnesteryuk commented 5 years ago

Is there a plan to support Set?

I am trying to use dry-types in place of Virtus in Grape. Currently, Set is supported because Virtus supports it.

I am think of the same interface as Array has:

PostStatuses = Types::Set.of(Types::Coercible::String)
flash-gordon commented 5 years ago

We'll need to generalize some internals for that. Maybe we could do it in 1.3

Alexxfrolov commented 3 years ago

Are there any ideas about this feat ? I guess it can be very useful

solnic commented 3 years ago

@Alexxfrolov this is as simple as:

[4] pry(main)> Types::Set = Types.Constructor(Set, Set.method(:new))
=> #<Dry::Types[Constructor<Nominal<Set> fn=Set.new>]>
[5] pry(main)> Types::Set[["a", "a", "b", "c"]]
=> #<Set: {"a", "b", "c"}>

I'm not 100% sure we should have it in the lib though but we'll think about it.