dry-types icon indicating copy to clipboard operation
dry-types copied to clipboard

Support of Set

Open dnesteryuk opened this issue 6 years ago • 4 comments

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)

dnesteryuk avatar Oct 04 '19 19:10 dnesteryuk

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

flash-gordon avatar Oct 06 '19 13:10 flash-gordon

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

Alexxfrolov avatar Dec 08 '20 10:12 Alexxfrolov

@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.

solnic avatar Dec 09 '20 07:12 solnic