extSequenceableCollection

Returns a extSequenceableCollection.


Description

Extensions to SequenceableCollection


Attributes Summary

Class Methods: Constructors

*geom2 Returns a geometric series.
*halfCos Create a S-shaped half-cosine curve.
*sigmoid Create a S-shaped curve using the hyperbolic tangent function.
*sigmoid2 !!!TODO: rename, or work into sigmoid definition.
*smoothStep Create a S-shaped curve using the smooth step function.
*smootherStep • TODO: rename smoothStep2 for consistency

Instance Methods

atN
bisect Locate the insertion point for val in array to maintain sorted order.
incise
intervals
iterate
mask
offsets
mutate
getItem Identical to getitem in python.
orderN
partitionBySizes Partitions receiver by sizes.
partitionByRatio Partitions receiver into nearest integer-sized parts by ratio.
reduceFraction
removeDuplicates
repeatToAbsSum Repeats collection to absolute sum.
sortN Sort an n-dimensional collection in ascending or descending order.
split Splits collection by sums.
extendToAbsSum
doLeaves – mirror selection and iteration methods in FoscObject
selectComponents – mirror selection and iteration methods in FoscObject
selectLeaves – mirror selection and iteration methods in FoscObject
selectLogicalTies – mirror selection and iteration methods in FoscObject
selectRuns – mirror selection and iteration methods in FoscObject
truncateToAbsSum (abjad: truncate)
truncateToSum (abjad: truncate)


Class Methods: Constructors


*geom2

Returns a geometric series.

  1. A 12ET chromatic scale.

    a = Array.geom2(13, 1, 2).round(0.001);
    [ 1.0, 1.059, 1.122, 1.189, 1.26, 1.335, 1.414, 1.498, 1.587, 1.682, 1.782, 1.888, 2.0 ]
    Array.interpolation(13, 0, 1).linexp(0, 1, 1, 2).round(0.001);
    [ 1.0, 1.059, 1.122, 1.189, 1.26, 1.335, 1.414, 1.498, 1.587, 1.682, 1.782, 1.888, 2.0 ]
  2. A 12ET chromatic scale in reverse.

    a = Array.geom2(13, 2, 1).round(0.001);
    [ 2.0, 1.941, 1.878, 1.811, 1.74, 1.665, 1.586, 1.502, 1.413, 1.318, 1.218, 1.112, 1.0 ]


*halfCos

Create a S-shaped half-cosine curve.

  1. Example

    a = Array.halfCos(size: 100);
    a.plot;


*sigmoid

Create a S-shaped curve using the hyperbolic tangent function.

See Sigmoid function.

  1. Example

    a = Array.sigmoid(size: 100, curve: 1);
    a.plot;
  2. Example

    a = Array.sigmoid(size: 100, curve: 2);
    a.plot;


*sigmoid2

!!!TODO: rename, or work into sigmoid definition.

Create an inverse S-shaped curve using the hyperbolic sine function.

  1. Example

    a = Array.sigmoid2(size: 100, curve: 1);
    a.plot;
  2. Example

    a = Array.sigmoid2(size: 100, curve: 4);
    a.plot;


*smoothStep

Create a S-shaped curve using the smooth step function.

  1. Example

    a = Array.smoothStep(size: 100);
    a.plot;


*smootherStep

• TODO: rename smoothStep2 for consistency

Create a S-shaped curve using the smoother step function.

  1. Example

    a = Array.smootherStep(size: 100);
    a.plot;


Instance Methods


atN

  1. Example

    x = [[1, 2], 3, [4, 5, 6]];
    x.atN(0, 1);
    x.atN(2, 0);
    x.atN(2, 2);
    x.atN(2, 3);


bisect

Locate the insertion point for val in array to maintain sorted order.

  1. Example

    a = [1, 2, 3, 4, 7, 8, 9, 10];
    a.bisect(5);
    4
    a = [10, 9, 8, 1];
    a.bisect(5);
    1


incise

  1. Example

    x = #[4,3,4,2];
    x.incise(0)
    [ 4, 3, 4, 2 ]


intervals


iterate


mask

  1. Example

    a = (1..10);
    a.mask([1, -1, 1, 1, -1, -1], isCyclic: false);
    [ 1, -2, 3, 4, -5, -6, 7, 8, 9, 10 ]
    a.mask([1, -1, 1, 1, -1, -1], isCyclic: true);
    [ 1, -2, 3, 4, -5, -6, 7, -8, 9, 10 ]
    a = (1..10);
    a.mask([-1, 1], isCyclic: true);
    [ -1, 2, -3, 4, -5, 6, -7, 8, -9, 10 ]
    a = (1..10);
    a.mask([false, true], isCyclic: true);
    [ -1, 2, -3, 4, -5, 6, -7, 8, -9, 10 ]


offsets


mutate


getItem

Identical to getitem in python.

  1. Example

    (0..5).prGetItem((2..4));
    [ 2, 3, 4 ]
    (0..5).prGetItem(2);
    2
    (0..5).prGetItem((4..9));
    [ 4, 5 ]
    (0..5).prGetItem((9..11));
    [  ]
    (0..5).prGetItem(9);      // nil: out of range when int rather than slice


