├── .gitignore ├── .npmignore ├── .npmrc ├── LICENSE ├── README.md ├── biblio.json ├── docs ├── .nojekyll ├── assets │ ├── css │ │ ├── main.css │ │ └── main.css.map │ ├── images │ │ ├── icons.png │ │ ├── icons@2x.png │ │ ├── widgets.png │ │ └── widgets@2x.png │ └── js │ │ ├── main.js │ │ └── search.js ├── classes │ ├── _iterable_query_.asynchierarchyquery.html │ ├── _iterable_query_.asyncorderedhierarchyquery.html │ ├── _iterable_query_.asyncorderedquery.html │ ├── _iterable_query_.asyncquery.html │ ├── _iterable_query_.hierarchyquery.html │ ├── _iterable_query_.lazy.html │ ├── _iterable_query_.lookup.html │ ├── _iterable_query_.orderedhierarchyquery.html │ ├── _iterable_query_.orderedquery.html │ └── _iterable_query_.query.html ├── globals.html ├── index.html ├── interfaces │ ├── _iterable_query_.asynchierarchyiterable.html │ ├── _iterable_query_.asyncorderedhierarchyiterable.html │ ├── _iterable_query_.asyncorderediterable.html │ ├── _iterable_query_.grouping.html │ ├── _iterable_query_.hierarchical.html │ ├── _iterable_query_.hierarchygrouping.html │ ├── _iterable_query_.hierarchyiterable.html │ ├── _iterable_query_.hierarchypage.html │ ├── _iterable_query_.hierarchyprovider.html │ ├── _iterable_query_.orderedhierarchyiterable.html │ ├── _iterable_query_.orderediterable.html │ ├── _iterable_query_.page.html │ ├── _iterable_query_.writablearraylike.html │ ├── _iterable_query_fn_.consumeasyncoptions.html │ └── _iterable_query_fn_.consumeoptions.html └── modules │ ├── _internal_assert_.html │ ├── _iterable_query_.html │ ├── _iterable_query_fn_.html │ └── _iterable_query_fn_.op.html ├── es2015 ├── fn │ ├── index.d.ts │ └── index.js ├── index.d.ts └── index.js ├── es5 ├── fn │ ├── index.d.ts │ └── index.js ├── index.d.ts └── index.js ├── fn ├── index.d.ts └── index.js ├── gulpfile.js ├── index.d.ts ├── index.js ├── package.json ├── scripts ├── coverage.js ├── mocha.js ├── projects.js ├── typedoc.js ├── typedoc.sandbox.js └── utils.js └── src ├── lib ├── asyncQuery.ts ├── collections.ts ├── compat │ ├── es2015.ts │ ├── es2017.ts │ └── index.ts ├── fn │ ├── append.ts │ ├── appendAsync.ts │ ├── average.ts │ ├── averageAsync.ts │ ├── axis.ts │ ├── bottomMost.ts │ ├── bottomMostAsync.ts │ ├── break.ts │ ├── breakAsync.ts │ ├── choose.ts │ ├── chooseAsync.ts │ ├── common.ts │ ├── concat.ts │ ├── concatAsync.ts │ ├── conditional.ts │ ├── conditionalAsync.ts │ ├── consume.ts │ ├── consumeAsync.ts │ ├── continuous.ts │ ├── continuousAsync.ts │ ├── copyTo.ts │ ├── copyToAsync.ts │ ├── corresponds.ts │ ├── correspondsAsync.ts │ ├── correspondsBy.ts │ ├── correspondsByAsync.ts │ ├── count.ts │ ├── countAsync.ts │ ├── defaultIfEmpty.ts │ ├── defaultIfEmptyAsync.ts │ ├── distinct.ts │ ├── distinctAsync.ts │ ├── distinctBy.ts │ ├── distinctByAsync.ts │ ├── do.ts │ ├── doAsync.ts │ ├── drain.ts │ ├── drainAsync.ts │ ├── elementAt.ts │ ├── elementAtAsync.ts │ ├── empty.ts │ ├── emptyAsync.ts │ ├── endsWith.ts │ ├── endsWithAsync.ts │ ├── eval.ts │ ├── evalAsync.ts │ ├── every.ts │ ├── everyAsync.ts │ ├── except.ts │ ├── exceptAsync.ts │ ├── exceptBy.ts │ ├── exceptByAsync.ts │ ├── exclude.ts │ ├── excludeAsync.ts │ ├── expand.ts │ ├── expandAsync.ts │ ├── filter.ts │ ├── filterAsync.ts │ ├── filterBy.ts │ ├── filterByAsync.ts │ ├── filterDefined.ts │ ├── filterDefinedAsync.ts │ ├── first.ts │ ├── firstAsync.ts │ ├── flatMap.ts │ ├── flatMapAsync.ts │ ├── forEach.ts │ ├── forEachAsync.ts │ ├── fullJoin.ts │ ├── fullJoinAsync.ts │ ├── generate.ts │ ├── generateAsync.ts │ ├── groupBy.ts │ ├── groupByAsync.ts │ ├── groupJoin.ts │ ├── groupJoinAsync.ts │ ├── hierarchy.ts │ ├── hierarchyAsync.ts │ ├── if.ts │ ├── ifAsync.ts │ ├── includes.ts │ ├── includesAsync.ts │ ├── includesSequence.ts │ ├── includesSequenceAsync.ts │ ├── index.ts │ ├── intersect.ts │ ├── intersectAsync.ts │ ├── intersectBy.ts │ ├── intersectByAsync.ts │ ├── join.ts │ ├── joinAsync.ts │ ├── last.ts │ ├── lastAsync.ts │ ├── map.ts │ ├── mapAsync.ts │ ├── max.ts │ ├── maxAsync.ts │ ├── maxBy.ts │ ├── maxByAsync.ts │ ├── min.ts │ ├── minAsync.ts │ ├── minBy.ts │ ├── minByAsync.ts │ ├── nth.ts │ ├── nthAsync.ts │ ├── nthChild.ts │ ├── nthChildAsync.ts │ ├── objectEntries.ts │ ├── objectEntriesAsync.ts │ ├── objectKeys.ts │ ├── objectKeysAsync.ts │ ├── objectValues.ts │ ├── objectValuesAsync.ts │ ├── once.ts │ ├── onceAsync.ts │ ├── orderBy.ts │ ├── orderByAsync.ts │ ├── pageBy.ts │ ├── pageByAsync.ts │ ├── patch.ts │ ├── patchAsync.ts │ ├── prepend.ts │ ├── prependAsync.ts │ ├── range.ts │ ├── reduce.ts │ ├── reduceAsync.ts │ ├── reduceRight.ts │ ├── reduceRightAsync.ts │ ├── relativeComplement.ts │ ├── relativeComplementAsync.ts │ ├── relativeComplementBy.ts │ ├── relativeComplementByAsync.ts │ ├── repeat.ts │ ├── repeatAsync.ts │ ├── reverse.ts │ ├── reverseAsync.ts │ ├── scan.ts │ ├── scanAsync.ts │ ├── scanRight.ts │ ├── scanRightAsync.ts │ ├── select.ts │ ├── selectAsync.ts │ ├── selectMany.ts │ ├── selectManyAsync.ts │ ├── single.ts │ ├── singleAsync.ts │ ├── skip.ts │ ├── skipAsync.ts │ ├── skipRight.ts │ ├── skipRightAsync.ts │ ├── skipUntil.ts │ ├── skipUntilAsync.ts │ ├── skipWhile.ts │ ├── skipWhileAsync.ts │ ├── some.ts │ ├── someAsync.ts │ ├── span.ts │ ├── spanAsync.ts │ ├── spanMap.ts │ ├── spanMapAsync.ts │ ├── startsWith.ts │ ├── startsWithAsync.ts │ ├── sum.ts │ ├── sumAsync.ts │ ├── symmetricDifference.ts │ ├── symmetricDifferenceAsync.ts │ ├── symmetricDifferenceBy.ts │ ├── symmetricDifferenceByAsync.ts │ ├── take.ts │ ├── takeAsync.ts │ ├── takeRight.ts │ ├── takeRightAsync.ts │ ├── takeUntil.ts │ ├── takeUntilAsync.ts │ ├── takeWhile.ts │ ├── takeWhileAsync.ts │ ├── tap.ts │ ├── tapAsync.ts │ ├── through.ts │ ├── throughAsync.ts │ ├── toArray.ts │ ├── toArrayAsync.ts │ ├── toHierarchy.ts │ ├── toHierarchyAsync.ts │ ├── toLookup.ts │ ├── toLookupAsync.ts │ ├── toMap.ts │ ├── toMapAsync.ts │ ├── toObject.ts │ ├── toObjectAsync.ts │ ├── toSet.ts │ ├── toSetAsync.ts │ ├── topMost.ts │ ├── topMostAsync.ts │ ├── traversal.ts │ ├── traversalAsync.ts │ ├── union.ts │ ├── unionAsync.ts │ ├── unionBy.ts │ ├── unionByAsync.ts │ ├── unzip.ts │ ├── unzipAsync.ts │ ├── where.ts │ ├── whereAsync.ts │ ├── whereBy.ts │ ├── whereByAsync.ts │ ├── whereDefined.ts │ ├── whereDefinedAsync.ts │ ├── xor.ts │ ├── xorAsync.ts │ ├── xorBy.ts │ ├── xorByAsync.ts │ ├── zip.ts │ └── zipAsync.ts ├── index.ts ├── internal │ ├── assert.ts │ ├── conversion.ts │ ├── debug.ts │ ├── decorators.ts │ ├── flow.ts │ ├── guards.ts │ ├── index.ts │ ├── types.ts │ └── utils.ts ├── lazy.ts ├── lookup.ts ├── query.ts ├── tsconfig.es2015.json ├── tsconfig.es5.json ├── tsconfig.json ├── tsconfig.typedoc.json └── types.ts ├── tests ├── asyncQuery.ts ├── chai-iterable.ts ├── collections.ts ├── data │ ├── books.ts │ ├── nodes.ts │ ├── numbers.ts │ └── users.ts ├── index.ts ├── lazy.ts ├── lookup.ts ├── query.ts ├── test-utils.ts └── tsconfig.json └── typedoc ├── plugin ├── augmentations.ts ├── index.ts ├── model │ └── exportBinding.ts ├── nodes │ └── exportDeclaration.ts ├── plugins │ ├── biblio.ts │ ├── excludeEmpty.ts │ ├── exports.ts │ ├── groupCategories.ts │ ├── index.ts │ ├── merge.ts │ ├── naming.ts │ ├── noJekyll.ts │ ├── reflectionEvents.ts │ ├── stripInternal.ts │ └── uncategorized.ts ├── tsconfig.json └── utils.ts └── theme ├── assets ├── css │ ├── main.css │ └── main.css.map ├── images │ ├── icons.png │ ├── icons@2x.png │ ├── widgets.png │ └── widgets@2x.png └── js │ └── main.js ├── helpers └── ifTest.js ├── layouts └── default.hbs ├── partials ├── analytics.hbs ├── breadcrumb.hbs ├── comment.hbs ├── comment.inline.hbs ├── exportBinding.hbs ├── footer.hbs ├── header.hbs ├── hierarchy.hbs ├── index.hbs ├── member.declaration.hbs ├── member.getterSetter.hbs ├── member.hbs ├── member.signature.body.hbs ├── member.signature.title.hbs ├── member.signatures.hbs ├── member.sources.hbs ├── members.group.hbs ├── members.hbs ├── navigation.hbs ├── parameter.hbs ├── toc.hbs ├── toc.root.hbs ├── type.hbs ├── typeAndParent.hbs └── typeParameters.hbs └── templates ├── index.hbs └── reflection.hbs /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | node_modules 3 | dist 4 | coverage -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | node_modules 3 | coverage 4 | src 5 | scripts 6 | dist/tests 7 | dist/typedoc 8 | gulpfile.js 9 | biblio.json -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false -------------------------------------------------------------------------------- /biblio.json: -------------------------------------------------------------------------------- 1 | { 2 | "Iterable": "https://tc39.github.io/ecma262/#sec-symbol.iterator", 3 | "Iterator": "https://tc39.github.io/ecma262/#sec-symbol.iterator", 4 | "AsyncIterable": "https://tc39.github.io/ecma262/#sec-symbol.asyncIterator", 5 | "AsyncIterator": "https://tc39.github.io/ecma262/#sec-symbol.asyncIterator", 6 | "Promise": "https://tc39.github.io/ecma262/#sec-promise-objects", 7 | "Map": "https://tc39.github.io/ecma262/#sec-map-objects", 8 | "Set": "https://tc39.github.io/ecma262/#sec-set-objects" 9 | } -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rbuckton/iterable-query/d3d1aadcc33bb184aff98759ca50cbae3943f81d/docs/.nojekyll -------------------------------------------------------------------------------- /docs/assets/images/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rbuckton/iterable-query/d3d1aadcc33bb184aff98759ca50cbae3943f81d/docs/assets/images/icons.png -------------------------------------------------------------------------------- /docs/assets/images/icons@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rbuckton/iterable-query/d3d1aadcc33bb184aff98759ca50cbae3943f81d/docs/assets/images/icons@2x.png -------------------------------------------------------------------------------- /docs/assets/images/widgets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rbuckton/iterable-query/d3d1aadcc33bb184aff98759ca50cbae3943f81d/docs/assets/images/widgets.png -------------------------------------------------------------------------------- /docs/assets/images/widgets@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rbuckton/iterable-query/d3d1aadcc33bb184aff98759ca50cbae3943f81d/docs/assets/images/widgets@2x.png -------------------------------------------------------------------------------- /es2015/fn/index.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | export * from "../../dist/es2015/fn"; -------------------------------------------------------------------------------- /es2015/fn/index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module.exports = require("../../dist/es2015/fn"); -------------------------------------------------------------------------------- /es2015/index.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | export * from "../dist/es2015"; -------------------------------------------------------------------------------- /es2015/index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module.exports = require("../dist/es2015"); -------------------------------------------------------------------------------- /es5/fn/index.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | export * from "../../dist/es5/fn"; -------------------------------------------------------------------------------- /es5/fn/index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module.exports = require("../../dist/es5/fn"); -------------------------------------------------------------------------------- /es5/index.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | export * from "../dist/es5"; -------------------------------------------------------------------------------- /es5/index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module.exports = require("../dist/es5"); -------------------------------------------------------------------------------- /fn/index.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | export * from "../dist/lib/fn"; -------------------------------------------------------------------------------- /fn/index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module.exports = require("../dist/lib/fn"); -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | export * from "./dist/lib"; -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | module.exports = require("./dist/lib"); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "iterable-query", 3 | "version": "1.0.0-pre.16", 4 | "description": "Query library for ECMAScript iterables.", 5 | "main": "index", 6 | "typings": "index", 7 | "dependencies": { 8 | "@esfx/collection-core": "^1.0.0-pre.11", 9 | "@esfx/collections-hashmap": "^1.0.0-pre.11", 10 | "@esfx/collections-hashset": "^1.0.0-pre.11", 11 | "@esfx/equatable": "^1.0.0-pre.9", 12 | "tslib": "^1.9.3" 13 | }, 14 | "devDependencies": { 15 | "@types/chai": "^4.1.4", 16 | "@types/gulp": "^3.8.36", 17 | "@types/gulp-if": "0.0.33", 18 | "@types/merge2": "^1.1.4", 19 | "@types/minimist": "^1.2.0", 20 | "@types/mocha": "^5.2.5", 21 | "@types/node": "^10.9.4", 22 | "@types/orchestrator": "^0.3.2", 23 | "@types/source-map-support": "^0.4.1", 24 | "@types/vinyl": "^2.0.2", 25 | "c8": "^3.2.1", 26 | "chai": "^4.1.2", 27 | "del": "^3.0.0", 28 | "foreground-child": "^1.5.6", 29 | "gulp": "^3.9.1", 30 | "gulp-if": "^2.0.2", 31 | "gulp-sourcemaps": "^2.6.4", 32 | "gulp-typedoc": "^2.2.0", 33 | "gulp-typescript": "^5.0.0-alpha.3", 34 | "gulp-util": "^3.0.7", 35 | "merge2": "^1.2.2", 36 | "minimist": "^1.2.0", 37 | "mkdirp": "^0.5.1", 38 | "mocha": "^5.2.0", 39 | "prex": "^0.4.3", 40 | "source-map-support": "^0.5.10", 41 | "typedoc": "^0.12.0", 42 | "typedoc-plugin-external-module-name": "^1.1.3", 43 | "typescript": "^3.4.0-rc", 44 | "vm-sandbox": "0.0.0" 45 | }, 46 | "scripts": { 47 | "build": "gulp build", 48 | "test": "gulp test", 49 | "prepublishOnly": "gulp prepublishOnly", 50 | "postpack": "gulp clean:dist" 51 | }, 52 | "repository": { 53 | "type": "git", 54 | "url": "https://github.com/rbuckton/iterable-query.git" 55 | }, 56 | "keywords": [ 57 | "query", 58 | "iterator", 59 | "iterable", 60 | "zip", 61 | "map", 62 | "filter", 63 | "reduce", 64 | "order", 65 | "hierarchy" 66 | ], 67 | "author": "Ron Buckton (rbuckton@chronicles.org)", 68 | "license": "Apache-2.0", 69 | "bugs": { 70 | "url": "https://github.com/rbuckton/iterable-query/issues" 71 | }, 72 | "homepage": "https://github.com/rbuckton/iterable-query" 73 | } 74 | -------------------------------------------------------------------------------- /scripts/coverage.js: -------------------------------------------------------------------------------- 1 | const del = require('del'); 2 | const util = require("util"); 3 | const mkdirp = util.promisify(require("mkdirp")); 4 | const report = require("c8/lib/report"); 5 | 6 | /** 7 | * @param {string} tempDirectory 8 | */ 9 | async function initCoverage(tempDirectory) { 10 | await del(tempDirectory); 11 | await mkdirp(tempDirectory); 12 | } 13 | exports.init = initCoverage; 14 | 15 | /** 16 | * @param {object} options 17 | * @param {string} options.tempDirectory 18 | * @param {string[]} [options.include] 19 | * @param {string[]} [options.exclude] 20 | * @param {string[]} [options.reporter] 21 | */ 22 | function writeCoverage(options) { 23 | console.log("Generating code coverage report... (to disable use '--no-coverage')"); 24 | report({ 25 | ...options, 26 | resolve: "", 27 | omitRelative: true 28 | }); 29 | } 30 | exports.write = writeCoverage; -------------------------------------------------------------------------------- /scripts/mocha.js: -------------------------------------------------------------------------------- 1 | const foreground = require("foreground-child"); 2 | 3 | /** 4 | * @param {object} options 5 | * @param {string[]} options.files 6 | * @param {string} [options.reporter] 7 | * @param {string} [options.coverageTempDirectory] 8 | */ 9 | async function mocha(options) { 10 | const cmd = "./node_modules/.bin/mocha"; 11 | let args = []; 12 | if (options.reporter) args.push("-R", options.reporter); 13 | if (options.coverageTempDirectory) process.env.NODE_V8_COVERAGE = options.coverageTempDirectory; 14 | try { 15 | await new Promise(resolve => foreground(cmd, [...args, ...options.files], () => resolve())); 16 | } 17 | finally { 18 | if (options.coverageTempDirectory) process.env.NODE_V8_COVERAGE = ""; 19 | } 20 | } 21 | 22 | exports.mocha = mocha; -------------------------------------------------------------------------------- /scripts/projects.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | const path = require("path"); 3 | const { exec, Debouncer } = require("./utils"); 4 | 5 | class ProjectQueue { 6 | /** 7 | * @param {(projects: string[], force: boolean) => Promise} action 8 | */ 9 | constructor(action) { 10 | /** @type {{ force: boolean, projects?: string[], debouncer: Debouncer }[]} */ 11 | this._debouncers = []; 12 | this._action = action; 13 | } 14 | 15 | /** 16 | * @param {string} project 17 | * @param {object} options 18 | */ 19 | enqueue(project, { force = false } = {}) { 20 | let entry = this._debouncers.find(entry => entry.force === force); 21 | if (!entry) { 22 | const debouncer = new Debouncer(100, async () => { 23 | const projects = entry.projects; 24 | if (projects) { 25 | entry.projects = undefined; 26 | await this._action(projects, force); 27 | } 28 | }); 29 | this._debouncers.push(entry = { force, debouncer }); 30 | } 31 | if (!entry.projects) entry.projects = []; 32 | entry.projects.push(project); 33 | return entry.debouncer.enqueue(); 34 | } 35 | } 36 | 37 | const projectBuilder = new ProjectQueue((projects, force) => exec(path.resolve("./node_modules/.bin/tsc"), ["-b", ...(force ? ["--force"] : []), ...projects], { hidePrompt: true })); 38 | 39 | /** 40 | * @param {string} project 41 | * @param {object} [options] 42 | * @param {boolean} [options.force=false] 43 | */ 44 | exports.buildProject = (project, { force } = {}) => projectBuilder.enqueue(project, { force }); 45 | 46 | const projectCleaner = new ProjectQueue((projects) => exec(path.resolve("./node_modules/.bin/tsc"), ["-b", "--clean", ...projects], { hidePrompt: true })); 47 | 48 | /** 49 | * @param {string} project 50 | */ 51 | exports.cleanProject = (project) => projectCleaner.enqueue(project); 52 | 53 | const projectWatcher = new ProjectQueue((projects) => exec(path.resolve("./node_modules/.bin/tsc"), ["-b", "--watch", ...projects], { hidePrompt: true })); 54 | 55 | /** 56 | * @param {string} project 57 | */ 58 | exports.watchProject = (project) => projectWatcher.enqueue(project); 59 | -------------------------------------------------------------------------------- /scripts/typedoc.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | const { Sandbox } = require("vm-sandbox"); 3 | const sandbox = new Sandbox({ 4 | base: __dirname, 5 | context: global, 6 | resolve: request => request === "typescript" ? require.resolve("typescript") : undefined 7 | }); 8 | 9 | module.exports = /** @type {typeof import("./typedoc.sandbox")} */(sandbox.require("./typedoc.sandbox.js")); -------------------------------------------------------------------------------- /src/lib/collections.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query" */ 17 | 18 | import "./compat"; 19 | 20 | const _Map = Map; 21 | const _Set = Set; 22 | const _WeakMap = WeakMap; 23 | const _WeakSet = WeakSet; 24 | 25 | export { 26 | _Map as Map, 27 | _Set as Set, 28 | _WeakMap as WeakMap, 29 | _WeakSet as WeakSet 30 | }; -------------------------------------------------------------------------------- /src/lib/compat/es2017.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import "./es2015"; 18 | 19 | // ES2017 compatibility for ES2015 hosts. 20 | if (typeof Symbol.asyncIterator === "undefined") { 21 | Object.defineProperty(Symbol, "asyncIterator", { value: Symbol.for("Symbol.asyncIterator") }); 22 | } -------------------------------------------------------------------------------- /src/lib/compat/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import "./es2015"; 18 | import "./es2017"; -------------------------------------------------------------------------------- /src/lib/fn/append.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable, FlowHierarchy, ToStringTag } from "../internal"; 19 | import { Queryable, HierarchyIterable } from "../types"; 20 | 21 | /** 22 | * Creates a [[HierarchyIterable]] for the elements of `source` with the provided `value` appended to the 23 | * end. 24 | * 25 | * @param source The [[HierarchyIterable]] to append to. 26 | * @param value The value to append. 27 | * @category Subquery 28 | */ 29 | export function append(source: HierarchyIterable, value: T): HierarchyIterable; 30 | /** 31 | * Creates an [[Iterable]] for the elements of `source` with the provided `value` appended to the 32 | * end. 33 | * 34 | * @param source The [[Queryable]] to append to. 35 | * @param value The value to append. 36 | * @category Subquery 37 | */ 38 | export function append(source: Queryable, value: T): Iterable; 39 | export function append(source: Queryable, value: T): Iterable { 40 | assert.mustBeQueryable(source, "source"); 41 | return FlowHierarchy(new AppendIterable(ToIterable(source), value), source); 42 | } 43 | 44 | @ToStringTag("AppendIterable") 45 | class AppendIterable implements Iterable { 46 | private _source: Iterable; 47 | private _value: T; 48 | 49 | constructor(source: Iterable, value: T) { 50 | this._source = source; 51 | this._value = value; 52 | } 53 | 54 | *[Symbol.iterator](): Iterator { 55 | yield* this._source; 56 | yield this._value; 57 | } 58 | } -------------------------------------------------------------------------------- /src/lib/fn/average.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable } from "../internal"; 19 | import { Queryable } from "../types"; 20 | import { identity } from "./common"; 21 | 22 | /** 23 | * Computes the average for a series of numbers. 24 | * 25 | * @param source A [[Queryable]] object. 26 | * @category Scalar 27 | */ 28 | export function average(source: Queryable): number; 29 | /** 30 | * Computes the average for a series of numbers. 31 | * 32 | * @param source A [[Queryable]] object. 33 | * @param elementSelector A callback used to convert a value in `source` to a number. 34 | * @category Scalar 35 | */ 36 | export function average(source: Queryable, elementSelector: (element: T) => number): number; 37 | export function average(source: Queryable, elementSelector: (element: number) => number = identity): number { 38 | assert.mustBeQueryable(source, "source"); 39 | assert.mustBeFunctionOrUndefined(elementSelector, "elementSelector"); 40 | let sum = 0; 41 | let count = 0; 42 | for (const value of ToIterable(source)) { 43 | const result = elementSelector(value); 44 | if (typeof result !== "number") throw new TypeError(); 45 | sum += result; 46 | count++; 47 | } 48 | return count > 0 ? sum / count : 0; 49 | } 50 | -------------------------------------------------------------------------------- /src/lib/fn/averageAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToPossiblyAsyncIterable } from "../internal"; 19 | import { AsyncQueryable } from "../types"; 20 | import { identity } from "./common"; 21 | 22 | /** 23 | * Computes the average for a series of numbers. 24 | * NOTE: If any element is not a `number`, this overload will throw. 25 | * 26 | * @param source An [[AsyncQueryable]] object. 27 | * @category Scalar 28 | */ 29 | export async function averageAsync(source: AsyncQueryable): Promise; 30 | /** 31 | * Computes the average for a series of numbers. 32 | * 33 | * @param source An [[AsyncQueryable]] object. 34 | * @param elementSelector A callback used to convert a value in `source` to a number. 35 | * @category Scalar 36 | */ 37 | export async function averageAsync(source: AsyncQueryable, elementSelector: (element: T) => number | PromiseLike): Promise; 38 | export async function averageAsync(source: AsyncQueryable, elementSelector: (element: number) => number | PromiseLike = identity): Promise { 39 | assert.mustBeAsyncQueryable(source, "source"); 40 | assert.mustBeFunction(elementSelector, "elementSelector"); 41 | let sum = 0; 42 | let count = 0; 43 | for await (const element of ToPossiblyAsyncIterable(source)) { 44 | const value = elementSelector(element); 45 | const result = typeof value === "number" ? value : await value; 46 | assert.mustBeNumber(result); 47 | sum += result; 48 | count++; 49 | } 50 | return count > 0 ? sum / count : 0; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/lib/fn/conditionalAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { ifAsync as conditionalAsync } from "./ifAsync"; 19 | -------------------------------------------------------------------------------- /src/lib/fn/continuous.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { ToStringTag} from "../internal"; 19 | 20 | /** 21 | * Creates an [[Iterable]] that repeats the provided value forever. 22 | * 23 | * @param value The value for each element of the [[Iterable]]. 24 | * @category Query 25 | */ 26 | export function continuous(value: T): Iterable { 27 | return new ContinuousIterable(value); 28 | } 29 | 30 | @ToStringTag("ContinuousIterable") 31 | class ContinuousIterable implements Iterable { 32 | private _value: T; 33 | 34 | constructor(value: T) { 35 | this._value = value; 36 | } 37 | 38 | *[Symbol.iterator](): Iterator { 39 | const value = this._value; 40 | for (;;) { 41 | yield value; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/lib/fn/continuousAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { ToStringTag } from "../internal"; 19 | 20 | /** 21 | * Creates an [[AsyncIterable]] that repeats the provided value forever. 22 | * 23 | * @param value The value for each element of the [[AsyncIterable]]. 24 | * @category Query 25 | */ 26 | export function continuousAsync(value: PromiseLike | T): AsyncIterable { 27 | return new AsyncContinuousIterable(value); 28 | } 29 | 30 | @ToStringTag("AsyncContinuousIterable") 31 | class AsyncContinuousIterable implements AsyncIterable { 32 | private _value: PromiseLike | T; 33 | 34 | constructor(value: PromiseLike | T) { 35 | this._value = value; 36 | } 37 | 38 | async *[Symbol.asyncIterator](): AsyncIterator { 39 | const value = await this._value; 40 | for (;;) { 41 | yield value; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/lib/fn/copyTo.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable } from "../internal"; 19 | import { Queryable, WritableArrayLike } from "../types"; 20 | 21 | /** 22 | * Writes each element of a source iterable to a destination array. 23 | * 24 | * @param source A [[Queryable]] object. 25 | * @param dest The destination array. 26 | * @param start The offset into the array at which to start writing. 27 | * @param count The number of elements to write to the array. 28 | * @category Scalar 29 | */ 30 | export function copyTo>(source: Queryable, dest: U, start: number = 0, count: number = dest.length - start): U { 31 | assert.mustBeQueryable(source, "source"); 32 | assert.mustBeArrayLike(dest, "dest"); 33 | assert.mustBePositiveInteger(start, "start"); 34 | assert.mustBePositiveInteger(count, "count"); 35 | if (count > 0) { 36 | const minLength = start + count; 37 | for (const element of ToIterable(source)) { 38 | if (count > 0) { 39 | dest[start++] = element; 40 | count--; 41 | } 42 | } 43 | if (dest.length < minLength) dest.length = minLength; 44 | } 45 | return dest; 46 | } -------------------------------------------------------------------------------- /src/lib/fn/copyToAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToPossiblyAsyncIterable } from "../internal"; 19 | import { WritableArrayLike, AsyncQueryable } from "../types"; 20 | 21 | /** 22 | * Writes each element of a source iterable to a destination array. 23 | * 24 | * @param source A [[Queryable]] object. 25 | * @param dest The destination array. 26 | * @param start The offset into the array at which to start writing. 27 | * @param count The number of elements to write to the array. 28 | * @category Scalar 29 | */ 30 | export async function copyToAsync>(source: AsyncQueryable, dest: U, start: number = 0, count: number = dest.length - start): Promise { 31 | assert.mustBeAsyncQueryable(source, "source"); 32 | assert.mustBeArrayLike(dest, "dest"); 33 | assert.mustBePositiveInteger(start, "start"); 34 | assert.mustBePositiveInteger(count, "count"); 35 | if (count > 0) { 36 | const minLength = start + count; 37 | for await (const element of ToPossiblyAsyncIterable(source)) { 38 | if (count > 0) { 39 | dest[start++] = element; 40 | count--; 41 | } 42 | } 43 | if (dest.length < minLength) dest.length = minLength; 44 | } 45 | return dest; 46 | } -------------------------------------------------------------------------------- /src/lib/fn/count.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable} from "../internal"; 19 | import { Queryable } from "../types"; 20 | import { Map, Set } from "../collections"; 21 | import { T } from "./common"; 22 | 23 | /** 24 | * Counts the number of elements, optionally filtering elements using the supplied callback. 25 | * 26 | * @param source A [[Queryable]] object. 27 | * @param predicate An optional callback used to match each element. 28 | * @category Scalar 29 | */ 30 | export function count(source: Queryable, predicate: (element: T) => boolean = T): number { 31 | assert.mustBeQueryable(source, "source"); 32 | assert.mustBeFunction(predicate, "predicate"); 33 | 34 | if (predicate === T) { 35 | if (Array.isArray(source)) return source.length; 36 | if (source instanceof Set || source instanceof Map) return source.size; 37 | } 38 | 39 | let count = 0; 40 | for (const element of ToIterable(source)) { 41 | if (predicate(element)) { 42 | count++; 43 | } 44 | } 45 | 46 | return count; 47 | } -------------------------------------------------------------------------------- /src/lib/fn/countAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToPossiblyAsyncIterable, GetAsyncSource } from "../internal"; 19 | import { Map, Set } from "../collections"; 20 | import { AsyncQueryable } from "../types"; 21 | import { T } from "./common"; 22 | 23 | /** 24 | * Counts the number of elements, optionally filtering elements using the supplied callback. 25 | * 26 | * @param source A [[Queryable]] object. 27 | * @param predicate An optional callback used to match each element. 28 | * @category Scalar 29 | */ 30 | export async function countAsync(source: AsyncQueryable, predicate: (element: T) => boolean | PromiseLike = T): Promise { 31 | assert.mustBeAsyncQueryable(source, "source"); 32 | assert.mustBeFunction(predicate, "predicate"); 33 | 34 | if (predicate === T) { 35 | const realSource = GetAsyncSource(source); 36 | if (Array.isArray(realSource)) return realSource.length; 37 | if (realSource instanceof Set || realSource instanceof Map) return realSource.size; 38 | } 39 | 40 | let count = 0; 41 | for await (const element of ToPossiblyAsyncIterable(source)) { 42 | if (predicate === T || await predicate(element)) { 43 | count++; 44 | } 45 | } 46 | 47 | return count; 48 | } -------------------------------------------------------------------------------- /src/lib/fn/distinct.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert } from "../internal"; 19 | import { Queryable, HierarchyIterable } from "../types"; 20 | import { identity } from "./common"; 21 | import { Equaler } from '@esfx/equatable'; 22 | import { distinctBy } from './distinctBy'; 23 | 24 | /** 25 | * Creates a [[HierarchyIterable]] for the distinct elements of `source`. 26 | * @category Subquery 27 | * 28 | * @param source A [[HierarchyIterable]] object. 29 | * @param equaler An [[Equaler]] object used to compare element equality. 30 | */ 31 | export function distinct(source: HierarchyIterable, equaler?: Equaler): HierarchyIterable; 32 | /** 33 | * Creates an [[Iterable]] for the distinct elements of `source`. 34 | * @category Subquery 35 | * 36 | * @param source A [[Queryable]] object. 37 | * @param equaler An [[Equaler]] object used to compare element equality. 38 | */ 39 | export function distinct(source: Queryable, equaler?: Equaler): Iterable; 40 | export function distinct(source: Queryable, equaler?: Equaler): Iterable { 41 | assert.mustBeQueryable(source, "source"); 42 | assert.mustBeEqualerOrUndefined(equaler, "equaler"); 43 | return distinctBy(source, identity, equaler); 44 | } 45 | -------------------------------------------------------------------------------- /src/lib/fn/distinctAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert } from "../internal"; 19 | import { AsyncHierarchyIterable, PossiblyAsyncHierarchyIterable, AsyncQueryable } from "../types"; 20 | import { identity } from "./common"; 21 | import { Equaler } from '@esfx/equatable'; 22 | import { distinctByAsync } from './distinctByAsync'; 23 | 24 | /** 25 | * Creates an [[AsyncHierarchyIterable]] for the distinct elements of `source`. 26 | * @category Subquery 27 | * 28 | * @param source A [[HierarchyIterable]] or [[AsyncHierarchyIterable]] object. 29 | * @param equaler An [[Equaler]] object used to compare element equality. 30 | */ 31 | export function distinctAsync(source: PossiblyAsyncHierarchyIterable, equaler?: Equaler): AsyncHierarchyIterable; 32 | /** 33 | * Creates an [[AsyncIterable]] for the distinct elements of source. 34 | * @category Subquery 35 | * 36 | * @param source An [[AsyncQueryable]] object. 37 | * @param equaler An [[Equaler]] object used to compare element equality. 38 | */ 39 | export function distinctAsync(source: AsyncQueryable, equaler?: Equaler): AsyncIterable; 40 | export function distinctAsync(source: AsyncQueryable, equaler?: Equaler): AsyncIterable { 41 | assert.mustBeAsyncQueryable(source, "source"); 42 | assert.mustBeEqualerOrUndefined(equaler, "equaler"); 43 | return distinctByAsync(source, identity, equaler); 44 | } -------------------------------------------------------------------------------- /src/lib/fn/do.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | // TODO: remove comment once auto-import is fixed 19 | /** @internal */ 20 | export { tap as do } from "./tap"; -------------------------------------------------------------------------------- /src/lib/fn/doAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { tapAsync as doAsync } from "./tapAsync"; -------------------------------------------------------------------------------- /src/lib/fn/drain.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable} from "../internal"; 19 | import { Queryable } from "../types"; 20 | 21 | /** 22 | * Iterates over all of the elements in a [[Queryable]], ignoring the results. 23 | * 24 | * @param source A [[Queryable]] object. 25 | * @category Scalar 26 | */ 27 | export function drain(source: Queryable): void { 28 | assert.mustBeQueryable(source, "source"); 29 | for (const _ of ToIterable(source)) ; 30 | } -------------------------------------------------------------------------------- /src/lib/fn/drainAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToPossiblyAsyncIterable } from "../internal"; 19 | import { AsyncQueryable } from "../types"; 20 | 21 | /** 22 | * Iterates over all of the elements in an [[AsyncQueryable]], ignoring the results. 23 | * 24 | * @param source A [[Queryable]] object. 25 | * @category Scalar 26 | */ 27 | export async function drainAsync(source: AsyncQueryable): Promise { 28 | assert.mustBeAsyncQueryable(source, "source"); 29 | for await (const _ of ToPossiblyAsyncIterable(source)) ; 30 | } -------------------------------------------------------------------------------- /src/lib/fn/elementAt.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable} from "../internal"; 19 | import { Queryable } from "../types"; 20 | import { last } from "./last"; 21 | 22 | /** 23 | * Finds the value at the provided offset. A negative offset starts from the 24 | * last element. 25 | * 26 | * @param source A [[Queryable]] object. 27 | * @param offset An offset. 28 | * @category Scalar 29 | */ 30 | export function elementAt(source: Queryable, offset: number): T | undefined { 31 | assert.mustBeQueryable(source, "source") 32 | assert.mustBeInteger(offset, "offset"); 33 | if (offset === -1) { 34 | return last(source); 35 | } 36 | if (offset < 0) { 37 | offset = Math.abs(offset); 38 | const array: T[] = []; 39 | for (const element of ToIterable(source)) { 40 | if (array.length >= offset) { 41 | array.shift(); 42 | } 43 | array.push(element); 44 | } 45 | return array.length - offset >= 0 ? array[array.length - offset] : undefined; 46 | } 47 | for (const element of ToIterable(source)) { 48 | if (offset === 0) { 49 | return element; 50 | } 51 | offset--; 52 | } 53 | return undefined; 54 | } -------------------------------------------------------------------------------- /src/lib/fn/elementAtAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToPossiblyAsyncIterable } from "../internal"; 19 | import { AsyncQueryable } from "../types"; 20 | import { lastAsync } from "./lastAsync"; 21 | 22 | /** 23 | * Finds the value at the provided offset. A negative offset starts from the 24 | * last element. 25 | * 26 | * @param source An [[AsyncQueryable]] object. 27 | * @param offset An offset. 28 | * @category Scalar 29 | */ 30 | export async function elementAtAsync(source: AsyncQueryable, offset: number): Promise { 31 | assert.mustBeAsyncQueryable(source, "source") 32 | assert.mustBeInteger(offset, "offset"); 33 | if (offset === -1) { 34 | return await lastAsync(source); 35 | } 36 | if (offset < 0) { 37 | offset = Math.abs(offset); 38 | const array: T[] = []; 39 | for await (const element of ToPossiblyAsyncIterable(source)) { 40 | if (array.length >= offset) { 41 | array.shift(); 42 | } 43 | array.push(element); 44 | } 45 | return array.length - offset >= 0 ? array[array.length - offset] : undefined; 46 | } 47 | for await (const element of ToPossiblyAsyncIterable(source)) { 48 | if (offset === 0) { 49 | return element; 50 | } 51 | offset--; 52 | } 53 | return undefined; 54 | } -------------------------------------------------------------------------------- /src/lib/fn/empty.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { ToStringTag } from "../internal"; 19 | 20 | /** 21 | * Creates an [[Iterable]] with no elements. 22 | * @category Query 23 | */ 24 | export function empty(): Iterable { 25 | return new EmptyIterable(); 26 | } 27 | 28 | @ToStringTag("EmptyIterable") 29 | class EmptyIterable implements Iterable { 30 | *[Symbol.iterator](): Iterator { 31 | } 32 | } -------------------------------------------------------------------------------- /src/lib/fn/emptyAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { ToStringTag } from "../internal"; 19 | 20 | /** 21 | * Creates an [[AsyncIterable]] with no elements. 22 | * @category Query 23 | */ 24 | export function emptyAsync(): AsyncIterable { 25 | return new AsyncEmptyIterable(); 26 | } 27 | 28 | @ToStringTag("AsyncEmptyIterable") 29 | class AsyncEmptyIterable implements AsyncIterable { 30 | async *[Symbol.asyncIterator](): AsyncIterator { 31 | } 32 | } -------------------------------------------------------------------------------- /src/lib/fn/eval.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, FlowHierarchy} from "../internal"; 19 | import { Queryable, HierarchyIterable } from "../types"; 20 | import { toArray } from "./toArray"; 21 | 22 | /** 23 | * Eagerly evaluate a [[HierarchyIterable]], returning a [[HierarchyIterable]] for the elements of the original sequence. 24 | * @category Scalar 25 | */ 26 | function _eval(source: HierarchyIterable): HierarchyIterable; 27 | /** 28 | * Eagerly evaluate a [[Queryable]], returning an [[Iterable]] for the elements of the original sequence. 29 | * @category Scalar 30 | */ 31 | function _eval(source: Queryable): Iterable; 32 | function _eval(source: Queryable): Iterable { 33 | assert.mustBeQueryable(source, "source"); 34 | return FlowHierarchy(toArray(source), source); 35 | } 36 | 37 | export { _eval as eval }; 38 | -------------------------------------------------------------------------------- /src/lib/fn/evalAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, FlowHierarchy } from "../internal"; 19 | import { AsyncQueryable, PossiblyAsyncHierarchyIterable, HierarchyIterable } from "../types"; 20 | import { toArrayAsync } from "./toArrayAsync"; 21 | 22 | /** 23 | * Eagerly evaluate a [[HierarchyIterable]] or [[AsyncHierarchyIterable]], returning a [[Promise]] 24 | * for a [[HierarchyIterable]] for the resolved elements of the original sequence. 25 | * 26 | * @param source A [[HierarchyIterable]] or [[AsyncHierarchyIterable]] object. 27 | * @category Scalar 28 | */ 29 | export async function evalAsync(source: PossiblyAsyncHierarchyIterable): Promise>; 30 | /** 31 | * Eagerly evaluate an [[AsyncQueryable]], returning a [[Promise]] for an [[Iterable]] for the 32 | * resolved elements of the original sequence. 33 | * 34 | * @param An [[AsyncQueryable]] object. 35 | * @category Scalar 36 | */ 37 | export async function evalAsync(source: AsyncQueryable): Promise>; 38 | export async function evalAsync(source: AsyncQueryable): Promise> { 39 | assert.mustBeAsyncQueryable(source, "source"); 40 | return FlowHierarchy(await toArrayAsync(source), source); 41 | } -------------------------------------------------------------------------------- /src/lib/fn/every.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable} from "../internal"; 19 | import { Queryable } from "../types"; 20 | 21 | /** 22 | * Computes a scalar value indicating whether all elements match the supplied callback. 23 | * 24 | * @param source A [[Queryable]] object. 25 | * @param predicate A callback used to match each element. 26 | * @category Scalar 27 | */ 28 | export function every(source: Queryable, predicate: (element: T) => element is U): source is Queryable; 29 | /** 30 | * Computes a scalar value indicating whether all elements match the supplied callback. 31 | * 32 | * @param source A [[Queryable]] object. 33 | * @param predicate A callback used to match each element. 34 | * @category Scalar 35 | */ 36 | export function every(source: Queryable, predicate: (element: T) => boolean): boolean; 37 | export function every(source: Queryable, predicate: (element: T) => boolean): boolean { 38 | assert.mustBeQueryable(source, "source"); 39 | assert.mustBeFunction(predicate, "predicate"); 40 | let hasMatchingElements = false; 41 | for (const element of ToIterable(source)) { 42 | if (!predicate(element)) { 43 | return false; 44 | } 45 | hasMatchingElements = true; 46 | } 47 | return hasMatchingElements; 48 | } -------------------------------------------------------------------------------- /src/lib/fn/everyAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToPossiblyAsyncIterable } from "../internal"; 19 | import { AsyncQueryable } from "../types"; 20 | 21 | /** 22 | * Computes a scalar value indicating whether all elements match the supplied callback. 23 | * 24 | * @param source An [[AsyncQueryable]] object. 25 | * @param predicate A callback used to match each element. 26 | * @category Scalar 27 | */ 28 | export async function everyAsync(source: AsyncQueryable, predicate: (element: T) => boolean | PromiseLike): Promise { 29 | assert.mustBeAsyncQueryable(source, "source"); 30 | assert.mustBeFunction(predicate, "predicate"); 31 | let hasMatchingElements = false; 32 | for await (const element of ToPossiblyAsyncIterable(source)) { 33 | const result = predicate(element); 34 | if (!(typeof result === "boolean" ? result : await result)) { 35 | return false; 36 | } 37 | hasMatchingElements = true; 38 | } 39 | return hasMatchingElements; 40 | } -------------------------------------------------------------------------------- /src/lib/fn/except.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert } from "../internal"; 19 | import { Queryable, HierarchyIterable } from "../types"; 20 | import { exceptBy } from './exceptBy'; 21 | import { identity } from './common'; 22 | import { Equaler } from '@esfx/equatable'; 23 | 24 | /** 25 | * Creates a [[HierarchyIterable]] for the set difference between a [[HierarchyIterable]] and a [[Queryable]] object. 26 | * 27 | * @param left A [[HierarchyIterable]] object. 28 | * @param right A [[Queryable]] object. 29 | * @param equaler An [[Equaler]] object used to compare equality. 30 | * @category Subquery 31 | */ 32 | export function except(left: HierarchyIterable, right: Queryable, equaler?: Equaler): HierarchyIterable; 33 | /** 34 | * Creates an [[Iterable]] for the set difference between two [[Queryable]] objects. 35 | * 36 | * @param left A [[Queryable]] object. 37 | * @param right A [[Queryable]] object. 38 | * @param equaler An [[Equaler]] object used to compare equality. 39 | * @category Subquery 40 | */ 41 | export function except(left: Queryable, right: Queryable, equaler?: Equaler): Iterable; 42 | export function except(left: Queryable, right: Queryable, equaler?: Equaler): Iterable { 43 | assert.mustBeQueryable(left, "left"); 44 | assert.mustBeQueryable(right, "right"); 45 | assert.mustBeEqualerOrUndefined(equaler, "equaler"); 46 | return exceptBy(left, right, identity, equaler); 47 | } 48 | -------------------------------------------------------------------------------- /src/lib/fn/exclude.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert } from "../internal"; 19 | import { Queryable, HierarchyIterable } from "../types"; 20 | import { exceptBy } from './exceptBy'; 21 | import { identity } from './common'; 22 | 23 | /** 24 | * Creates a [[HierarchyIterable]] with every instance of the specified value removed. 25 | * 26 | * @param source A [[HierarchyIterable]] object. 27 | * @param values The values to exclude. 28 | * @category Subquery 29 | */ 30 | export function exclude(source: HierarchyIterable, ...values: [T, ...T[]]): HierarchyIterable; 31 | /** 32 | * Creates an [[Iterable]] with every instance of the specified value removed. 33 | * 34 | * @param source A [[Queryable]] object. 35 | * @param values The values to exclude. 36 | * @category Subquery 37 | */ 38 | export function exclude(source: Queryable, ...values: [T, ...T[]]): Iterable; 39 | export function exclude(source: Queryable, ...values: [T, ...T[]]): Iterable { 40 | assert.mustBeQueryable(source, "left"); 41 | return exceptBy(source, values, identity); 42 | } -------------------------------------------------------------------------------- /src/lib/fn/excludeAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert } from "../internal"; 19 | import { PossiblyAsyncHierarchyIterable, AsyncQueryable, AsyncHierarchyIterable } from "../types"; 20 | import { exceptByAsync } from './exceptByAsync'; 21 | import { identity } from './common'; 22 | 23 | /** 24 | * Creates an [[AsyncHierarchyIterable]] with every instance of the specified value removed. 25 | * 26 | * @param source A [[HierarchyIterable]] or [[AsyncHierarchyIterable]] object. 27 | * @param values The values to exclude. 28 | * @category Subquery 29 | */ 30 | export function excludeAsync(source: PossiblyAsyncHierarchyIterable, ...values: [T | PromiseLike, ...(T | PromiseLike)[]]): AsyncHierarchyIterable; 31 | /** 32 | * Creates an [[AsyncIterable]] with every instance of the specified value removed. 33 | * 34 | * @param source An [[AsyncQueryable]] object. 35 | * @param values The values to exclude. 36 | * @category Subquery 37 | */ 38 | export function excludeAsync(source: AsyncQueryable, ...values: [T | PromiseLike, ...(T | PromiseLike)[]]): AsyncIterable; 39 | export function excludeAsync(source: AsyncQueryable, ...values: [T | PromiseLike, ...(T | PromiseLike)[]]): AsyncIterable { 40 | assert.mustBeAsyncQueryable(source, "left"); 41 | return exceptByAsync(source, values, identity); 42 | } 43 | -------------------------------------------------------------------------------- /src/lib/fn/first.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable} from "../internal"; 19 | import { Queryable } from "../types"; 20 | import { T } from "./common"; 21 | 22 | /** 23 | * Gets the first element, optionally filtering elements using the supplied callback. 24 | * 25 | * @param source A [[Queryable]] object. 26 | * @param predicate An optional callback used to match each element. 27 | * @category Scalar 28 | */ 29 | export function first(source: Queryable, predicate: (element: T) => boolean = T): T | undefined { 30 | assert.mustBeQueryable(source, "source"); 31 | assert.mustBeFunction(predicate, "predicate"); 32 | for (const element of ToIterable(source)) { 33 | if (predicate(element)) { 34 | return element; 35 | } 36 | } 37 | return undefined; 38 | } -------------------------------------------------------------------------------- /src/lib/fn/firstAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToPossiblyAsyncIterable } from "../internal"; 19 | import { AsyncQueryable } from "../types"; 20 | import { T } from "./common"; 21 | 22 | /** 23 | * Gets the first element, optionally filtering elements using the supplied callback. 24 | * 25 | * @param source A [[Queryable]] object. 26 | * @param predicate An optional callback used to match each element. 27 | * @category Scalar 28 | */ 29 | export async function firstAsync(source: AsyncQueryable, predicate: (element: T) => element is U): Promise; 30 | /** 31 | * Gets the first element, optionally filtering elements using the supplied callback. 32 | * 33 | * @param source A [[Queryable]] object. 34 | * @param predicate An optional callback used to match each element. 35 | * @category Scalar 36 | */ 37 | export async function firstAsync(source: AsyncQueryable, predicate?: (element: T) => boolean | PromiseLike): Promise; 38 | export async function firstAsync(source: AsyncQueryable, predicate: (element: T) => boolean | PromiseLike = T): Promise { 39 | assert.mustBeAsyncQueryable(source, "source"); 40 | assert.mustBeFunction(predicate, "predicate"); 41 | for await (const element of ToPossiblyAsyncIterable(source)) { 42 | const result = predicate(element); 43 | if (typeof result === "boolean" ? result : await result) { 44 | return element; 45 | } 46 | } 47 | return undefined; 48 | } -------------------------------------------------------------------------------- /src/lib/fn/forEach.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable} from "../internal"; 19 | import { Queryable } from "../types"; 20 | 21 | /** 22 | * Invokes a callback for each element of `source`. 23 | * 24 | * @param source A [[Queryable]] object. 25 | * @param callback The callback to invoke. 26 | * @category Scalar 27 | */ 28 | export function forEach(source: Queryable, callback: (element: T, offset: number) => void): void { 29 | assert.mustBeQueryable(source, "source"); 30 | assert.mustBeFunction(callback, "callback"); 31 | let offset = 0; 32 | for (const element of ToIterable(source)) { 33 | callback(element, offset++); 34 | } 35 | } -------------------------------------------------------------------------------- /src/lib/fn/forEachAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToPossiblyAsyncIterable } from "../internal"; 19 | import { AsyncQueryable } from "../types"; 20 | 21 | /** 22 | * Invokes a callback for each element of `source`. 23 | * 24 | * @param source An [[AsyncQueryable]] object. 25 | * @param callback The callback to invoke. 26 | * @category Scalar 27 | */ 28 | export async function forEachAsync(source: AsyncQueryable, callback: (element: T, offset: number) => void | PromiseLike): Promise { 29 | assert.mustBeAsyncQueryable(source, "source"); 30 | assert.mustBeFunction(callback, "callback"); 31 | let offset = 0; 32 | for await (const element of ToPossiblyAsyncIterable(source)) { 33 | const result = callback(element, offset++); 34 | if (typeof result !== "undefined") await result; 35 | } 36 | } -------------------------------------------------------------------------------- /src/lib/fn/generate.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToStringTag} from "../internal"; 19 | 20 | /** 21 | * Creates an [[Iterable]] whose values are provided by a callback executed a provided number of 22 | * times. 23 | * 24 | * @param count The number of times to execute the callback. 25 | * @param generator The callback to execute. 26 | * @category Query 27 | */ 28 | export function generate(count: number, generator: (offset: number) => T): Iterable { 29 | assert.mustBePositiveFiniteNumber(count, "count"); 30 | assert.mustBeFunction(generator, "generator"); 31 | return new GenerateIterable(count, generator); 32 | } 33 | 34 | @ToStringTag("GenerateIterable") 35 | class GenerateIterable implements Iterable { 36 | private _count: number; 37 | private _generator: (offset: number) => T; 38 | 39 | constructor(count: number, generator: (offset: number) => T) { 40 | this._count = count; 41 | this._generator = generator; 42 | } 43 | 44 | *[Symbol.iterator](): Iterator { 45 | const count = this._count; 46 | const generator = this._generator; 47 | for (let i = 0; i < count; i++) { 48 | yield generator(i); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /src/lib/fn/generateAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToStringTag } from "../internal"; 19 | 20 | /** 21 | * Creates an [[AsyncIterable]] whose values are provided by a callback executed a provided number of 22 | * times. 23 | * 24 | * @param count The number of times to execute the callback. 25 | * @param generator The callback to execute. 26 | * @category Query 27 | */ 28 | export function generateAsync(count: number, generator: (offset: number) => PromiseLike | T): AsyncIterable { 29 | assert.mustBePositiveFiniteNumber(count, "count"); 30 | assert.mustBeFunction(generator, "generator"); 31 | return new AsyncGenerateIterable(count, generator); 32 | } 33 | 34 | @ToStringTag("AsyncGenerateIterable") 35 | class AsyncGenerateIterable implements AsyncIterable { 36 | private _count: number; 37 | private _generator: (offset: number) => PromiseLike | T; 38 | 39 | constructor(count: number, generator: (offset: number) => PromiseLike | T) { 40 | this._count = count; 41 | this._generator = generator; 42 | } 43 | 44 | async *[Symbol.asyncIterator](): AsyncIterator { 45 | const count = this._count; 46 | const generator = this._generator; 47 | for (let i = 0; i < count; i++) { 48 | yield generator(i); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /src/lib/fn/hierarchy.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, MakeHierarchyIterable } from "../internal"; 19 | import { HierarchyProvider, HierarchyIterable } from "../types"; 20 | import { once } from "./once"; 21 | 22 | /** 23 | * Creates a [[HierarchyIterable]] for a root element using the provided [[HierarchyProvider]]. 24 | * 25 | * @param root The root element. 26 | * @param hierarchy A [[HierarchyProvider]] object. 27 | * @category Hierarchy 28 | */ 29 | export function hierarchy(root: T, hierarchy: HierarchyProvider): HierarchyIterable { 30 | assert.mustBeHierarchyProvider(hierarchy, "hierarchy"); 31 | return MakeHierarchyIterable(once(root), hierarchy); 32 | } -------------------------------------------------------------------------------- /src/lib/fn/hierarchyAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, MakeAsyncHierarchyIterable } from "../internal"; 19 | import { HierarchyProvider, AsyncHierarchyIterable } from "../types"; 20 | import { onceAsync } from "./onceAsync"; 21 | 22 | /** 23 | * Creates an [[AsyncHierarchyIterable]] for a resolved root element using the provided [[HierarchyProvider]]. 24 | * 25 | * @param root The root element. 26 | * @param hierarchy A [[HierarchyProvider]] object. 27 | * @category Hierarchy 28 | */ 29 | export function hierarchyAsync(root: PromiseLike | T, hierarchy: HierarchyProvider): AsyncHierarchyIterable { 30 | assert.mustBeHierarchyProvider(hierarchy, "hierarchy"); 31 | return MakeAsyncHierarchyIterable(onceAsync(root), hierarchy); 32 | } -------------------------------------------------------------------------------- /src/lib/fn/if.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | // TODO: remove comment once auto-import is fixed 19 | /** @internal */ 20 | export { conditional as if } from "./conditional"; -------------------------------------------------------------------------------- /src/lib/fn/includes.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable } from "../internal"; 19 | import { Queryable } from "../types"; 20 | import { EqualityComparison, Equaler } from '@esfx/equatable'; 21 | 22 | /** 23 | * Computes a scalar value indicating whether the provided value is included in a [[Queryable]]. 24 | * 25 | * @param source A [[Queryable]] object. 26 | * @param value A value. 27 | * @param equaler An optional callback used to compare the equality of two elements. 28 | * @category Scalar 29 | */ 30 | export function includes(source: Queryable, value: T, equaler?: EqualityComparison | Equaler): boolean; 31 | /** 32 | * Computes a scalar value indicating whether the provided value is included in a [[Queryable]]. 33 | * 34 | * @param source A [[Queryable]] object. 35 | * @param value A value. 36 | * @param equaler An optional callback used to compare the equality of two elements. 37 | * @category Scalar 38 | */ 39 | export function includes(source: Queryable, value: U, equaler: (left: T, right: U) => boolean): boolean; 40 | export function includes(source: Queryable, value: T, equaler: EqualityComparison | Equaler = Equaler.defaultEqualer): boolean { 41 | if (typeof equaler === "function") equaler = Equaler.create(equaler); 42 | assert.mustBeQueryable(source, "source"); 43 | assert.mustBeEqualer(equaler, "equaler"); 44 | for (const element of ToIterable(source)) { 45 | if (equaler.equals(value, element)) { 46 | return true; 47 | } 48 | } 49 | return false; 50 | } -------------------------------------------------------------------------------- /src/lib/fn/last.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable} from "../internal"; 19 | import { Queryable } from "../types"; 20 | import { T } from "./common"; 21 | 22 | /** 23 | * Gets the last element of a [[Queryable]], optionally filtering elements using the supplied 24 | * callback. 25 | * 26 | * @param source A [[Queryable]] object. 27 | * @param predicate An optional callback used to match each element. 28 | * @category Scalar 29 | */ 30 | export function last(source: Queryable, predicate: (element: T) => boolean = T): T | undefined { 31 | assert.mustBeQueryable(source, "source"); 32 | assert.mustBeFunction(predicate, "predicate"); 33 | let result: T | undefined; 34 | for (const element of ToIterable(source)) { 35 | if (predicate(element)) { 36 | result = element; 37 | } 38 | } 39 | return result; 40 | } -------------------------------------------------------------------------------- /src/lib/fn/map.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable, ToStringTag} from "../internal"; 19 | import { Queryable } from "../types"; 20 | 21 | /** 22 | * Creates an [[Iterable]] by applying a callback to each element of a [[Queryable]]. 23 | * 24 | * @param source A [[Queryable]] object. 25 | * @param selector A callback used to map each element. 26 | * @category Subquery 27 | */ 28 | export function map(source: Queryable, selector: (element: T, offset: number) => U): Iterable { 29 | assert.mustBeQueryable(source, "source"); 30 | assert.mustBeFunction(selector, "selector"); 31 | return new MapIterable(ToIterable(source), selector); 32 | } 33 | 34 | @ToStringTag("MapIterable") 35 | class MapIterable implements Iterable { 36 | private _source: Iterable; 37 | private _selector: (element: T, offset: number) => U; 38 | 39 | constructor(source: Iterable, selector: (element: T, offset: number) => U) { 40 | this._source = source; 41 | this._selector = selector; 42 | } 43 | 44 | *[Symbol.iterator](): Iterator { 45 | const selector = this._selector; 46 | let offset = 0; 47 | for (const element of this._source) { 48 | yield selector(element, offset++); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/lib/fn/mapAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToPossiblyAsyncIterable, ToStringTag } from "../internal"; 19 | import { AsyncQueryable, PossiblyAsyncIterable } from "../types"; 20 | 21 | /** 22 | * Creates an [[AsyncIterable]] by applying a callback to each element of an [[AsyncQueryable]]. 23 | * 24 | * @param source An [[AsyncQueryable]] object. 25 | * @param selector A callback used to map each element. 26 | * @category Subquery 27 | */ 28 | export function mapAsync(source: AsyncQueryable, selector: (element: T, offset: number) => U | PromiseLike): AsyncIterable { 29 | assert.mustBeAsyncQueryable(source, "source"); 30 | assert.mustBeFunction(selector, "selector"); 31 | return new AsyncMapIterable(ToPossiblyAsyncIterable(source), selector); 32 | } 33 | 34 | @ToStringTag("AsyncMapIterable") 35 | class AsyncMapIterable implements AsyncIterable { 36 | private _source: PossiblyAsyncIterable; 37 | private _selector: (element: T, offset: number) => U | PromiseLike; 38 | 39 | constructor(source: PossiblyAsyncIterable, selector: (element: T, offset: number) => U | PromiseLike) { 40 | this._source = source; 41 | this._selector = selector; 42 | } 43 | 44 | async *[Symbol.asyncIterator](): AsyncIterator { 45 | const selector = this._selector; 46 | let offset = 0; 47 | for await (const element of this._source) { 48 | yield selector(element, offset++); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /src/lib/fn/max.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert } from "../internal"; 19 | import { Queryable } from "../types"; 20 | import { identity } from "./common"; 21 | import { maxBy } from './maxBy'; 22 | import { Comparison, Comparer } from '@esfx/equatable'; 23 | 24 | /** 25 | * Gets the maximum element of a [[Queryable]], optionally comparing elements using the supplied callback. 26 | * 27 | * @param source A [[Queryable]] object. 28 | * @param comparer An optional callback used to compare two elements. 29 | * @category Scalar 30 | */ 31 | export function max(source: Queryable, comparer: Comparison | Comparer = Comparer.defaultComparer): T | undefined { 32 | if (typeof comparer === "function") comparer = Comparer.create(comparer); 33 | assert.mustBeQueryable(source, "source"); 34 | assert.mustBeComparer(comparer, "comparer"); 35 | return maxBy(source, identity, comparer); 36 | } -------------------------------------------------------------------------------- /src/lib/fn/maxAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert } from "../internal"; 19 | import { AsyncQueryable } from "../types"; 20 | import { identity } from "./common"; 21 | import { maxByAsync } from './maxByAsync'; 22 | import { Comparison, Comparer } from '@esfx/equatable'; 23 | 24 | /** 25 | * Gets the maximum element of an [[AsyncQueryable]], optionally comparing elements using the supplied callback. 26 | * 27 | * @param source An [[AsyncQueryable]] object. 28 | * @param comparer An optional callback used to compare two elements. 29 | * @category Scalar 30 | */ 31 | export async function maxAsync(source: AsyncQueryable, comparer: Comparison | Comparer = Comparer.defaultComparer): Promise { 32 | if (typeof comparer === "function") comparer = Comparer.create(comparer); 33 | assert.mustBeAsyncQueryable(source, "source"); 34 | assert.mustBeComparer(comparer, "comparer"); 35 | return maxByAsync(source, identity, comparer); 36 | } -------------------------------------------------------------------------------- /src/lib/fn/maxBy.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable } from "../internal"; 19 | import { Queryable } from "../types"; 20 | import { Comparison, Comparer } from '@esfx/equatable'; 21 | 22 | /** 23 | * Gets the maximum element of a [[Queryable]], optionally comparing the keys of each element using the supplied callback. 24 | * 25 | * @param source A [[Queryable]] object. 26 | * @param keySelector A callback used to choose the key to compare. 27 | * @param keyComparer An optional callback used to compare the keys. 28 | * @category Scalar 29 | */ 30 | export function maxBy(source: Queryable, keySelector: (value: T) => K, keyComparer: Comparison | Comparer = Comparer.defaultComparer): T | undefined { 31 | if (typeof keyComparer === "function") keyComparer = Comparer.create(keyComparer); 32 | assert.mustBeQueryable(source, "source"); 33 | assert.mustBeFunction(keySelector, "keySelector"); 34 | assert.mustBeComparer(keyComparer, "keyComparer"); 35 | let hasResult = false; 36 | let result: T | undefined; 37 | let resultKey: K | undefined; 38 | for (const element of ToIterable(source)) { 39 | const key = keySelector(element); 40 | if (!hasResult) { 41 | result = element; 42 | resultKey = key; 43 | hasResult = true; 44 | } 45 | else if (keyComparer.compare(key, resultKey!) > 0) { 46 | result = element; 47 | resultKey = key; 48 | } 49 | } 50 | return result; 51 | } -------------------------------------------------------------------------------- /src/lib/fn/maxByAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToPossiblyAsyncIterable } from "../internal"; 19 | import { AsyncQueryable } from "../types"; 20 | import { Comparison, Comparer } from '@esfx/equatable'; 21 | 22 | /** 23 | * Gets the maximum element of an [[AsyncQueryable]], optionally comparing the keys of each element using the supplied callback. 24 | * 25 | * @param source An [[AsyncQueryable]] object. 26 | * @param keySelector A callback used to choose the key to compare. 27 | * @param keyComparer An optional callback used to compare the keys. 28 | * @category Scalar 29 | */ 30 | export async function maxByAsync(source: AsyncQueryable, keySelector: (value: T) => K, keyComparer: Comparison | Comparer = Comparer.defaultComparer): Promise { 31 | if (typeof keyComparer === "function") keyComparer = Comparer.create(keyComparer); 32 | assert.mustBeAsyncQueryable(source, "source"); 33 | assert.mustBeFunction(keySelector, "keySelector"); 34 | assert.mustBeComparer(keyComparer, "keyComparer"); 35 | let hasResult = false; 36 | let result: T | undefined; 37 | let resultKey: K | undefined; 38 | for await (const element of ToPossiblyAsyncIterable(source)) { 39 | const key = keySelector(element); 40 | if (!hasResult) { 41 | result = element; 42 | resultKey = key; 43 | hasResult = true; 44 | } 45 | else if (keyComparer.compare(key, resultKey!) > 0) { 46 | result = element; 47 | resultKey = key; 48 | } 49 | } 50 | return result; 51 | } -------------------------------------------------------------------------------- /src/lib/fn/min.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert } from "../internal"; 19 | import { Queryable } from "../types"; 20 | import { identity } from "./common"; 21 | import { minBy } from './minBy'; 22 | import { Comparison, Comparer } from '@esfx/equatable'; 23 | 24 | /** 25 | * Gets the minimum element of a [[Queryable]], optionally comparing elements using the supplied callback. 26 | * 27 | * @param source A [[Queryable]] object. 28 | * @param comparer An optional callback used to compare two elements. 29 | * @category Scalar 30 | */ 31 | export function min(source: Queryable, comparer: Comparison | Comparer = Comparer.defaultComparer): T | undefined { 32 | if (typeof comparer === "function") comparer = Comparer.create(comparer); 33 | assert.mustBeQueryable(source, "source"); 34 | assert.mustBeComparer(comparer, "comparer"); 35 | return minBy(source, identity, comparer); 36 | } -------------------------------------------------------------------------------- /src/lib/fn/minAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert } from "../internal"; 19 | import { AsyncQueryable } from "../types"; 20 | import { identity } from "./common"; 21 | import { minByAsync } from './minByAsync'; 22 | import { Comparison, Comparer } from '@esfx/equatable'; 23 | 24 | /** 25 | * Gets the minimum element of an [[AsyncQueryable]], optionally comparing elements using the supplied callback. 26 | * 27 | * @param source An [[AsyncQueryable]] object. 28 | * @param comparer An optional callback used to compare two elements. 29 | * @category Scalar 30 | */ 31 | export async function minAsync(source: AsyncQueryable, comparer: Comparison | Comparer = Comparer.defaultComparer): Promise { 32 | if (typeof comparer === "function") comparer = Comparer.create(comparer); 33 | assert.mustBeAsyncQueryable(source, "source"); 34 | assert.mustBeComparer(comparer, "comparer"); 35 | return minByAsync(source, identity, comparer); 36 | } -------------------------------------------------------------------------------- /src/lib/fn/minBy.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable } from "../internal"; 19 | import { Queryable } from "../types"; 20 | import { Comparison, Comparer } from '@esfx/equatable'; 21 | 22 | /** 23 | * Gets the minimum element of a [[Queryable]], optionally comparing the keys of each element using the supplied callback. 24 | * 25 | * @param source A [[Queryable]] object. 26 | * @param keySelector A callback used to choose the key to compare. 27 | * @param keyComparer An optional callback used to compare the keys. 28 | * @category Scalar 29 | */ 30 | export function minBy(source: Queryable, keySelector: (value: T) => K, keyComparer: Comparison | Comparer = Comparer.defaultComparer): T | undefined { 31 | if (typeof keyComparer === "function") keyComparer = Comparer.create(keyComparer); 32 | assert.mustBeQueryable(source, "source"); 33 | assert.mustBeFunction(keySelector, "keySelector"); 34 | assert.mustBeComparer(keyComparer, "keyComparer"); 35 | let hasResult = false; 36 | let result: T | undefined; 37 | let resultKey: K | undefined; 38 | for (const element of ToIterable(source)) { 39 | const key = keySelector(element); 40 | if (!hasResult) { 41 | result = element; 42 | resultKey = key; 43 | hasResult = true; 44 | } 45 | else if (keyComparer.compare(key, resultKey!) < 0) { 46 | result = element; 47 | resultKey = key; 48 | } 49 | } 50 | return result; 51 | } -------------------------------------------------------------------------------- /src/lib/fn/minByAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToPossiblyAsyncIterable } from "../internal"; 19 | import { AsyncQueryable } from "../types"; 20 | import { Comparison, Comparer } from '@esfx/equatable'; 21 | 22 | /** 23 | * Gets the minimum element of an [[AsyncQueryable]], optionally comparing the keys of each element using the supplied callback. 24 | * 25 | * @param source An [[AsyncQueryable]] object. 26 | * @param keySelector A callback used to choose the key to compare. 27 | * @param keyComparer An optional callback used to compare the keys. 28 | * @category Scalar 29 | */ 30 | export async function minByAsync(source: AsyncQueryable, keySelector: (value: T) => K, keyComparer: Comparison | Comparer = Comparer.defaultComparer): Promise { 31 | if (typeof keyComparer === "function") keyComparer = Comparer.create(keyComparer); 32 | assert.mustBeAsyncQueryable(source, "source"); 33 | assert.mustBeFunction(keySelector, "keySelector"); 34 | assert.mustBeComparer(keyComparer, "keyComparer"); 35 | let hasResult = false; 36 | let result: T | undefined; 37 | let resultKey: K | undefined; 38 | for await (const element of ToPossiblyAsyncIterable(source)) { 39 | const key = keySelector(element); 40 | if (!hasResult) { 41 | result = element; 42 | resultKey = key; 43 | hasResult = true; 44 | } 45 | else if (keyComparer.compare(key, resultKey!) < 0) { 46 | result = element; 47 | resultKey = key; 48 | } 49 | } 50 | return result; 51 | } -------------------------------------------------------------------------------- /src/lib/fn/nth.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { elementAt as nth } from "./elementAt"; -------------------------------------------------------------------------------- /src/lib/fn/nthAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { elementAtAsync as nthAsync } from "./elementAtAsync"; -------------------------------------------------------------------------------- /src/lib/fn/objectEntries.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToStringTag } from "../internal"; 19 | import { KeyValuePair } from "../types"; 20 | 21 | /** 22 | * Creates an [[Iterable]] for the own property entries of an `object`. 23 | * 24 | * @param source An `object`. 25 | * @category Query 26 | */ 27 | export function objectEntries(source: T): Iterable>> { 28 | assert.mustBeObject(source, "source"); 29 | return new ObjectEntriesIterable(source); 30 | } 31 | 32 | @ToStringTag("ObjectEntriesIterable") 33 | class ObjectEntriesIterable implements Iterable>> { 34 | private _source: T; 35 | constructor(source: T) { 36 | this._source = source; 37 | } 38 | 39 | *[Symbol.iterator](): Iterator>> { 40 | const source = this._source; 41 | for (const key of Object.keys(source) as Extract[]) { 42 | yield [key, source[key]] as KeyValuePair>; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /src/lib/fn/objectEntriesAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToStringTag } from "../internal"; 19 | import { KeyValuePair } from "../types"; 20 | 21 | /** 22 | * Creates an [[AsyncIterable]] for the own property entries of an `object`. 23 | * 24 | * @param source An `object` or a [[Promise]] for an `object`. 25 | * @category Query 26 | */ 27 | export function objectEntriesAsync(source: PromiseLike | T): AsyncIterable>> { 28 | assert.mustBeObject(source, "source"); 29 | return new AsyncObjectEntriesIterable(source); 30 | } 31 | 32 | @ToStringTag("AsyncObjectEntriesIterable") 33 | class AsyncObjectEntriesIterable implements AsyncIterable>> { 34 | private _source: PromiseLike | T; 35 | constructor(source: PromiseLike | T) { 36 | this._source = source; 37 | } 38 | 39 | async *[Symbol.asyncIterator](): AsyncIterator>> { 40 | const source = await this._source; 41 | assert.mustBeObject(source, "source"); 42 | for (const key of Object.keys(source) as Extract[]) { 43 | yield [key, source[key]] as KeyValuePair>; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/lib/fn/objectKeys.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToStringTag } from "../internal"; 19 | 20 | /** 21 | * Creates an [[Iterable]] for the own property keys of an `object`. 22 | * 23 | * @param source An `object`. 24 | * @category Query 25 | */ 26 | export function objectKeys(source: T): Iterable> { 27 | assert.mustBeObject(source, "source"); 28 | return new ObjectKeysIterable(source); 29 | } 30 | 31 | @ToStringTag("ObjectKeysIterable") 32 | class ObjectKeysIterable implements Iterable> { 33 | private _source: T; 34 | constructor(source: T) { 35 | this._source = source; 36 | } 37 | 38 | *[Symbol.iterator](): Iterator> { 39 | const source = this._source; 40 | yield* Object.keys(source) as Extract[]; 41 | } 42 | } -------------------------------------------------------------------------------- /src/lib/fn/objectKeysAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToStringTag } from "../internal"; 19 | 20 | /** 21 | * Creates an [[AsyncIterable]] for the own property keys of an `object`. 22 | * 23 | * @param source An `object` or a [[Promise]] for an `object`. 24 | * @category Query 25 | */ 26 | export function objectKeysAsync(source: PromiseLike | T): AsyncIterable> { 27 | assert.mustBeObject(source, "source"); 28 | return new AsyncObjectKeysIterable(source); 29 | } 30 | 31 | @ToStringTag("AsyncObjectKeysIterable") 32 | class AsyncObjectKeysIterable implements AsyncIterable> { 33 | private _source: PromiseLike | T; 34 | constructor(source: PromiseLike | T) { 35 | this._source = source; 36 | } 37 | 38 | async *[Symbol.asyncIterator](): AsyncIterator> { 39 | const source = await this._source; 40 | assert.mustBeObject(source, "source"); 41 | yield* Object.keys(source) as Extract[]; 42 | } 43 | } -------------------------------------------------------------------------------- /src/lib/fn/objectValues.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToStringTag } from "../internal"; 19 | 20 | /** 21 | * Creates an [[Iterable]] for the own property values of an `object`. 22 | * 23 | * @param source An `object`. 24 | * @category Query 25 | */ 26 | export function objectValues(source: T): Iterable]> { 27 | assert.mustBeObject(source, "source"); 28 | return new ObjectValuesIterable(source); 29 | } 30 | 31 | @ToStringTag("ObjectValuesIterable") 32 | class ObjectValuesIterable implements Iterable]> { 33 | private _source: T; 34 | constructor(source: T) { 35 | this._source = source; 36 | } 37 | 38 | *[Symbol.iterator](): Iterator]> { 39 | const source = this._source; 40 | for (const key of Object.keys(source) as Extract[]) { 41 | yield source[key]; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/lib/fn/objectValuesAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToStringTag } from "../internal"; 19 | 20 | /** 21 | * Creates an [[AsyncIterable]] for the own property values of an `object`. 22 | * 23 | * @param source An `object` or a [[Promise]] for an `object`. 24 | * @category Query 25 | */ 26 | export function objectValuesAsync(source: PromiseLike | T): AsyncIterable]> { 27 | assert.mustBeObject(source, "source"); 28 | return new AsyncObjectValuesIterable(source); 29 | } 30 | 31 | @ToStringTag("AsyncObjectValuesIterable") 32 | class AsyncObjectValuesIterable implements AsyncIterable]> { 33 | private _source: PromiseLike | T; 34 | constructor(source: PromiseLike | T) { 35 | this._source = source; 36 | } 37 | 38 | async *[Symbol.asyncIterator](): AsyncIterator]> { 39 | const source = await this._source; 40 | assert.mustBeObject(source, "source"); 41 | for (const key of Object.keys(source) as Extract[]) { 42 | yield source[key]; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /src/lib/fn/once.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { ToStringTag} from "../internal"; 19 | 20 | /** 21 | * Creates an [[Iterable]] over a single element. 22 | * 23 | * @param value The only element for the [[Iterable]]. 24 | * @category Query 25 | */ 26 | export function once(value: T): Iterable { 27 | return new OnceIterable(value); 28 | } 29 | 30 | @ToStringTag("OnceIterable") 31 | class OnceIterable implements Iterable { 32 | private _value: T; 33 | 34 | constructor(value: T) { 35 | this._value = value; 36 | } 37 | 38 | *[Symbol.iterator](): Iterator { 39 | yield this._value; 40 | } 41 | } -------------------------------------------------------------------------------- /src/lib/fn/onceAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { ToStringTag } from "../internal"; 19 | 20 | /** 21 | * Creates an [[AsyncIterable]] over a single element. 22 | * 23 | * @param value The only element for the [[AsyncIterable]]. 24 | * @category Query 25 | */ 26 | export function onceAsync(value: PromiseLike | T): AsyncIterable { 27 | return new AsyncOnceIterable(value); 28 | } 29 | 30 | @ToStringTag("AsyncOnceIterable") 31 | class AsyncOnceIterable implements AsyncIterable { 32 | private _value: PromiseLike | T; 33 | 34 | constructor(value: PromiseLike | T) { 35 | this._value = value; 36 | } 37 | 38 | async *[Symbol.asyncIterator](): AsyncIterator { 39 | yield this._value; 40 | } 41 | } -------------------------------------------------------------------------------- /src/lib/fn/prepend.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable, FlowHierarchy, ToStringTag} from "../internal"; 19 | import { Queryable, HierarchyIterable } from "../types"; 20 | 21 | /** 22 | * Creates a subquery for the elements of the source with the provided value prepended to the beginning. 23 | * 24 | * @param value The value to prepend. 25 | * @category Subquery 26 | */ 27 | export function prepend(source: HierarchyIterable, value: T): HierarchyIterable; 28 | /** 29 | * Creates a subquery for the elements of the source with the provided value prepended to the beginning. 30 | * 31 | * @param value The value to prepend. 32 | * @category Subquery 33 | */ 34 | export function prepend(source: Queryable, value: T): Iterable; 35 | export function prepend(source: Queryable, value: T): Iterable { 36 | assert.mustBeQueryable(source, "source"); 37 | return FlowHierarchy(new PrependIterable(value, ToIterable(source)), source); 38 | } 39 | 40 | @ToStringTag("PrependIterable") 41 | class PrependIterable implements Iterable { 42 | private _source: Iterable; 43 | private _value: T; 44 | 45 | constructor(value: T, source: Iterable) { 46 | this._value = value; 47 | this._source = source; 48 | } 49 | 50 | *[Symbol.iterator](): Iterator { 51 | yield this._value; 52 | yield* this._source; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/lib/fn/relativeComplement.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { except as relativeComplement } from "./except"; -------------------------------------------------------------------------------- /src/lib/fn/relativeComplementAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { exceptAsync as relativeComplementAsync } from "./exceptAsync"; -------------------------------------------------------------------------------- /src/lib/fn/relativeComplementBy.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { exceptBy as relativeComplementBy } from "./exceptBy"; -------------------------------------------------------------------------------- /src/lib/fn/relativeComplementByAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { exceptByAsync as relativeComplementByAsync } from "./exceptByAsync"; -------------------------------------------------------------------------------- /src/lib/fn/repeat.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToStringTag} from "../internal"; 19 | 20 | /** 21 | * Creates an Iterable for a value repeated a provided number of times. 22 | * 23 | * @param value The value for each element of the Iterable. 24 | * @param count The number of times to repeat the value. 25 | * @category Query 26 | */ 27 | export function repeat(value: T, count: number): Iterable { 28 | assert.mustBePositiveFiniteNumber(count, "count"); 29 | return new RepeatIterable(value, count); 30 | } 31 | 32 | @ToStringTag("RepeatIterable") 33 | class RepeatIterable implements Iterable { 34 | private _value: T; 35 | private _count: number; 36 | 37 | constructor(value: T, count: number) { 38 | this._value = value; 39 | this._count = count; 40 | } 41 | 42 | *[Symbol.iterator](): Iterator { 43 | const value = this._value; 44 | for (let count = this._count; count > 0; --count) { 45 | yield value; 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/lib/fn/repeatAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToStringTag } from "../internal"; 19 | 20 | /** 21 | * Creates an Iterable for a value repeated a provided number of times. 22 | * 23 | * @param value The value for each element of the Iterable. 24 | * @param count The number of times to repeat the value. 25 | * @category Query 26 | */ 27 | export function repeatAsync(value: PromiseLike | T, count: number): AsyncIterable { 28 | assert.mustBePositiveFiniteNumber(count, "count"); 29 | return new AsyncRepeatIterable(value, count); 30 | } 31 | 32 | @ToStringTag("AsyncRepeatIterable") 33 | class AsyncRepeatIterable implements AsyncIterable { 34 | private _value: PromiseLike | T; 35 | private _count: number; 36 | 37 | constructor(value: PromiseLike | T, count: number) { 38 | this._value = value; 39 | this._count = count; 40 | } 41 | 42 | async *[Symbol.asyncIterator](): AsyncIterator { 43 | const value = await this._value; 44 | let count = this._count; 45 | while (count > 0) { 46 | yield value; 47 | count--; 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/lib/fn/reverse.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable, FlowHierarchy, ToStringTag} from "../internal"; 19 | import { Queryable, HierarchyIterable } from "../types"; 20 | import { toArray } from "./toArray"; 21 | 22 | /** 23 | * Creates a subquery whose elements are in the reverse order. 24 | * @category Subquery 25 | */ 26 | export function reverse(source: HierarchyIterable): HierarchyIterable; 27 | /** 28 | * Creates a subquery whose elements are in the reverse order. 29 | * @category Subquery 30 | */ 31 | export function reverse(source: Queryable): Iterable; 32 | export function reverse(source: Queryable): Iterable { 33 | assert.mustBeQueryable(source, "source"); 34 | return FlowHierarchy(new ReverseIterable(ToIterable(source)), source); 35 | } 36 | 37 | @ToStringTag("ReverseIterable") 38 | class ReverseIterable implements Iterable { 39 | private _source: Iterable; 40 | 41 | constructor(source: Iterable) { 42 | this._source = source; 43 | } 44 | 45 | *[Symbol.iterator](): Iterator { 46 | const list = toArray(this._source); 47 | list.reverse(); 48 | yield* list; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/lib/fn/reverseAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, FlowHierarchy, ToStringTag, ToPossiblyAsyncIterable } from "../internal"; 19 | import { PossiblyAsyncHierarchyIterable, AsyncHierarchyIterable, AsyncQueryable, PossiblyAsyncIterable } from "../types"; 20 | import { toArrayAsync } from "./toArrayAsync"; 21 | 22 | /** 23 | * Creates a subquery whose elements are in the reverse order. 24 | * @category Subquery 25 | */ 26 | export function reverseAsync(source: PossiblyAsyncHierarchyIterable): AsyncHierarchyIterable; 27 | /** 28 | * Creates a subquery whose elements are in the reverse order. 29 | * @category Subquery 30 | */ 31 | export function reverseAsync(source: AsyncQueryable): AsyncIterable; 32 | export function reverseAsync(source: AsyncQueryable): AsyncIterable { 33 | assert.mustBeAsyncQueryable(source, "source"); 34 | return FlowHierarchy(new AsyncReverseIterable(ToPossiblyAsyncIterable(source)), source); 35 | } 36 | 37 | @ToStringTag("AsyncReverseIterable") 38 | class AsyncReverseIterable implements AsyncIterable { 39 | private _source: PossiblyAsyncIterable; 40 | 41 | constructor(source: PossiblyAsyncIterable) { 42 | this._source = source; 43 | } 44 | 45 | async *[Symbol.asyncIterator](): AsyncIterator { 46 | const list = await toArrayAsync(this._source); 47 | list.reverse(); 48 | yield* list; 49 | } 50 | } -------------------------------------------------------------------------------- /src/lib/fn/select.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { map as select } from "./map"; -------------------------------------------------------------------------------- /src/lib/fn/selectAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { mapAsync as selectAsync } from "./mapAsync"; -------------------------------------------------------------------------------- /src/lib/fn/selectMany.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { flatMap as selectMany } from "./flatMap"; -------------------------------------------------------------------------------- /src/lib/fn/selectManyAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { flatMapAsync as selectManyAsync } from "./flatMapAsync"; -------------------------------------------------------------------------------- /src/lib/fn/single.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable } from "../internal"; 19 | import { Queryable } from "../types"; 20 | import { T } from "./common"; 21 | 22 | /** 23 | * Gets the only element, or returns `undefined`. 24 | * 25 | * @param source A [[Queryable]] object. 26 | * @param predicate An optional callback used to match each element. 27 | * @category Scalar 28 | */ 29 | export function single(source: Queryable, predicate: (element: T) => boolean = T) { 30 | assert.mustBeQueryable(source, "source"); 31 | assert.mustBeFunction(predicate, "predicate"); 32 | let hasResult = false; 33 | let result: T | undefined; 34 | for (const element of ToIterable(source)) { 35 | if (predicate(element)) { 36 | if (hasResult) { 37 | return undefined; 38 | } 39 | hasResult = true; 40 | result = element; 41 | } 42 | } 43 | return hasResult ? result : undefined; 44 | } -------------------------------------------------------------------------------- /src/lib/fn/some.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable } from "../internal"; 19 | import { Queryable } from "../types"; 20 | import { T } from "./common"; 21 | 22 | /** 23 | * Computes a scalar value indicating whether `source` contains any elements, 24 | * optionally filtering the elements using the supplied callback. 25 | * 26 | * @param source A [[Queryable]] object. 27 | * @param predicate An optional callback used to match each element. 28 | * @category Scalar 29 | */ 30 | export function some(source: Queryable, predicate: (element: T) => boolean = T): boolean { 31 | assert.mustBeQueryable(source, "source"); 32 | assert.mustBeFunction(predicate, "predicate"); 33 | for (const element of ToIterable(source)) { 34 | if (predicate(element)) { 35 | return true; 36 | } 37 | } 38 | return false; 39 | } -------------------------------------------------------------------------------- /src/lib/fn/someAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToPossiblyAsyncIterable } from "../internal"; 19 | import { AsyncQueryable } from "../types"; 20 | import { T } from "./common"; 21 | 22 | /** 23 | * Computes a scalar value indicating whether `source` contains any elements, 24 | * optionally filtering the elements using the supplied callback. 25 | * 26 | * @param source An [[AsyncQueryable]] object. 27 | * @param predicate An optional callback used to match each element. 28 | * @category Scalar 29 | */ 30 | export async function someAsync(source: AsyncQueryable, predicate: (element: T) => boolean | PromiseLike = T): Promise { 31 | assert.mustBeAsyncQueryable(source, "source"); 32 | assert.mustBeFunction(predicate, "predicate"); 33 | for await (const element of ToPossiblyAsyncIterable(source)) { 34 | const result = predicate(element); 35 | if (typeof result === "boolean" ? result : await result) { 36 | return true; 37 | } 38 | } 39 | return false; 40 | } -------------------------------------------------------------------------------- /src/lib/fn/sum.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable} from "../internal"; 19 | import { Queryable } from "../types"; 20 | import { identity } from "./common"; 21 | 22 | /** 23 | * Computes the sum for a series of numbers. 24 | * 25 | * @param source A [[Queryable]] object. 26 | * @category Scalar 27 | */ 28 | export function sum(source: Queryable): number; 29 | /** 30 | * Computes the sum for a series of numbers. 31 | * 32 | * @param source A [[Queryable]] object. 33 | * @param elementSelector A callback used to convert a value in `source` to a number. 34 | * @category Scalar 35 | */ 36 | export function sum(source: Queryable, elementSelector: (element: T) => number): number; 37 | export function sum(source: Queryable, elementSelector: (element: number) => number = identity): number { 38 | assert.mustBeQueryable(source, "source"); 39 | assert.mustBeFunction(elementSelector, "elementSelector"); 40 | let sum = 0; 41 | for (const value of ToIterable(source)) { 42 | const result = elementSelector(value); 43 | if (typeof result !== "number") throw new TypeError(); 44 | sum += result; 45 | } 46 | return sum; 47 | } -------------------------------------------------------------------------------- /src/lib/fn/sumAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToPossiblyAsyncIterable } from "../internal"; 19 | import { AsyncQueryable } from "../types"; 20 | import { identity } from "./common"; 21 | 22 | /** 23 | * Computes the sum for a series of numbers. 24 | * NOTE: If any element is not a `number`, this overload will throw. 25 | * 26 | * @param source An [[AsyncQueryable]] object. 27 | * @category Scalar 28 | */ 29 | export async function sumAsync(source: AsyncQueryable): Promise; 30 | /** 31 | * Computes the sum for a series of numbers. 32 | * 33 | * @param source An [[AsyncQueryable]] object. 34 | * @param elementSelector A callback used to convert a value in `source` to a number. 35 | * @category Scalar 36 | */ 37 | export async function sumAsync(source: AsyncQueryable, elementSelector: (element: T) => number | PromiseLike): Promise; 38 | export async function sumAsync(source: AsyncQueryable, elementSelector: (element: number) => number | PromiseLike = identity): Promise { 39 | assert.mustBeAsyncQueryable(source, "source"); 40 | assert.mustBeFunction(elementSelector, "elementSelector"); 41 | let sum = 0; 42 | for await (const element of ToPossiblyAsyncIterable(source)) { 43 | const value = elementSelector(element); 44 | const result = typeof value === "number" ? value : await value; 45 | assert.mustBeNumber(result); 46 | sum += result; 47 | } 48 | return sum; 49 | } -------------------------------------------------------------------------------- /src/lib/fn/through.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert } from "../internal"; 19 | import { Queryable } from "../types"; 20 | 21 | /** 22 | * Pass the entire source to the provided callback, returning a [[Queryable]] from the result. 23 | * 24 | * @param source A [[Queryable]] object. 25 | * @param callback A callback function. 26 | * @category Subquery 27 | */ 28 | export function through = Queryable, R extends Queryable = Queryable>(source: S, callback: (source: S) => R): R { 29 | assert.mustBeQueryable(source, "source"); 30 | assert.mustBeFunction(callback, "callback"); 31 | const result = callback(source); 32 | assert.mustBeQueryable(result); 33 | return result; 34 | } -------------------------------------------------------------------------------- /src/lib/fn/throughAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert } from "../internal"; 19 | import { AsyncQueryable } from "../types"; 20 | 21 | /** 22 | * Pass the entire source to the provided callback, returning an [[AsyncQueryable]] from the result. 23 | * 24 | * @param source An [[AsyncQueryable]] object. 25 | * @param callback A callback function. 26 | * @category Subquery 27 | */ 28 | export function throughAsync = AsyncQueryable, R extends AsyncQueryable = AsyncQueryable>(source: S, callback: (source: S) => R): R { 29 | assert.mustBeAsyncQueryable(source, "source"); 30 | assert.mustBeFunction(callback, "callback"); 31 | const result = callback(source); 32 | assert.mustBeAsyncQueryable(result); 33 | return result; 34 | } -------------------------------------------------------------------------------- /src/lib/fn/toArray.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToIterable} from "../internal"; 19 | import { Queryable } from "../types"; 20 | import { identity } from "./common"; 21 | 22 | /** 23 | * Creates an Array for the elements of the [[Queryable]]. 24 | * 25 | * @param source A [[Queryable]] object. 26 | * @category Scalar 27 | */ 28 | export function toArray(source: Queryable): T[]; 29 | /** 30 | * Creates an Array for the elements of the [[Queryable]]. 31 | * 32 | * @param source A [[Queryable]] object. 33 | * @param elementSelector A callback that selects a value for each element. 34 | * @category Scalar 35 | */ 36 | export function toArray(source: Queryable, elementSelector: (element: T) => V): V[]; 37 | export function toArray(source: Queryable, elementSelector: (element: T) => T = identity): T[] { 38 | assert.mustBeQueryable(source, "source"); 39 | assert.mustBeFunction(elementSelector, "elementSelector"); 40 | const result: T[] = []; 41 | for (const element of ToIterable(source)) { 42 | result.push(elementSelector(element)); 43 | } 44 | return result; 45 | } 46 | ;; -------------------------------------------------------------------------------- /src/lib/fn/toArrayAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, ToPossiblyAsyncIterable } from "../internal"; 19 | import { AsyncQueryable } from "../types"; 20 | import { identity } from "./common"; 21 | 22 | /** 23 | * Creates an Array for the elements of the [[AsyncIterable]]. 24 | * 25 | * @param source An [[AsyncQueryable]] object. 26 | * @category Scalar 27 | */ 28 | export async function toArrayAsync(source: AsyncQueryable): Promise; 29 | /** 30 | * Creates an Array for the elements of the [[AsyncIterable]]. 31 | * 32 | * @param source An [[AsyncQueryable]] object. 33 | * @param elementSelector A callback that selects a value for each element. 34 | * @category Scalar 35 | */ 36 | export async function toArrayAsync(source: AsyncQueryable, elementSelector: (element: T) => V | PromiseLike): Promise; 37 | export async function toArrayAsync(source: AsyncQueryable, elementSelector: (element: T) => T | PromiseLike = identity): Promise { 38 | assert.mustBeAsyncQueryable(source, "source"); 39 | assert.mustBeFunction(elementSelector, "elementSelector"); 40 | const result: T[] = []; 41 | for await (const item of ToPossiblyAsyncIterable(source)) { 42 | result.push(elementSelector === identity ? item : await elementSelector(item)); 43 | } 44 | return result; 45 | } -------------------------------------------------------------------------------- /src/lib/fn/toHierarchy.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, MakeHierarchyIterable} from "../internal"; 19 | import { Queryable, HierarchyIterable, HierarchyProvider, OrderedIterable, OrderedHierarchyIterable } from "../types"; 20 | 21 | /** 22 | * Creates a [[HierarchyIterable]] using the provided `HierarchyProvider`. 23 | * 24 | * @param source A [[Queryable]] object. 25 | * @param hierarchy A `HierarchyProvider`. 26 | * @category Hierarchy 27 | */ 28 | export function toHierarchy(source: OrderedIterable, hierarchy: HierarchyProvider): OrderedHierarchyIterable; 29 | /** 30 | * Creates a [[HierarchyIterable]] using the provided `HierarchyProvider`. 31 | * 32 | * @param source A [[Queryable]] object. 33 | * @param hierarchy A `HierarchyProvider`. 34 | * @category Hierarchy 35 | */ 36 | export function toHierarchy(source: Queryable, hierarchy: HierarchyProvider): HierarchyIterable; 37 | export function toHierarchy(source: Queryable, hierarchy: HierarchyProvider): HierarchyIterable { 38 | assert.mustBeQueryable(source, "source"); 39 | assert.mustBeHierarchyProvider(hierarchy, "hierarchy"); 40 | return MakeHierarchyIterable(source, hierarchy); 41 | } 42 | -------------------------------------------------------------------------------- /src/lib/fn/toHierarchyAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { assert, MakeAsyncHierarchyIterable } from "../internal"; 19 | import { HierarchyProvider, AsyncHierarchyIterable, AsyncOrderedHierarchyIterable, PossiblyAsyncOrderedIterable, AsyncQueryable } from "../types"; 20 | 21 | /** 22 | * Creates an [[AsyncHierarchyIterable]] using the provided `HierarchyProvider`. 23 | * 24 | * @param source An [[AsyncQueryable]] object. 25 | * @param hierarchy A `HierarchyProvider`. 26 | * @category Hierarchy 27 | */ 28 | export function toHierarchyAsync(source: PossiblyAsyncOrderedIterable, hierarchy: HierarchyProvider): AsyncOrderedHierarchyIterable; 29 | /** 30 | * Creates an [[AsyncHierarchyIterable]] using the provided `HierarchyProvider`. 31 | * 32 | * @param source An [[AsyncQueryable]] object. 33 | * @param hierarchy A `HierarchyProvider`. 34 | * @category Hierarchy 35 | */ 36 | export function toHierarchyAsync(source: AsyncQueryable, hierarchy: HierarchyProvider): AsyncHierarchyIterable; 37 | export function toHierarchyAsync(source: AsyncQueryable, hierarchy: HierarchyProvider): AsyncHierarchyIterable { 38 | assert.mustBeAsyncQueryable(source, "source"); 39 | assert.mustBeHierarchyProvider(hierarchy, "hierarchy"); 40 | return MakeAsyncHierarchyIterable(source, hierarchy); 41 | } -------------------------------------------------------------------------------- /src/lib/fn/unzip.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { Queryable } from "../types"; 19 | import { ToIterable } from "../internal"; 20 | import { identity } from "./common"; 21 | 22 | /** 23 | * Unzips a sequence of tuples into a tuple of sequences. 24 | * @param source A [[Queryable]] 25 | * @category Scalar 26 | */ 27 | export function unzip(source: Queryable): { [I in keyof T]: T[I][]; }; 28 | /** 29 | * Unzips a sequence of tuples into a tuple of sequences. 30 | * @param source A [[Queryable]] 31 | * @param partSelector A callback that converts a result into a tuple. 32 | * @category Scalar 33 | */ 34 | export function unzip(source: Queryable, partSelector: (value: T) => U): { [I in keyof U]: U[I][]; }; 35 | export function unzip(source: Queryable, partSelector: (value: T) => T = identity): any { 36 | const result: any[][] = []; 37 | let length = -1; 38 | for (const element of ToIterable(source)) { 39 | const row = partSelector(element); 40 | if (length === -1) { 41 | length = row.length; 42 | for (let i = 0; i < length; i++) { 43 | result.push([]); 44 | } 45 | } 46 | for (let i = 0; i < length; i++) { 47 | result[i].push(row[i]); 48 | } 49 | } 50 | return result; 51 | } -------------------------------------------------------------------------------- /src/lib/fn/unzipAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | import { AsyncQueryable } from "../types"; 19 | import { ToPossiblyAsyncIterable } from "../internal"; 20 | import { identity } from "./common"; 21 | 22 | /** 23 | * Unzips a sequence of tuples into a tuple of sequences. 24 | * @param source An [[AsyncQueryable]] 25 | * @category Scalar 26 | */ 27 | export async function unzipAsync(source: AsyncQueryable): Promise<{ [I in keyof T]: T[I][]; }>; 28 | /** 29 | * Unzips a sequence of tuples into a tuple of sequences. 30 | * @param source An [[AsyncQueryable]] 31 | * @param partSelector A callback that converts a result into a tuple. 32 | * @category Scalar 33 | */ 34 | export async function unzipAsync(source: AsyncQueryable, partSelector: (value: T) => U | PromiseLike): Promise<{ [I in keyof U]: U[I][]; }> 35 | export async function unzipAsync(source: AsyncQueryable, partSelector: (value: T) => T | PromiseLike = identity): Promise { 36 | const result: any[][] = []; 37 | let length = -1; 38 | for await (const element of ToPossiblyAsyncIterable(source)) { 39 | const row = await partSelector(element); 40 | if (length === -1) { 41 | length = row.length; 42 | for (let i = 0; i < length; i++) { 43 | result.push([]); 44 | } 45 | } 46 | for (let i = 0; i < length; i++) { 47 | result[i].push(row[i]); 48 | } 49 | } 50 | return result; 51 | } -------------------------------------------------------------------------------- /src/lib/fn/where.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { filter as where } from "./filter"; -------------------------------------------------------------------------------- /src/lib/fn/whereAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { filterAsync as whereAsync } from "./filterAsync"; -------------------------------------------------------------------------------- /src/lib/fn/whereBy.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { filterBy as whereBy } from "./filterBy"; -------------------------------------------------------------------------------- /src/lib/fn/whereByAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { filterByAsync as whereByAsync } from "./filterByAsync"; -------------------------------------------------------------------------------- /src/lib/fn/whereDefined.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { filterDefined as whereDefined } from "./filterDefined"; -------------------------------------------------------------------------------- /src/lib/fn/whereDefinedAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { filterDefinedAsync as whereDefinedAsync } from "./filterDefinedAsync"; -------------------------------------------------------------------------------- /src/lib/fn/xor.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { symmetricDifference as xor } from "./symmetricDifference"; -------------------------------------------------------------------------------- /src/lib/fn/xorAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { symmetricDifferenceAsync as xorAsync } from "./symmetricDifferenceAsync"; -------------------------------------------------------------------------------- /src/lib/fn/xorBy.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { symmetricDifferenceBy as xorBy } from "./symmetricDifferenceBy"; -------------------------------------------------------------------------------- /src/lib/fn/xorByAsync.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** @module "iterable-query/fn" */ 17 | 18 | export { symmetricDifferenceByAsync as xorByAsync } from "./symmetricDifferenceByAsync"; -------------------------------------------------------------------------------- /src/lib/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | /** 17 | * @module "iterable-query" 18 | * @preferred 19 | */ 20 | 21 | export * from "./types"; 22 | export * from "./query"; 23 | export * from "./asyncQuery"; 24 | export * from "./lookup"; 25 | export * from "./lazy"; 26 | export * from "./collections"; 27 | import * as fn from "./fn"; 28 | export { fn }; -------------------------------------------------------------------------------- /src/lib/internal/debug.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | interface ErrorConstructorWithStackTraceApi extends ErrorConstructor { 18 | captureStackTrace(target: any, stackCrawlMark?: Function): void; 19 | } 20 | 21 | declare const Error: ErrorConstructorWithStackTraceApi; 22 | 23 | /** @internal */ 24 | export function captureStackTrace(error: any, stackCrawlMark?: Function) { 25 | if (typeof error === "object" && error !== null && Error.captureStackTrace) { 26 | Error.captureStackTrace(error, stackCrawlMark || captureStackTrace); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/lib/internal/decorators.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /** @internal */ 18 | import "../compat"; 19 | 20 | /** @internal */ 21 | export function ToStringTag(tag: string) { 22 | return (ctor: T) => { 23 | Object.defineProperty(ctor.prototype, Symbol.toStringTag, { configurable: true, value: tag }); 24 | return ctor; 25 | }; 26 | } 27 | 28 | /** @internal */ 29 | export function ClassName(name: string) { 30 | return (ctor: T) => { 31 | Object.defineProperty(ctor, "name", { value: name, writable: false, enumerable: false, configurable: true }); 32 | return ctor; 33 | }; 34 | } -------------------------------------------------------------------------------- /src/lib/internal/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | /** @internal */ 18 | export * from "./decorators"; 19 | /** @internal */ 20 | export * from "./conversion"; 21 | /** @internal */ 22 | export * from "./flow"; 23 | /** @internal */ 24 | export * from "./guards"; 25 | /** @internal */ 26 | export * from "./utils"; 27 | /** @internal */ 28 | export * from "./types"; 29 | /** @internal */ 30 | import * as assert from "./assert"; 31 | /** @internal */ 32 | import * as Debug from "./debug"; 33 | /** @internal */ 34 | export { assert, Debug }; 35 | -------------------------------------------------------------------------------- /src/lib/internal/types.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | Copyright 2018 Ron Buckton (rbuckton@chronicles.org) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { Queryable, AsyncQueryable } from "../types"; 18 | 19 | // Queries 20 | 21 | /** @internal */ 22 | export namespace QuerySource { 23 | export const source = Symbol("QuerySource.source"); 24 | } 25 | 26 | /** @internal */ 27 | export interface QuerySource extends Iterable { 28 | [QuerySource.source](): Queryable; 29 | } 30 | 31 | /** @internal */ 32 | export namespace AsyncQuerySource { 33 | export const source = Symbol("AsyncQuerySource.source"); 34 | } 35 | 36 | /** @internal */ 37 | export interface AsyncQuerySource extends AsyncIterable { 38 | [AsyncQuerySource.source](): AsyncQueryable; 39 | } -------------------------------------------------------------------------------- /src/lib/tsconfig.es2015.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "target": "es2015", 5 | "lib": ["es2015"], 6 | "outDir": "../../dist/es2015" 7 | } 8 | } -------------------------------------------------------------------------------- /src/lib/tsconfig.es5.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "target": "es5", 5 | "lib": ["es2015"], 6 | "outDir": "../../dist/es5", 7 | "downlevelIteration": true 8 | } 9 | } -------------------------------------------------------------------------------- /src/lib/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2017", 4 | "module": "commonjs", 5 | "lib": ["esnext"], 6 | "outDir": "../../dist/lib", 7 | "experimentalDecorators": true, 8 | "importHelpers": true, 9 | "noEmitOnError": true, 10 | "noImplicitAny": true, 11 | "sourceMap": true, 12 | "stripInternal": true, 13 | "declaration": true, 14 | "declarationMap": true, 15 | "skipLibCheck": true, 16 | "strict": true, 17 | "composite": true, 18 | "noUnusedLocals": true, 19 | "preserveConstEnums": true, 20 | // "noUnusedParameters": true 21 | }, 22 | "include": [ 23 | "**/*.ts" 24 | ] 25 | } -------------------------------------------------------------------------------- /src/lib/tsconfig.typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2017", 4 | "module": "commonjs", 5 | "lib": ["esnext"], 6 | "outDir": "../../dist/lib", 7 | "experimentalDecorators": true, 8 | "noEmitOnError": true, 9 | "noEmit": true, 10 | "noImplicitAny": true, 11 | "sourceMap": true, 12 | "stripInternal": true, 13 | "skipLibCheck": true, 14 | "strict": true, 15 | "noUnusedLocals": true 16 | }, 17 | "include": [ 18 | "**/*.ts" 19 | ] 20 | } -------------------------------------------------------------------------------- /src/tests/data/books.ts: -------------------------------------------------------------------------------- 1 | export interface Book { title: string; id: number } 2 | export const bookA3 = { title: "A", id: 3 }; 3 | export const bookA4 = { title: "A", id: 4 }; 4 | export const bookB1 = { title: "B", id: 1 }; 5 | export const bookB2 = { title: "B", id: 2 }; 6 | export const bookB2_same = { title: "B", id: 2 }; 7 | export const books = [bookA4, bookB2, bookB1, bookA3]; 8 | export const books_same = [bookB2, bookB2_same]; 9 | export const bookHierarchy = { 10 | owns(_: Book) { return true; }, 11 | parent(): Book { return undefined; }, 12 | children(): Book[] { return undefined; } 13 | }; -------------------------------------------------------------------------------- /src/tests/data/nodes.ts: -------------------------------------------------------------------------------- 1 | import { HierarchyProvider } from "../../lib"; 2 | 3 | export interface Node { 4 | name: string; 5 | parent?: Node; 6 | children?: Node[]; 7 | toJSON?: () => any; 8 | marker?: boolean; 9 | } 10 | 11 | function makeTree(node: Node, parent?: Node) { 12 | node.toJSON = () => node.name; 13 | node.parent = parent; 14 | if (node.children) { 15 | for (const child of node.children) { 16 | if (child) makeTree(child, node); 17 | } 18 | } 19 | 20 | return node; 21 | } 22 | 23 | export const nodeAAAA: Node = { name: "AAAA" } 24 | export const nodeAAA: Node = { name: "AAA", children: [nodeAAAA] }; 25 | export const nodeAAB: Node = { name: "AAB", marker: true }; 26 | export const nodeAAC: Node = { name: "AAC" }; 27 | export const nodeAA: Node = { name: "AA", children: [nodeAAA, nodeAAB, nodeAAC] }; 28 | export const nodeAB: Node = { name: "AB" }; 29 | export const nodeACA: Node = { name: "ACA" }; 30 | export const nodeAC: Node = { name: "AC", children: [nodeACA] }; 31 | export const nodeA: Node = { name: "A", children: [nodeAA, nodeAB, nodeAC] }; 32 | makeTree(nodeA); 33 | 34 | export const badNode: Node = { name: "bad", children: [undefined!] }; 35 | 36 | export const nodeHierarchy: HierarchyProvider = { 37 | owns(_: Node) { 38 | return true; 39 | }, 40 | parent(node: Node) { 41 | return node.parent; 42 | }, 43 | children(node: Node) { 44 | return node.children || []; 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /src/tests/data/numbers.ts: -------------------------------------------------------------------------------- 1 | import { HierarchyProvider } from "../../lib"; 2 | 3 | export const numberHierarchy: HierarchyProvider = { 4 | owns(_: number) { return true; }, 5 | parent(): number { return undefined; }, 6 | children(): number[] { return undefined; } 7 | }; -------------------------------------------------------------------------------- /src/tests/data/users.ts: -------------------------------------------------------------------------------- 1 | export interface User { name: string, role: string } 2 | export interface Role { name: string } 3 | 4 | export const aliceUser: User = { name: "alice", role: "admin" }; 5 | export const bobUser: User = { name: "bob", role: "user" }; 6 | export const daveUser: User = { name: "dave", role: "user" }; 7 | export const users: User[] = [aliceUser, bobUser, daveUser]; 8 | 9 | export const adminRole: Role = { name: "admin" }; 10 | export const userRole: Role = { name: "user" }; 11 | export const guestRole: Role = { name: "guest" }; 12 | export const roles: Role[] = [adminRole, userRole, guestRole]; 13 | -------------------------------------------------------------------------------- /src/tests/lazy.ts: -------------------------------------------------------------------------------- 1 | import { Lazy } from "../lib"; 2 | import { expect } from "chai"; 3 | 4 | describe("Lazy", () => { 5 | describe("from()", () => { 6 | it("eval only once", () => { 7 | let counter = 0; 8 | const lazy = Lazy.from(() => counter++); 9 | expect(counter).to.equal(0); 10 | expect(lazy.hasValue).to.be.false; 11 | expect(lazy.value).to.equal(0); 12 | expect(lazy.hasValue).to.be.true; 13 | expect(counter).to.equal(1); 14 | expect(lazy.value).to.equal(0); 15 | expect(counter).to.equal(1); 16 | }); 17 | it("throws if recursive", () => { 18 | const lazy: Lazy = Lazy.from(() => lazy.value); 19 | expect(lazy.hasValue).to.be.false; 20 | expect(() => lazy.value).to.throw(); 21 | expect(lazy.hasValue).to.be.false; 22 | }); 23 | }); 24 | describe("for()", () => { 25 | it("is value", () => { 26 | const lazy = Lazy.for(0); 27 | expect(lazy.hasValue).to.be.true; 28 | expect(lazy.value).to.equal(0); 29 | }) 30 | }); 31 | }); -------------------------------------------------------------------------------- /src/tests/lookup.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { Lookup, from } from "../lib"; 3 | 4 | describe("lookup", () => { 5 | it("constructor()", () => { 6 | const lookup = new Lookup([["a", [1, 2]], ["b", [3, 4]]]); 7 | expect(lookup.size).to.equal(2); 8 | }); 9 | it("has()", () => { 10 | const lookup = new Lookup([["a", [1, 2]], ["b", [3, 4]]]); 11 | expect(lookup.has("a")).to.be.true; 12 | expect(lookup.has("c")).to.be.false; 13 | }); 14 | it("get()", () => { 15 | const lookup = new Lookup([["a", [1, 2]], ["b", [3, 4]]]); 16 | expect(lookup.get("a")).to.equalSequence([1, 2]); 17 | }); 18 | it("applyResultSelector()", () => { 19 | const lookup = new Lookup([["a", [1, 2]], ["b", [3, 4]]]); 20 | expect([...lookup.applyResultSelector((key, values) => [key, ...from(values)])]).to.deep.equal([["a", 1, 2], ["b", 3, 4]]); 21 | }); 22 | }); -------------------------------------------------------------------------------- /src/tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015", 4 | "lib": ["esnext"], 5 | "module": "commonjs", 6 | "outDir": "../../dist/tests", 7 | "noImplicitAny": true, 8 | "noEmitOnError": true, 9 | "sourceMap": true, 10 | "stripInternal": true, 11 | "declaration": true, 12 | "experimentalDecorators": true, 13 | "rootDirs": ["../es5", "../es2015", "../lib"] 14 | }, 15 | "references": [ 16 | { "path": "../lib/tsconfig.json" }, 17 | { "path": "../lib/tsconfig.es5.json" }, 18 | { "path": "../lib/tsconfig.es2015.json" }, 19 | ], 20 | "include": [ 21 | "**/*.ts" 22 | ] 23 | } -------------------------------------------------------------------------------- /src/typedoc/plugin/index.ts: -------------------------------------------------------------------------------- 1 | import "source-map-support/register"; 2 | import { PluginHost } from "typedoc/dist/lib/utils"; 3 | import { ExportDeclarationConverter } from "./nodes/exportDeclaration"; 4 | import { ReflectionEventsPlugin } from "./plugins/reflectionEvents"; 5 | import { ExcludeEmptyPlugin } from "./plugins/excludeEmpty"; 6 | import { StripInternalPlugin } from "./plugins/stripInternal"; 7 | import { ExportsPlugin } from "./plugins/exports"; 8 | import { UncategorizedPlugin } from "./plugins/uncategorized"; 9 | import { GroupCategoriesPlugin } from "./plugins/groupCategories"; 10 | import { MergePlugin } from "./plugins/merge"; 11 | import { NamingPlugin } from "./plugins/naming"; 12 | import { BiblioPlugin } from "./plugins/biblio"; 13 | import { NoJekyllPlugin } from "./plugins/noJekyll"; 14 | 15 | function load(host: PluginHost) { 16 | const app = host.owner; 17 | app.converter.addComponent("reflectionEvents", ReflectionEventsPlugin); 18 | app.converter.addComponent("excludeEmpty", ExcludeEmptyPlugin); 19 | app.converter.addComponent("stripInternal", StripInternalPlugin); 20 | app.converter.addComponent("exports", ExportsPlugin); 21 | app.converter.addComponent("uncategorized", UncategorizedPlugin); 22 | app.converter.addComponent("groupCategories", GroupCategoriesPlugin); 23 | app.converter.addComponent("merge", MergePlugin); 24 | app.converter.addComponent("naming", NamingPlugin); 25 | app.converter.addComponent("biblio", BiblioPlugin); 26 | app.converter.addComponent("node:exportDeclaration", ExportDeclarationConverter); 27 | app.renderer.addComponent("no-jekyll", NoJekyllPlugin); 28 | } 29 | 30 | export = load; -------------------------------------------------------------------------------- /src/typedoc/plugin/model/exportBinding.ts: -------------------------------------------------------------------------------- 1 | import { Reflection, DeclarationReflection } from "typedoc"; 2 | 3 | export class ExportBinding { 4 | name: string; 5 | symbolID?: number; 6 | reflection?: Reflection; 7 | isExportStar?: boolean; 8 | 9 | constructor(name: string, symbolID?: number, reflection?: Reflection) { 10 | this.name = name; 11 | this.symbolID = symbolID; 12 | this.reflection = reflection; 13 | } 14 | 15 | toObject() { 16 | const result = {} as any; 17 | result.name = this.name; 18 | if (this.reflection) result.id = this.reflection.id; 19 | return result; 20 | } 21 | 22 | toString() { 23 | return this.reflection ? this.reflection.name : this.name; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/typedoc/plugin/plugins/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./reflectionEvents"; 2 | export * from "./excludeEmpty"; 3 | export * from "./stripInternal"; 4 | export * from "./exports"; 5 | export * from "./uncategorized"; 6 | export * from "./groupCategories"; 7 | export * from "./merge"; 8 | export * from "./naming"; -------------------------------------------------------------------------------- /src/typedoc/plugin/plugins/noJekyll.ts: -------------------------------------------------------------------------------- 1 | import * as fs from "fs"; 2 | import * as path from "path"; 3 | import { RendererComponent, Component } from "typedoc/dist/lib/output/components"; 4 | import { Option, writeFile } from "typedoc/dist/lib/utils"; 5 | import { ParameterType } from "typedoc/dist/lib/utils/options/declaration"; 6 | import { ComponentHost } from "typedoc/dist/lib/utils/component"; 7 | import { Renderer } from "typedoc"; 8 | import { RendererEvent } from "typedoc/dist/lib/output/events"; 9 | 10 | @Component({ 11 | name: "no-jekyll", 12 | }) 13 | export class NoJekyllPlugin extends RendererComponent { 14 | @Option({ 15 | name: "noJekyll", 16 | help: "Generates a .nojekyll file as part of the output", 17 | type: ParameterType.Boolean 18 | }) 19 | noJekyll!: boolean; 20 | 21 | constructor(owner: ComponentHost) { 22 | if (!(owner instanceof Renderer)) throw new TypeError(); 23 | super(owner); 24 | } 25 | 26 | initialize() { 27 | super.initialize(); 28 | this.listenTo(this.owner, RendererEvent.END, this.onEnd); 29 | } 30 | 31 | private onEnd(event: RendererEvent) { 32 | if (this.noJekyll) { 33 | const filename = path.resolve(event.outputDirectory, ".nojekyll"); 34 | try { 35 | writeFile(filename, "", /*writeByteOrderMark*/ false); 36 | } 37 | catch (e) { 38 | this.application.logger.error("Could not write file %s", filename); 39 | } 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /src/typedoc/plugin/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015", 4 | "lib": ["esnext"], 5 | "module": "commonjs", 6 | "outDir": "../../../dist/typedoc/plugin", 7 | "experimentalDecorators": true, 8 | "strict": true, 9 | "noEmitOnError": true, 10 | "sourceMap": true, 11 | "stripInternal": true, 12 | "declaration": true, 13 | "declarationMap": true, 14 | "composite": true, 15 | "allowSyntheticDefaultImports": true, 16 | "esModuleInterop": true 17 | }, 18 | "include": [ 19 | "**/*.ts" 20 | ] 21 | } -------------------------------------------------------------------------------- /src/typedoc/theme/assets/images/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rbuckton/iterable-query/d3d1aadcc33bb184aff98759ca50cbae3943f81d/src/typedoc/theme/assets/images/icons.png -------------------------------------------------------------------------------- /src/typedoc/theme/assets/images/icons@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rbuckton/iterable-query/d3d1aadcc33bb184aff98759ca50cbae3943f81d/src/typedoc/theme/assets/images/icons@2x.png -------------------------------------------------------------------------------- /src/typedoc/theme/assets/images/widgets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rbuckton/iterable-query/d3d1aadcc33bb184aff98759ca50cbae3943f81d/src/typedoc/theme/assets/images/widgets.png -------------------------------------------------------------------------------- /src/typedoc/theme/assets/images/widgets@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rbuckton/iterable-query/d3d1aadcc33bb184aff98759ca50cbae3943f81d/src/typedoc/theme/assets/images/widgets@2x.png -------------------------------------------------------------------------------- /src/typedoc/theme/helpers/ifTest.js: -------------------------------------------------------------------------------- 1 | const { Reflection, ReflectionKind } = require("typedoc/dist/lib/models"); 2 | 3 | exports.ifTest = function (v1, operator, v2, options) { 4 | return cond(v1, operator, v2) ? options.fn(this) : options.inverse(this); 5 | }; 6 | 7 | const regExpPattern = /^\/(.*)\/([a-zA-Z]*)/; 8 | 9 | function cond(v1, operator, v2) { 10 | switch (operator.toLowerCase()) { 11 | default: return false; 12 | case "==": return v1 == v2; 13 | case "===": return v1 === v2; 14 | case "!=": return v1 != v2; 15 | case "!==": return v1 !== v2; 16 | case "<": return v1 < v2; 17 | case "<=": return v1 <= v2; 18 | case ">": return v1 > v2; 19 | case ">=": return v1 >= v2; 20 | case "&&": return v1 && v2; 21 | case "||": return v1 || v2; 22 | case "in": return v1 in v2; 23 | case "typeof": return typeof v1 === v2; 24 | case "includes": 25 | return Array.isArray(v1) || typeof v1 === "string" ? v1.includes(v2) : 26 | v1 instanceof Set || v1 instanceof Map ? v1.has(v2) : 27 | v1 === v2; 28 | case "startswith": 29 | return Array.isArray(v1) ? v1.length > 0 && v1[0] === v2 : 30 | typeof v1 === "string" ? v1.startsWith(v2) : 31 | v1 === v2; 32 | case "endswith": 33 | return Array.isArray(v1) ? v1.length > 0 && v1[v1.length - 1] === v2 : 34 | typeof v1 === "string" ? v1.endsWith(v2) : 35 | v1 === v2; 36 | case "matches": 37 | if (v2 instanceof RegExp) return v2.test(v1); 38 | const str = String(v2); 39 | const match = regExpPattern.match(str); 40 | const re = match ? new RegExp(match[1], match[2]) : new RegExp(str); 41 | return re.test(v1); 42 | case "kindof": 43 | if (!(v1 instanceof Reflection)) return false; 44 | if (typeof v2 === "number") return v1.kindOf(v2); 45 | if (typeof v2 !== "string") return false; 46 | const array = v2.split(",").map(k => ReflectionKind[k.trim()]).filter(k => typeof k === "number"); 47 | return array.length > 0 && v1.kindOf(array); 48 | } 49 | } -------------------------------------------------------------------------------- /src/typedoc/theme/layouts/default.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {{#ifCond model.name '==' project.name}}{{project.name}}{{else}}{{model.name}} | {{project.name}}{{/ifCond}} 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | {{> header}} 15 | 16 |
17 |
18 |
19 | {{{contents}}} 20 |
21 | 38 |
39 |
40 | 41 | {{> footer}} 42 | 43 |
44 | 45 | 46 | 47 | {{> analytics}} 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/typedoc/theme/partials/analytics.hbs: -------------------------------------------------------------------------------- 1 | {{#if settings.gaID}} 2 | 11 | {{/if}} -------------------------------------------------------------------------------- /src/typedoc/theme/partials/breadcrumb.hbs: -------------------------------------------------------------------------------- 1 | {{#if parent}} 2 | {{#with parent}}{{> breadcrumb}}{{/with}} 3 |
  • 4 | {{#if url}} 5 | {{name}} 6 | {{else}} 7 | {{name}} 8 | {{/if}} 9 |
  • 10 | {{else}} 11 | {{#if url}} 12 |
  • 13 | Globals 14 |
  • 15 | {{/if}} 16 | {{/if}} -------------------------------------------------------------------------------- /src/typedoc/theme/partials/comment.hbs: -------------------------------------------------------------------------------- 1 | {{#with comment}} 2 | {{#if hasVisibleComponent}} 3 |
    4 | {{#if shortText}} 5 |
    6 | {{#markdown}}{{{shortText}}}{{/markdown}} 7 |
    8 | {{/if}} 9 | {{#if text}} 10 | {{#markdown}}{{{text}}}{{/markdown}} 11 | {{/if}} 12 | {{#if tags}} 13 |
    14 | {{#each tags}} 15 |
    {{tagName}}
    16 |
    {{#markdown}}{{{text}}}{{/markdown}}
    17 | {{/each}} 18 |
    19 | {{/if}} 20 |
    21 | {{/if}} 22 | {{/with}} -------------------------------------------------------------------------------- /src/typedoc/theme/partials/comment.inline.hbs: -------------------------------------------------------------------------------- 1 | {{#with comment}} 2 | {{#if hasVisibleComponent}} 3 | — 4 |
    5 | {{#if shortText}} 6 |
    7 | {{#markdown}}{{{shortText}}}{{/markdown}} 8 |
    9 | {{/if}} 10 | {{#if text}} 11 | {{#markdown}}{{{text}}}{{/markdown}} 12 | {{/if}} 13 | {{#if tags}} 14 |
    15 | {{#each tags}} 16 |
    {{tagName}}
    17 |
    {{#markdown}}{{{text}}}{{/markdown}}
    18 | {{/each}} 19 |
    20 | {{/if}} 21 |
    22 | {{/if}} 23 | {{/with}} -------------------------------------------------------------------------------- /src/typedoc/theme/partials/exportBinding.hbs: -------------------------------------------------------------------------------- 1 | {{#compact}} 2 | {{#if reflection}} 3 | {{#ifTest reflection.parent '!==' ../parent}} 4 | {{#if isExportStar}} 5 | {{#if showStar}}* from {{/if}} 6 | {{#if reflection.url}} 7 | {{reflection.name}} 8 | {{else}} 9 | {{reflection.name}} 10 | {{/if}} 11 | {{else}} 12 | {{#if reflection.url}} 13 | {{reflection.name}} 14 | {{else}} 15 | {{reflection.name}} 16 | {{/if}} 17 |  from  18 | {{#if reflection.parent.url}} 19 | {{reflection.parent.name}} 20 | {{else}} 21 | {{reflection.parent.name}} 22 | {{/if}} 23 | {{/if}} 24 | {{else}} 25 | {{#if reflection.url}} 26 | {{reflection.name}} 27 | {{else}} 28 | {{reflection.name}} 29 | {{/if}} 30 | {{/ifTest}} 31 | {{else}} 32 | {{this}} 33 | {{/if}} 34 | {{/compact}} -------------------------------------------------------------------------------- /src/typedoc/theme/partials/hierarchy.hbs: -------------------------------------------------------------------------------- 1 |
      2 | {{#each types}} 3 |
    • 4 | {{#if ../isTarget}} 5 | {{this}} 6 | {{else}} 7 | {{> type}} 8 | {{/if}} 9 | 10 | {{#if @last}} 11 | {{#with ../next}} 12 | {{> hierarchy}} 13 | {{/with}} 14 | {{/if}} 15 |
    • 16 | {{/each}} 17 |
    18 | -------------------------------------------------------------------------------- /src/typedoc/theme/partials/index.hbs: -------------------------------------------------------------------------------- 1 | {{#if groups}} 2 |
    3 |

    Index

    4 |
    5 |
    6 | {{#each groups}} 7 |
    8 | {{#if categories}} 9 | {{#each categories}} 10 |

    {{../title}}{{#if title}} ({{title}}){{/if}}

    11 | 16 | {{/each}} 17 | {{else}} 18 |

    {{title}}

    19 | 24 | {{/if}} 25 |
    26 | {{/each}} 27 |
    28 |
    29 |
    30 | {{/if}} -------------------------------------------------------------------------------- /src/typedoc/theme/partials/member.declaration.hbs: -------------------------------------------------------------------------------- 1 |
    {{#compact}} 2 | {{{wbr name}}}{{#if isOptional}}?{{/if}}: {{#with type}}{{>type}}{{/with}} 3 | {{#if defaultValue}} 4 | 5 |  =  6 | {{defaultValue}} 7 | 8 | {{else if exportOf}} 9 | 10 | {{#with exportOf}}{{> exportBinding showStar=true}}{{/with}} 11 | 12 | {{/if}} 13 | {{/compact}}
    14 | 15 | {{> member.sources}} 16 | 17 | {{> comment}} 18 | 19 | {{#if type.declaration}} 20 |
    21 |

    Type declaration

    22 | {{#with type.declaration}} 23 | {{> parameter}} 24 | {{/with}} 25 |
    26 | {{/if}} -------------------------------------------------------------------------------- /src/typedoc/theme/partials/member.getterSetter.hbs: -------------------------------------------------------------------------------- 1 |
      2 | {{#if getSignature}} 3 | {{#with getSignature}} 4 |
    • {{#compact}} 5 | get  6 | {{../name}} 7 | {{> member.signature.title hideName=true }} 8 | {{/compact}}
    • 9 | {{/with}} 10 | {{/if}} 11 | {{#if setSignature}} 12 | {{#with setSignature}} 13 |
    • {{#compact}} 14 | set  15 | {{../name}} 16 | {{> member.signature.title hideName=true }} 17 | {{/compact}}
    • 18 | {{/with}} 19 | {{/if}} 20 |
    21 | 22 |
      23 | {{#if getSignature}} 24 | {{#with getSignature}} 25 |
    • 26 | {{> member.signature.body }} 27 |
    • 28 | {{/with}} 29 | {{/if}} 30 | {{#if setSignature}} 31 | {{#with setSignature}} 32 |
    • 33 | {{> member.signature.body }} 34 |
    • 35 | {{/with}} 36 | {{/if}} 37 |
    -------------------------------------------------------------------------------- /src/typedoc/theme/partials/member.hbs: -------------------------------------------------------------------------------- 1 |
    2 | 3 | {{#if name}} 4 |

    {{#each flags}}{{this}} {{/each}}{{{wbr name}}}

    5 | {{/if}} 6 | 7 | {{#if signatures}} 8 | {{> member.signatures}} 9 | {{else if hasGetterOrSetter}} 10 | {{> member.getterSetter}} 11 | {{else}} 12 | {{> member.declaration}} 13 | {{/if}} 14 | 15 | {{#each groups}} 16 | {{#each children}} 17 | {{#unless hasOwnDocument}} 18 | {{> member}} 19 | {{/unless}} 20 | {{/each}} 21 | {{/each}} 22 |
    23 | -------------------------------------------------------------------------------- /src/typedoc/theme/partials/member.signature.body.hbs: -------------------------------------------------------------------------------- 1 | {{#unless hideSources}} 2 | {{> member.sources isSignature=true}} 3 | {{/unless}} 4 | 5 | {{> comment}} 6 | 7 | {{#if typeParameters}} 8 |

    Type parameters

    9 | {{> typeParameters}} 10 | {{/if}} 11 | 12 | {{#if parameters}} 13 |

    Parameters

    14 |
      15 | {{#each parameters}} 16 |
    • 17 | {{#compact}} 18 | {{#each flags}} 19 | {{this}}  20 | {{/each}} 21 | {{#if flags.isRest}}...{{/if}} 22 | {{name}}:  23 | {{#with type}}{{>type}}{{/with}} 24 | {{#if defaultValue}} 25 | 26 |  =  27 | {{defaultValue}} 28 | 29 | {{/if}} 30 | {{/compact}} 31 | {{> comment.inline}} 32 | {{#if type.declaration}} 33 | {{#with type.declaration}} 34 | {{> parameter}} 35 | {{/with}} 36 | {{/if}} 37 |
    • 38 | {{/each}} 39 |
    40 | {{/if}} 41 | 42 | {{#if type}} 43 |

    Returns {{#with type}}{{>type}}{{/with}}

    44 | 45 | {{#if comment.returns}} 46 | {{#markdown}}{{{comment.returns}}}{{/markdown}} 47 | {{/if}} 48 | 49 | {{#if type.declaration}} 50 | {{#with type.declaration}} 51 | {{> parameter}} 52 | {{/with}} 53 | {{/if}} 54 | {{/if}} -------------------------------------------------------------------------------- /src/typedoc/theme/partials/member.signature.title.hbs: -------------------------------------------------------------------------------- 1 | {{#compact}} 2 | {{#unless hideName}}{{{wbr name}}}{{/unless}} 3 | {{#if typeParameters}} 4 | < 5 | {{#each typeParameters}} 6 | {{#if @index}}, {{/if}} 7 | {{name}} 8 | {{/each}} 9 | > 10 | {{/if}} 11 | ( 12 | {{#each parameters}} 13 | {{#if @index}}, {{/if}} 14 | {{#if flags.isRest}}...{{/if}} 15 | {{name}} 16 | 17 | {{#if flags.isOptional}}?{{/if}} 18 | {{#if defaultValue}}?{{/if}} 19 | :  20 | 21 | {{#with type}}{{>type}}{{/with}} 22 | {{/each}} 23 | ) 24 | {{#if type}} 25 | 26 | {{#with type}}{{>type}}{{/with}} 27 | {{/if}} 28 | {{/compact}} -------------------------------------------------------------------------------- /src/typedoc/theme/partials/member.signatures.hbs: -------------------------------------------------------------------------------- 1 |
      2 | {{#each signatures}} 3 |
    • {{> member.signature.title }}
    • 4 | {{/each}} 5 |
    6 | 7 |
      8 | {{#each signatures}} 9 |
    • 10 | {{> member.signature.body }} 11 |
    • 12 | {{/each}} 13 |
    -------------------------------------------------------------------------------- /src/typedoc/theme/partials/member.sources.hbs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/typedoc/theme/partials/members.group.hbs: -------------------------------------------------------------------------------- 1 | {{#if categories}} 2 | {{#each categories}} 3 |
    4 |

    {{../title}}{{#ifCond title '==' "Other"}}{{else}} ({{title}}){{/ifCond}}

    5 | {{#each children}} 6 | {{#unless hasOwnDocument}} 7 | {{> member}} 8 | {{/unless}} 9 | {{/each}} 10 |
    11 | {{/each}} 12 | {{else}} 13 |
    14 |

    {{title}}

    15 | {{#each children}} 16 | {{#unless hasOwnDocument}} 17 | {{> member}} 18 | {{/unless}} 19 | {{/each}} 20 |
    21 | {{/if}} -------------------------------------------------------------------------------- /src/typedoc/theme/partials/members.hbs: -------------------------------------------------------------------------------- 1 | {{#each groups}} 2 | {{#unless allChildrenHaveOwnDocument}} 3 | {{> members.group}} 4 | {{/unless}} 5 | {{/each}} -------------------------------------------------------------------------------- /src/typedoc/theme/partials/navigation.hbs: -------------------------------------------------------------------------------- 1 | {{#if isVisible}} 2 | {{#if isLabel}} 3 |
  • 4 | {{{wbr title}}} 5 |
  • 6 | {{else}} 7 | {{#if isGlobals}} 8 |
  • 9 | {{{wbr title}}} 10 |
  • 11 | {{else}} 12 |
  • 13 | {{{wbr title}}} 14 | {{#if isInPath}} 15 | {{#if children}} 16 |
      17 | {{#each children}} 18 | {{> navigation}} 19 | {{/each}} 20 |
    21 | {{/if}} 22 | {{/if}} 23 |
  • 24 | {{/if}} 25 | {{/if}} 26 | {{/if}} 27 | -------------------------------------------------------------------------------- /src/typedoc/theme/partials/toc.hbs: -------------------------------------------------------------------------------- 1 |
  • 2 | {{{wbr title}}} 3 | {{#if children}} 4 |
      5 | {{#each children}} 6 | {{> toc}} 7 | {{/each}} 8 |
    9 | {{/if}} 10 |
  • 11 | -------------------------------------------------------------------------------- /src/typedoc/theme/partials/toc.root.hbs: -------------------------------------------------------------------------------- 1 | {{#if isInPath}} 2 | 3 |
      4 | {{/if}} 5 |
    • 6 | {{{wbr title}}} 7 | {{#if children}} 8 |
        9 | {{#each children}} 10 | {{> toc}} 11 | {{/each}} 12 |
      13 | {{/if}} 14 |
    • 15 | {{#if isInPath}} 16 |
    17 |
      18 | {{/if}} 19 | -------------------------------------------------------------------------------- /src/typedoc/theme/partials/typeAndParent.hbs: -------------------------------------------------------------------------------- 1 | {{#compact}} 2 | {{#if this}} 3 | {{#if elementType}} 4 | {{#with elementType}} 5 | {{> typeAndParent}} 6 | {{/with}} 7 | [] 8 | {{else}} 9 | {{#if reflection}} 10 | {{#ifSignature reflection}} 11 | {{#if reflection.parent.parent.url}} 12 | {{reflection.parent.parent.name}} 13 | {{else}} 14 | {{reflection.parent.parent.name}} 15 | {{/if}} 16 | . 17 | {{#if reflection.parent.url}} 18 | {{reflection.parent.name}} 19 | {{else}} 20 | {{reflection.parent.name}} 21 | {{/if}} 22 | {{else}} 23 | {{#if reflection.parent.url}} 24 | {{reflection.parent.name}} 25 | {{else}} 26 | {{reflection.parent.name}} 27 | {{/if}} 28 | . 29 | {{#if reflection.url}} 30 | {{reflection.name}} 31 | {{else}} 32 | {{reflection.name}} 33 | {{/if}} 34 | {{/ifSignature}} 35 | {{else}} 36 | {{this}} 37 | {{/if}} 38 | {{/if}} 39 | {{else}} 40 | void 41 | {{/if}} 42 | {{/compact}} -------------------------------------------------------------------------------- /src/typedoc/theme/partials/typeParameters.hbs: -------------------------------------------------------------------------------- 1 |
        2 | {{#each typeParameters}} 3 |
      • 4 | {{#compact}} 5 | {{name}} 6 | {{#if type}} 7 | 8 | {{#with type}}{{> type}}{{/with}} 9 | {{/if}} 10 | {{#if comment.hasVisibleComponent}} 11 | — 12 |
        13 | {{> comment}} 14 |
        15 | {{/if}} 16 | {{/compact}} 17 |
      • 18 | {{/each}} 19 |
      -------------------------------------------------------------------------------- /src/typedoc/theme/templates/index.hbs: -------------------------------------------------------------------------------- 1 |
      2 | {{#markdown}}{{{model.readme}}}{{/markdown}} 3 |
      --------------------------------------------------------------------------------