FoscTypedList

Returns a FoscTypedList.


Description

A typed list.


Attributes Summary

Instance Methods: List Modification

concat Concatenates typed list and expr.
add Appends item to list.
append – REMOVE
addAll
extend – REMOVE
insert Inserts item at index.
pop Puts item at index.
prepend Prepends item to list.
put Puts item at index.
remove Remove item.
removeAt Remove item at index.
sort

Instance Methods: Properties

at Gets item at index.
atAll Gets items at indices.
includes Answer true if item exists in collection.
indexOf (abjad: index)
occurrencesOf (abjad: count)

Instance Methods: Transformation

collect
reject
select

Instance Methods: Display

inspect Inspect items in collection.


Usage

  1. Example

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


Instance Methods: List Modification


concat

Concatenates typed list and expr.

Returns new typed list.

  1. FIXME ERROR: Message asList not understood.

    a = FoscTypedList([1, 2, 3, 4], Number);
    b = FoscTypedList([5, 6], Number);
    (a ++ b).inspect;


add

Appends item to list.

  1. Example

    a = FoscTypedList([1, 2, 3, 4], Number);
    a.add(5);
    a.inspect;
    FoscTypedList([
        1,
        2,
        3,
        4,
        5
    ])


append

– REMOVE

  1. Example

    a = FoscTypedList([1, 2, 3, 4], Number);
    a.extend([5, 6, 7]);
    a.inspect;
    FoscTypedList([
        1,
        2,
        3,
        4,
        5,
        6,
        7
    ])


addAll


extend

– REMOVE


insert

Inserts item at index.


pop

Puts item at index.

  1. Example

    a = FoscTypedList([1, 2, 3, 4], Number);
    a.pop;
    a.inspect;
    FoscTypedList([
        1,
        2,
        3
    ])


prepend

Prepends item to list.

  1. Example

    a = FoscTypedList([1, 2, 3, 4], Number);
    a.prepend(5);
    a.inspect;
    FoscTypedList([
        5,
        1,
        2,
        3,
        4
    ])


put

Puts item at index.

  1. Example

    a = FoscTypedList([1, 2, 3, 4], Number);
    a[1] = 5;
    a.inspect;
    FoscTypedList([
        1,
        5,
        3,
        4
    ])


remove

Remove item.

  1. Example

    a = FoscTypedList([1, 2, 3, 4], Number);
    a.remove(3);
    a.inspect;
    FoscTypedList([
        1,
        2,
        4
    ])


removeAt

Remove item at index.

  1. Example

    a = FoscTypedList([1, 2, 3, 4], Number);
    a.removeAt(1);
    a.inspect;
    FoscTypedList([
        1,
        3,
        4
    ])


sort

  1. Example

    a = FoscTypedList([5, 2, 3, 4], Number);
    a.sort;
    a.inspect;
    FoscTypedList([
        2,
        3,
        4,
        5
    ])
    a = FoscTypedList([5, 2, 3, 4], Number);
    a.sort { |a, b| a > b };
    a.inspect;
    FoscTypedList([
        5,
        4,
        3,
        2
    ])


Instance Methods: Properties


at

Gets item at index.

Returns item.

  1. Example

    a = FoscTypedList([1, 2, 3, 4], Number);
    a[2];
    3


atAll

Gets items at indices.

Returns items.

  1. Example

    a = FoscTypedList([1, 2, 3, 4], Number);
    a[(2..3)];
    [ 3, 4 ]


includes

Answer true if item exists in collection.

Returns boolean.

  1. Example

    a = FoscTypedList([1, 2, 3, 4], Number);
    a.includes(3);
    a.includes(5);
    false


indexOf

(abjad: index)

Return the first index matching item.

Returns nonegative integer.

  1. Example

    a = FoscTypedList([1, 2, 3, 4], Number);
    a.indexOf(3);
    2


occurrencesOf

(abjad: count)

Return the number of occurrences of item in collection.

Returns nonegative integer.

  1. Example

    a = FoscTypedList([1, 2, 3, 4], Number);
    a.occurrencesOf(3);
    1


Instance Methods: Transformation


collect

  1. Example

    x = FoscTypedList([1, 2, 3, 4], Number);
    x = x.collect { |each| each * 2 };
    x.inspect;
    FoscTypedList([
        2,
        4,
        6,
        8
    ])


reject

  1. Example

    x = FoscTypedSequenceableCollection([1, 2, 3, 4], Number);
    x = x.reject { |each| each.even };
    x.inspect;
    FoscTypedSequenceableCollection([
        1,
        3
    ])


select

  1. Example

    x = FoscTypedSequenceableCollection([1, 2, 3, 4], Number);
    x = x.select { |each| each.even };
    x.inspect;
    FoscTypedSequenceableCollection([
        2,
        4
    ])


Instance Methods: Display


inspect

Inspect items in collection.

  1. Example

    a = FoscTypedList([1, 2, 3, 4], Number);
    a.inspect;
    FoscTypedList([
        1,
        2,
        3,
        4
    ])