Abstract supertype of objects that contain other values,
called *elements*, where it is possible to efficiently
determine if a given value is an element. A `Category`

may not be finite, and its elements may not even be
countable. Thus, unlike streams, the
elements of a generic `Category`

are not iterable.

`Category`

models a mathematical set, but is distinct
from the `Set`

collection type which represents finite
sets.

The `in`

operator may be used to determine if a value
belongs to a `Category`

:

if (69 in 0..100) { ... } assert (key->item in { for (n in 0..100) n.string->n**2 });

An object may be a `Category`

of two different disjoint
element types. For example, `String`

is a `Category`

of its `Character`

s and of its substrings.

if ("hello" in "hello world") { ... } assert ('.' in string);

Every meaningful `Category`

is formed from elements with
some equivalence relation. Ordinarily, that equivalence
relation is value equality. Thus,
ordinarily, `x==y`

implies that `x in cat == y in cat`

.
But this contract is not required since it is possible to
form a meaningful `Category`

using a different
equivalence relation. For example, an `IdentitySet`

is a
meaningful `Category`

, where the equivalence relation is
identity equality.

Since `Null`

is not considered to have any meaningful
equivalence relation, a `Category`

may not contain the
null value.

Note that even though `Category<Element>`

is declared
contravariant in its Element, most types
that inherit `Category`

are covariant in their element
type, and therefore satisfy `Category<Object>`

, resulting
in some loss of typesafety. For such types, `contains()`

should return `false`

for any value that is not an
instance of the element type. For example, `String`

is a
`Category<Object>`

, not a `Category<Character|String>`

,
and `x in string`

evaluates to `false`

for every `x`

that
is not a `String`

or `Character`

.

By: Gavin

*no type hierarchy*

*no supertypes hierarchy*

Methods | |

`contains` | Source Code`shared formal Boolean contains(Element element)` Returns For any instance element in c For most - if
`x==y` , then`x in category == y in category`
However, it is possible to form a useful See also `containsEvery()` , `containsAny()` |

`containsAny` | Source Code`shared default Boolean containsAny({Element*} elements)` Returns See also `contains()` , `containsEvery()` |

`containsEvery` | Source Code`shared default Boolean containsEvery({Element*} elements)` Returns See also `contains()` , `containsAny()` |

Inherited Methods |

Methods inherited from: `Object` |