Returns a extSequenceableCollection.
Extensions to SequenceableCollection
| *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 |
| 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) |
Returns a geometric series.
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 ]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 ]Create a S-shaped half-cosine curve.
Example
a = Array.halfCos(size: 100);
a.plot;Create a S-shaped curve using the hyperbolic tangent function.
See Sigmoid function.
Example
a = Array.sigmoid(size: 100, curve: 1);
a.plot;Example
a = Array.sigmoid(size: 100, curve: 2);
a.plot;!!!TODO: rename, or work into sigmoid definition.
Create an inverse S-shaped curve using the hyperbolic sine function.
Example
a = Array.sigmoid2(size: 100, curve: 1);
a.plot;Example
a = Array.sigmoid2(size: 100, curve: 4);
a.plot;Create a S-shaped curve using the smooth step function.
Example
a = Array.smoothStep(size: 100);
a.plot;• TODO: rename smoothStep2 for consistency
Create a S-shaped curve using the smoother step function.
Example
a = Array.smootherStep(size: 100);
a.plot;Example
x = [[1, 2], 3, [4, 5, 6]];
x.atN(0, 1);
x.atN(2, 0);
x.atN(2, 2);
x.atN(2, 3);Locate the insertion point for val in array to maintain sorted order.
Example
a = [1, 2, 3, 4, 7, 8, 9, 10];
a.bisect(5);4
a = [10, 9, 8, 1];
a.bisect(5);1Example
x = #[4,3,4,2];
x.incise(0)[ 4, 3, 4, 2 ]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 ]Identical to getitem in python.
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 sliceExample
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 ] ]Partitions receiver by sizes.
Returns a nested collection.
Example
(0..16).partitionBySizes([3]);[ [ 0, 1, 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 ] ]Example
(0..16).partitionBySizes([3], isCyclic: true);[ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ], [ 9, 10, 11 ], [ 12, 13, 14 ] ]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 ] ]Partitions receiver into nearest integer-sized parts by ratio.
Returns a nested collection.
Example
(0..15).partitionByRatio(#[1, 1]);[ [ 0, 1, 2, 3, 4, 5, 6, 7 ], [ 8, 9, 10, 11, 12, 13, 14, 15 ] ]Example
(0..15).partitionByRatio(#[1, 2, 3]);[ [ 0, 1, 2 ], [ 3, 4, 5, 6, 7 ], [ 8, 9, 10, 11, 12, 13, 14, 15 ] ]Example
[28, 24].reduceFraction;[ 7, 6 ]Example
[28, 25].reduceFraction;[ 28, 25 ]Repeats collection to absolute sum.
Returns new collection.
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 ]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 ] ]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 ] ]Sort an n-dimensional collection in ascending or descending order.
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 ] ]Example
a = { "abracadabra".scramble } ! 10;
a.sortN.printAll;[ "aaacrbadrab", "aabarcdaarb", "aabcaradbra", "abbraaaacrd", "ardaaarcabb", "bdracaaarba", "bracadaarba", "brcaraaadab", "rbrdaacaaab", "rdaaabbcara" ]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 ] ]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 ] ]Splits collection by sums.
Returns new collection.
Example
l = #[10,-10,10,-10];
l.split([3, 15, 2], overhang: true).printAll;[ [ 3 ], [ 7, -8 ], [ -2 ], [ 10, -10 ] ]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 ] ]Example
l = #[10,-10,10,-10];
l.split(#[3,15,3], isCyclic: false, overhang: true).printAll;[ [ 3 ], [ 7, -8 ], [ -2, 1 ], [ 9, -10 ] ]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" ] ]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 ]– mirror selection and iteration methods in FoscObject
!!!TODO: make a mixin interface for use by FoscComponent, FoscSelection and SequenceableCollection
– mirror selection and iteration methods in FoscObject
!!!TODO: make a mixin interface for use by FoscComponent, FoscSelection and SequenceableCollection
– mirror selection and iteration methods in FoscObject
!!!TODO: make a mixin interface for use by FoscComponent, FoscSelection and SequenceableCollection
– mirror selection and iteration methods in FoscObject
!!!TODO: make a mixin interface for use by FoscComponent, FoscSelection and SequenceableCollection
– mirror selection and iteration methods in FoscObject
!!!TODO: make a mixin interface for use by FoscComponent, FoscSelection and SequenceableCollection
(abjad: truncate)
Truncates collection to absolute sum of values.
Returns new collection.
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 ] ](abjad: truncate)
Truncates collection to sum of values.
Returns new collection.
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 ] ]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 ] ]