FoscTypedSet

Returns a FoscTypedSet.


Description

A typed set.


Attributes Summary

Instance Methods

difference Set-theoretic difference of receiver and expr.
sect Set-theoretic intersection of receiver and expr.
isDisjoint Is true when typed receiver shares no elements with expr. Otherwise false.
isEmpty Is true when set is empty.
isSubsetOf Is true when receiver is a subset of expr. Otherwise false.
isSupersetOf Is true when receiver is a superset of expr. Otherwise false.
notEmpty Is true when set is not empty.
symmetricDifference Symmetric difference of receiver and expr.
union Union of receiver and expr.


Usage

  1. Example

    x = FoscTypedSet([1, 1, 2, 3, 4], Number);
    x.inspect;
    FoscTypedSet([
        1,
        2,
        3,
        4
    ])


Instance Methods


difference

Set-theoretic difference of receiver and expr.

Returns new typed frozen set.

  1. Example

    a = FoscTypedSet([1, 2, 3], Number);
    b = FoscTypedSet([2, 3, 4], Number);
    x = a.difference(b); // x = (a - b);
    x.inspect;
    FoscTypedSet([
        1
    ])
    a = FoscPitchClassSet([1, 2, 3]);
    b = FoscPitchClassSet([2, 3, 4]);
    a.difference(b).items.collect { |each| each.pitchClassNumber };
    [ 1.0 ]


sect

Set-theoretic intersection of receiver and expr.

Returns new typed frozen set.

  1. Example

    a = FoscTypedSet([1, 2, 3], Number);
    b = FoscTypedSet([2, 3, 4], Number);
    x = sect(a, b); // x = (a & b);
    x.inspect;
    FoscTypedSet([
        2,
        3
    ])
    a = FoscPitchClassSet([1, 2, 3]);
    b = FoscPitchClassSet([2, 3, 4]);
    a.sect(b).items.collect { |each| each.pitchClassNumber };
    [ 2.0, 3.0 ]


isDisjoint

Is true when typed receiver shares no elements with expr. Otherwise false.

Returns boolean.

  1. Example

    a = FoscTypedSet([1, 2, 3], Number);
    b = FoscTypedSet([4], Number);
    c = FoscTypedSet([3, 4], Number);
    isDisjoint(a, b);
    true
    isDisjoint(a, c);
    false


isEmpty

Is true when set is empty.

Returns boolean.

  1. Example

    a = FoscTypedSet([1, 2, 3], Number);
    a.isEmpty;
    false
    a = FoscTypedSet([], Number);
    a.isEmpty;
    true


isSubsetOf

Is true when receiver is a subset of expr. Otherwise false.

Returns boolean.

  1. Example

    a = FoscTypedSet([1, 2, 3], Number);
    b = FoscTypedSet([4], Number);
    c = FoscTypedSet([1, 2, 3, 4], Number);
    b.isSubsetOf(a);
    false
    a.isSubsetOf(c);
    true
    a = FoscPitchClassSet([1, 2, 3]);
    b = FoscPitchClassSet([2, 3]);
    a.isSubsetOf(b);
    false
    b.isSubsetOf(a);
    true


isSupersetOf

Is true when receiver is a superset of expr. Otherwise false.

Returns boolean.

  1. Example

    a = FoscTypedSet([1, 2, 3], Number);
    b = FoscTypedSet([4], Number);
    c = FoscTypedSet([1, 2, 3, 4], Number);
    b.isSupersetOf(a);
    false
    c.isSupersetOf(a);
    true
    a = FoscPitchClassSet([1, 2, 3]);
    b = FoscPitchClassSet([2, 3]);
    a.isSupersetOf(b);
    true
    b.isSupersetOf(a);
    false


notEmpty

Is true when set is not empty.

Returns boolean.

  1. Example

    a = FoscTypedSet([1, 2, 3], Number);
    a.notEmpty;
    true
    a = FoscTypedSet([], Number);
    a.notEmpty;
    false


symmetricDifference

Symmetric difference of receiver and expr.

Returns new typed frozen set.

  1. Example

    a = FoscTypedSet([1, 2, 3], Number);
    b = FoscTypedSet([2, 3, 4], Number);
    x = symmetricDifference(a, b); // a -- b;
    x.inspect;
    FoscTypedSet([
        1,
        4
    ])
    a = FoscPitchClassSet([1, 2, 3]);
    b = FoscPitchClassSet([2, 3, 4]);
    a.symmetricDifference(b).items.collect { |each| each.pitchClassNumber };
    [ 1.0, 4.0 ]


union

Union of receiver and expr.

Returns new typed frozen set.

  1. Example

    a = FoscTypedSet([1, 2, 3], Number);
    b = FoscTypedSet([2, 3, 4], Number);
    x = union(a, b); // x = (a | b);
    x.inspect;
    FoscTypedSet([
        1,
        2,
        3,
        4
    ])
    a = FoscPitchClassSet([1, 2, 3]);
    b = FoscPitchClassSet([2, 3, 4]);
    a.union(b).items.collect { |each| each.pitchClassNumber };
    [ 1.0, 2.0, 3.0, 4.0 ]