orderN

  1. Example

    x = [[3, 2], [3, 1], [1, 7], [2, 0]];
    x.orderN;
    [ 2, 3, 1, 0 ]
    x[x.orderN]; // sorted
    [ [ 1, 7 ], [ 2, 0 ], [ 3, 1 ], [ 3, 2 ] ]


partitionBySizes

Partitions receiver by sizes.

Returns a nested collection.

  1. Example

    (0..16).partitionBySizes([3]);
    [ [ 0, 1, 2 ] ]
  2. Example

    (0..16).partitionBySizes([3], overhang: true);
    [ [ 0, 1, 2 ], [ 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] ]
  3. Example

    (0..16).partitionBySizes([3], isCyclic: true);
    [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ], [ 9, 10, 11 ], [ 12, 13, 14 ] ]
  4. Example

    (0..16).partitionBySizes([3], isCyclic: true, overhang: true);
    [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ], [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16 ] ]


partitionByRatio

Partitions receiver into nearest integer-sized parts by ratio.

Returns a nested collection.

  1. Example

    (0..15).partitionByRatio(#[1, 1]);
    [ [ 0, 1, 2, 3, 4, 5, 6, 7 ], [ 8, 9, 10, 11, 12, 13, 14, 15 ] ]
  2. Example

    (0..15).partitionByRatio(#[1, 2, 3]);
    [ [ 0, 1, 2 ], [ 3, 4, 5, 6, 7 ], [ 8, 9, 10, 11, 12, 13, 14, 15 ] ]


reduceFraction

  1. Example

    [28, 24].reduceFraction;
    [ 7, 6 ]
  2. Example

    [28, 25].reduceFraction;
    [ 28, 25 ]


removeDuplicates

  1. • removeDuplicates


repeatToAbsSum

Repeats collection to absolute sum.

Returns new collection.

  1. Example

    [1, 2, 3].repeatToAbsSum(15);
    [ 1, 2, 3, 1, 2, 3, 1, 2 ]
    [1, 2, -3].repeatToAbsSum(15);
    [ 1, 2, -3, 1, 2, -3, 1, 2 ]
    [1, 2, 3].repeatToAbsSum(14.5);
    [ 1, 2, 3, 1, 2, 3, 1, 1.5 ]
  2. Example

    a = [[3, 16], [-2, 16]].collect { |each| FoscNonreducedFraction(each) };
    b = a.repeatToAbsSum(FoscNonreducedFraction(5, 4));
    b.collect { |each| each.pair };
    [ [ 3, 16 ], [ -2, 16 ], [ 3, 16 ], [ -2, 16 ], [ 3, 16 ], [ -2, 16 ], [ 3, 16 ], [ -2, 16 ] ]
  3. Example

    a = [[3, 16], [2, 16]].collect { |each| FoscDuration(each) };
    b = a.repeatToAbsSum(FoscDuration(5, 4));
    b.collect { |each| each.pair };
    [ [ 3, 16 ], [ 1, 8 ], [ 3, 16 ], [ 1, 8 ], [ 3, 16 ], [ 1, 8 ], [ 3, 16 ], [ 1, 8 ] ]


sortN

Sort an n-dimensional collection in ascending or descending order.

  1. Example

    a = { [9.rand, 9.rand, 9.rand] } ! 10;
    a.sortN.printAll;
    [ [ 0, 4, 1 ], [ 1, 1, 8 ], [ 1, 4, 1 ], [ 2, 4, 5 ], [ 2, 5, 7 ], [ 3, 8, 6 ], [ 5, 1, 0 ], [ 6, 3, 1 ], [ 7, 5, 0 ], [ 8, 6, 4 ] ]
  2. Example

    a = { "abracadabra".scramble } ! 10;
    a.sortN.printAll;
    [ "aaacrbadrab", "aabarcdaarb", "aabcaradbra", "abbraaaacrd", "ardaaarcabb", "bdracaaarba", "bracadaarba", "brcaraaadab", "rbrdaacaaab", "rdaaabbcara" ]
  3. Example

    a = { [9.rand, 9.rand, 9.rand] } ! 10;
    a.sortN(reverse: true).printAll;
    [ [ 8, 1, 2 ], [ 7, 7, 1 ], [ 7, 4, 6 ], [ 7, 3, 6 ], [ 4, 6, 8 ], [ 4, 1, 1 ], [ 2, 3, 7 ], [ 2, 2, 0 ], [ 1, 2, 2 ], [ 0, 1, 1 ] ]
  4. Sort from startIndex. If startIndex is 1, then 0th element is ignored in search function.

    a = { [9.rand, 9.rand, 9.rand] } ! 10;
    a.sortN(startIndex: 1).printAll;
    [ [ 6, 0, 2 ], [ 4, 1, 0 ], [ 6, 2, 3 ], [ 5, 3, 4 ], [ 3, 4, 1 ], [ 4, 4, 3 ], [ 5, 5, 2 ], [ 6, 5, 2 ], [ 4, 7, 6 ], [ 2, 8, 0 ] ]


split

Splits collection by sums.

Returns new collection.

  1. Example

    l = #[10,-10,10,-10];
    l.split([3, 15, 2], overhang: true).printAll;
    [ [ 3 ], [ 7, -8 ], [ -2 ], [ 10, -10 ] ]
  2. Example

    l = #[10,-10,10,-10];
    l.split(#[3,15,3], isCyclic: true, overhang: true).printAll;
    [ [ 3 ], [ 7, -8 ], [ -2, 1 ], [ 3 ], [ 6, -9 ], [ -1 ] ]
  3. Example

    l = #[10,-10,10,-10];
    l.split(#[3,15,3], isCyclic: false, overhang: true).printAll;
    [ [ 3 ], [ 7, -8 ], [ -2, 1 ], [ 9, -10 ] ]
  4. Example

    l = #[10,10,10, 10].collect { |each| FoscDuration(each) };
    m = l.split(#[3,15,3], isCyclic: false, overhang: true);
    m.collect { |each| each.collect { |elem| elem.str } };
    [ [ "3/1" ], [ "7/1", "8/1" ], [ "2/1", "1/1" ], [ "9/1", "10/1" ] ]


extendToAbsSum

  1. Example

    [1, 2, 3].extendToAbsSum(10);
    [ 1, 2, 3, 4 ]
    [1, 2, -3].extendToAbsSum(10);
    [ 1, 2, -3, 4 ]
    [1, 2, 3, 99].extendToAbsSum(10);   // truncate if needed
    [ 1, 2, 3, 4 ]


doLeaves

– mirror selection and iteration methods in FoscObject

!!!TODO: make a mixin interface for use by FoscComponent, FoscSelection and SequenceableCollection


selectComponents

– mirror selection and iteration methods in FoscObject

!!!TODO: make a mixin interface for use by FoscComponent, FoscSelection and SequenceableCollection


selectLeaves

– mirror selection and iteration methods in FoscObject

!!!TODO: make a mixin interface for use by FoscComponent, FoscSelection and SequenceableCollection


selectLogicalTies

– mirror selection and iteration methods in FoscObject

!!!TODO: make a mixin interface for use by FoscComponent, FoscSelection and SequenceableCollection


selectRuns

– mirror selection and iteration methods in FoscObject

!!!TODO: make a mixin interface for use by FoscComponent, FoscSelection and SequenceableCollection


truncateToAbsSum

(abjad: truncate)

Truncates collection to absolute sum of values.

Returns new collection.

  1. Example

    l = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10];
    (1..11).collect { |sum| [sum, l.truncateToAbsSum(sum)] }.join("\n");
    [ 1, [ -1 ] ]
    [ 2, [ -1, 1 ] ]
    [ 3, [ -1, 2 ] ]
    [ 4, [ -1, 2, -1 ] ]
    [ 5, [ -1, 2, -2 ] ]
    [ 6, [ -1, 2, -3 ] ]
    [ 7, [ -1, 2, -3, 1 ] ]
    [ 8, [ -1, 2, -3, 2 ] ]
    [ 9, [ -1, 2, -3, 3 ] ]
    [ 10, [ -1, 2, -3, 4 ] ]
    [ 11, [ -1, 2, -3, 4, -1 ] ]


truncateToSum

(abjad: truncate)

Truncates collection to sum of values.

Returns new collection.

  1. Example

    l = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10];
    (1..11).collect { |sum| [sum, l.truncateToSum(sum)] }.join("\n");
    [ 1, [ -1, 2 ] ]
    [ 2, [ -1, 2, -3, 4 ] ]
    [ 3, [ -1, 2, -3, 4, -5, 6 ] ]
    [ 4, [ -1, 2, -3, 4, -5, 6, -7, 8 ] ]
    [ 5, [ -1, 2, -3, 4, -5, 6, -7, 8, -9, 10 ] ]
    [ 6, [ -1, 2, -3, 4, -5, 6, -7, 8, -9, 10 ] ]
    [ 7, [ -1, 2, -3, 4, -5, 6, -7, 8, -9, 10 ] ]
    [ 8, [ -1, 2, -3, 4, -5, 6, -7, 8, -9, 10 ] ]
    [ 9, [ -1, 2, -3, 4, -5, 6, -7, 8, -9, 10 ] ]
    [ 10, [ -1, 2, -3, 4, -5, 6, -7, 8, -9, 10 ] ]
    [ 11, [ -1, 2, -3, 4, -5, 6, -7, 8, -9, 10 ] ]
  2. Example

    a = (1..10).collect { |each| FoscDuration(each, 16) };
    b = a.truncateToSum(FoscDuration(7, 4));
    b.collect { |each| each.pair };
    [ [ 1, 16 ], [ 1, 8 ], [ 3, 16 ], [ 1, 4 ], [ 5, 16 ], [ 3, 8 ], [ 7, 16 ] ]