collection
Type-checked set
Example
type = String
collection = Collection::Set.new(type)
collection.add('something')
collection.entry? { |v| v == 'something' }
# => true
collection.entry?('something')
# => true
collection.add(:not_a_string)
# => ArgumentError (:not_a_string must be a String)
Generic-Style
type = String
cls = Collection::Set[type]
cls
# => "Collection::Set::String"
collection = cls.new
collection.add('something')
collection.entry? { |v| v == 'something' }
# => true
collection.entry?('something')
# => true
collection.add(:not_a_string)
# => ArgumentError (:not_a_string must be a String)
Factory Method
things = ['Thing 1', 'Thing 2']
collection = Collection::Set(things)
collection.entry? { |v| v == 'Thing 1' }
# => true
collection.entry?('Thing 1')
# => true
collection.add(:not_a_string)
# => ArgumentError (:not_a_string must be a String)
Constructor
things = ['Thing 1', 'Thing 2']
collection = Collection::Set[String].build(things)
collection.entry? { |v| v == 'Thing 1' }
# => true
collection.entry?('Thing 1')
# => true
collection.add(:not_a_string)
# => ArgumentError (:not_a_string must be a String)
License
The collection
library is released under the MIT License.