Skip to content

Support of Set #356

Description

@dnesteryuk

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)

Activity

  1. flash-gordon commented on Oct 6, 2019

    @flash-gordon
    Member

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

  2. Alexxfrolov commented on Dec 8, 2020

    @Alexxfrolov

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

  3. solnic commented on Dec 9, 2020

    @solnic
    Member

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

  4. heyimalex commented on May 28, 2025

    @heyimalex

    That lets you enforce the type is Set, but doesn't allow type composition like Array.of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions