{"version":3,"file":"index.cjs","sources":["../src/_drop.js","../src/_tail.js","../src/_take.js","../src/_trunc.js","../src/dropwhile.js","../src/take.js","../src/head.js","../src/slice.js","../src/takewhile.js","../src/drop.js","../src/tail.js","../src/trunc.js"],"sourcesContent":["import assert from 'assert';\nimport {iter} from '@iterable-iterator/iter';\nimport {consume} from '@iterable-iterator/consume';\n\n/**\n * Drops the first <code>n</code> values of the input iterable.\n *\n * @example\n * // returns [ 3 , 4 ]\n * list( _drop( range( 5 ) , 3 ) ) ;\n *\n * @param {Iterable} iterable - The input iterable.\n * @param {Number} n - The nonnegative number of values to drop.\n * @returns {IterableIterator} - The remaining values of the input iterable.\n */\nexport default function* _drop(iterable, n) {\n\tassert(Number.isInteger(n) && n >= 0);\n\tconst iterator = iter(iterable);\n\tconsume(iterator, n);\n\tyield* iterator;\n}\n","import assert from 'assert';\nimport {deque} from '@data-structure/deque';\n\n/**\n * Returns the last <code>n</code> values of the input iterable in an array.\n *\n * @example\n * // returns [ 3 , 4 ]\n * list( _tail( range( 5 ) , 2 ) ) ;\n *\n * @param {Iterable} iterable - The input iterable.\n * @param {Number} n - The nonnegative number of values to include in the output.\n * @returns {IterableIterator} - The last <code>n</code> values of the input iterable.\n */\nexport default function* _tail(iterable, n) {\n\tassert(Number.isInteger(n) && n >= 0);\n\tyield* deque(iterable, n);\n}\n","import assert from 'assert';\nimport {iter} from '@iterable-iterator/iter';\n\n/**\n * Yields the first <code>n</code> elements of the input iterable.\n *\n * @example\n * // returns [ 0 , 1 , 2 ]\n * list( _take( range( 5 ) , 3 ) ) ;\n *\n * @param {Iterable} iterable - The input iterable.\n * @param {Number} n - The nonnegative number of elements to include in the output.\n * @returns {IterableIterator} - The first <code>n</code> elements of the input iterable.\n */\nexport default function* _take(iterable, n) {\n\tassert(Number.isInteger(n) && n >= 0);\n\n\tconst iterator = iter(iterable);\n\n\twhile (n-- > 0) {\n\t\tconst current = iterator.next();\n\n\t\tif (current.done) {\n\t\t\treturn;\n\t\t}\n\n\t\tyield current.value;\n\t}\n}\n","import assert from 'assert';\nimport {deque} from '@data-structure/deque';\nimport {iter} from '@iterable-iterator/iter';\n\n/**\n * Yields all elements of the iterable except the last <code>n</code> ones.\n *\n * @example\n * // returns [ 0 , 1 , 2 ]\n * list( _trunc( range( 5 ) , 2 ) ) ;\n *\n * @param {Iterable} iterable - The input iterable.\n * @param {Number} n - The nonnegative number of elements to exclude from the output.\n * @returns {IterableIterator}\n */\nexport default function* _trunc(iterable, n) {\n\tassert(Number.isInteger(n) && n >= 0);\n\n\tif (n === 0) {\n\t\tyield* iterable;\n\t\treturn;\n\t}\n\n\tconst iterator = iter(iterable);\n\n\tconst buffer = deque(null, n);\n\n\twhile (n-- > 0) {\n\t\tconst event = iterator.next();\n\t\tif (event.done) {\n\t\t\treturn;\n\t\t}\n\n\t\tbuffer.append(event.value);\n\t}\n\n\tfor (const value of iterator) {\n\t\tyield buffer.popleft();\n\t\tbuffer.append(value);\n\t}\n}\n","import {iter} from '@iterable-iterator/iter';\n\n/**\n * Drop elements of the input iterable while the current element satisfies the\n * input predicate.\n *\n * @param {Function} predicate - The input predicate.\n * @param {Iterable} iterable - The input iterable.\n * @returns {Iterator}\n */\nexport default function* dropwhile(predicate, iterable) {\n\tconst iterator = iter(iterable);\n\n\tfor (const item of iterator) {\n\t\tif (predicate(item)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Equivalent to return chain( [ [ item ] , iterator ] ) ;\n\n\t\tyield item;\n\n\t\tyield* iterator;\n\n\t\treturn;\n\t}\n}\n","import _trunc from './_trunc.js';\nimport _take from './_take.js';\n\n/**\n * Yields the first <code>n</code> elements of the input iterable. If\n * <code>n</code> is negative, behaves like <code>{@link trunc}( iterable,\n * -n)</code>.\n *\n * @example\n * // returns [ 0 , 1 , 2 ]\n * list( take( range( 5 ) , 3 ) ) ;\n *\n * @param {Iterable} iterable - The input iterable.\n * @param {Number} n - The number of elements to include in the output.\n * @returns {IterableIterator} - The first <code>n</code> elements of the input iterable.\n */\nexport default function take(iterable, n) {\n\treturn n < 0 ? _trunc(iterable, -n) : _take(iterable, n);\n}\n","import take from './take.js';\n\n/**\n * Same as {@link take}.\n * @function head\n */\nconst head = take;\nexport default head;\n","import {iter} from '@iterable-iterator/iter';\n\n/**\n * Same as\n * <code>map( [ i , x ] => x , filter( [ i , x ] => (new Set( range( start ,\n * stop , step ) ) ).has( i ) , enumerate( iterable ) ) );</code>.\n *\n * @param {Iterable} iterable - The input iterable.\n * @param {Number} start - Where to start the slice.\n * @param {Number} stop - Where to stop the slice.\n * @param {Number} step - The step of the slice.\n * @returns {IterableIterator}\n */\nexport default function* slice(iterable, start, stop, step) {\n\tconst iterator = iter(iterable);\n\n\twhile (start > 0) {\n\t\tif (iterator.next().done) {\n\t\t\treturn;\n\t\t}\n\n\t\t--start;\n\t\t--stop;\n\t}\n\n\twhile (stop > 0) {\n\t\tconst current = iterator.next();\n\n\t\tif (current.done) {\n\t\t\treturn;\n\t\t}\n\n\t\tyield current.value;\n\n\t\t--stop;\n\n\t\tlet n = step;\n\n\t\twhile (n > 1) {\n\t\t\tif (iterator.next().done) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t--n;\n\t\t}\n\t}\n}\n","/**\n * Output elements of the input iterable while the current element satisfies the\n * input predicate.\n *\n * @param {Function} predicate - The input predicate.\n * @param {Iterable} iterable - The input iterable.\n * @returns {Iterator}\n */\nexport default function* takewhile(predicate, iterable) {\n\tfor (const item of iterable) {\n\t\tif (!predicate(item)) {\n\t\t\treturn;\n\t\t}\n\n\t\tyield item;\n\t}\n}\n","import _drop from './_drop.js';\nimport _tail from './_tail.js';\n\n/**\n * Drops the first <code>n</code> values of the input iterable.\n * If <code>n</code> is negative, behaves like <code>{@link tail}( iterable,\n * -n)</code>.\n *\n * @example\n * // returns [ 3 , 4 ]\n * list( drop( range( 5 ) , 3 ) ) ;\n *\n * @param {Iterable} iterable - The input iterable.\n * @param {Number} n - The number of values to drop.\n * @returns {IterableIterator} - The remaining values of the input iterable.\n */\nexport default function drop(iterable, n) {\n\treturn n < 0 ? _tail(iterable, -n) : _drop(iterable, n);\n}\n","import _drop from './_drop.js';\nimport _tail from './_tail.js';\n\n/**\n * Returns the last <code>n</code> values of the input iterable in an array.\n * If <code>n</code> is negative, behaves like <code>{@link drop}( iterable,\n * -n)</code>.\n *\n * @example\n * // returns [ 3 , 4 ]\n * list( tail( range( 5 ) , 2 ) ) ;\n *\n * @param {Iterable} iterable - The input iterable.\n * @param {Number} n - The number of values to include in the output.\n * @returns {IterableIterator} - The last <code>n</code> values of the input iterable.\n */\nexport default function tail(iterable, n) {\n\treturn n < 0 ? _drop(iterable, -n) : _tail(iterable, n);\n}\n","import _take from './_take.js';\nimport _trunc from './_trunc.js';\n\n/**\n * Yields all elements of the iterable except the last <code>n</code> ones. If\n * <code>n</code> is negative, behaves like <code>{@link take}( iterable, -n\n * )</code>.\n *\n * @example\n * // returns [ 0 , 1 , 2 ]\n * list( trunc( range( 5 ) , 2 ) ) ;\n *\n * @param {Iterable} iterable - The input iterable.\n * @param {Number} n - The number of elements to exclude from the output.\n * @returns {IterableIterator}\n */\nexport default function trunc(iterable, n) {\n\treturn n < 0 ? _take(iterable, -n) : _trunc(iterable, n);\n}\n"],"names":["_drop","iterable","n","iterator","iter","consume","_tail","deque","_take","current","next","done","value","_trunc","buffer","event","append","_context","popleft","dropwhile","predicate","item","take","slice","start","stop","step","takewhile"],"mappings":"2JAeyBA,YAAAA,EAAMC,EAAUC,wFAIxC,OAFMC,EAAWC,OAAKH,GACtBI,UAAQF,EAAUD,mBACXC,UAJO,iFCDUG,YAAAA,EAAML,EAAUC,kFAExC,uBAAOK,QAAMN,EAAUC,WAFT,iFCAUM,YAAAA,EAAMP,EAAUC,0FAGlCC,EAAWC,OAAKH,eAEfC,KAAM,wBACNO,EAAUN,EAASO,QAEbC,sDAIZ,gBAAMF,EAAQG,MAZD,65BCCUC,YAAAA,EAAOZ,EAAUC,qGAG/B,IAANA,kBACH,uBAAOD,U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