Loading TOC...

Sequence.from

Sequence.from(
   $srcValue as Array | Object,
   [$options as Function | Object],
   [$thisValue as Object]
) as Sequence

Summary

Create a Sequence object from an array-like or iterable object.

Parameters
$srcValue An array, array-like object, or iterable object from which to create a Sequence.
$options This parameter can be a map function that will be applied to the values in srcValue in order to generate the values in the new Sequence. The function receives the current value and index in srcValue and returns a value to be included in the new Sequence. The parameter can also be an object which can specify the mapFn and sequenceLimit as key-value pairs. sequenceLimit sets the limit for the sequence length and is default set to 4096.
mapFn
A map function that will be applied to the values in srcValue
sequenceLimit
Limit for length of sequence. It can be passed as a String
$thisValue A value to use as this when executing mapFn. You are not required to supply thisvalue when you supply a mapFn.

Example

// Create a Sequence from an array.
Sequence.from([1,2]);

// Returns a Sequence containing of 2 items with values 1 and 2.

Example

// Create a Sequence from an array-like object and a map function.
Sequence.from({length:5},(v,k)=>k);

// => A Sequence containing 0,1,2,3,4.

Example

// Create a Sequence from an array-like object and a map function with sequenceLimit.
Sequence.from({length:5},{"mapFn":(v,k)=>k, "sequenceLimit":"10000"});

// => A Sequence containing 0,1,2,3,4.

Example

// Create a Sequence from a generator
function* gen() {
  for (let i = 0; i < 5; i++) yield i;
}
Sequence.from(gen());

// => A Sequence containing 0,1,2,3,4.

Example

// Create a Sequence from a generator with sequenceLimit
function* gen() {
  for (let i = 0; i < 10; i++) yield i;
}
Sequence.from(gen(),{"sequenceLimit":"10000"});

// => A Sequence containing 0,1,2,3,4.

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.