diff --git a/.gitignore b/.gitignore index d1e8db0..75133da 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,7 @@ build/ node_modules/ .idea/ *.log +*~ +*.pdf +functions/index.* +functions/index/ diff --git a/functions/index.js b/functions/index.js deleted file mode 100644 index a9ab995..0000000 --- a/functions/index.js +++ /dev/null @@ -1,232 +0,0 @@ -(function (_, Kotlin) { - 'use strict'; - var Kind_CLASS = Kotlin.Kind.CLASS; - var throwCCE = Kotlin.throwCCE; - var until = Kotlin.kotlin.ranges.until_dqglrj$; - var chunked = Kotlin.kotlin.collections.chunked_ba2ldo$; - function get_cm($receiver) { - return $receiver / 2.54; - } - function get_asPoints($receiver) { - return $receiver * 72; - } - function Entry(eventNbr, event, lane, heat, swimmer, team) { - this.eventNbr = eventNbr; - this.event = event; - this.lane = lane; - this.heat = heat; - this.swimmer = swimmer; - this.team = team; - } - Entry.$metadata$ = { - kind: Kind_CLASS, - simpleName: 'Entry', - interfaces: [] - }; - Entry.prototype.component1 = function () { - return this.eventNbr; - }; - Entry.prototype.component2 = function () { - return this.event; - }; - Entry.prototype.component3 = function () { - return this.lane; - }; - Entry.prototype.component4 = function () { - return this.heat; - }; - Entry.prototype.component5 = function () { - return this.swimmer; - }; - Entry.prototype.component6 = function () { - return this.team; - }; - Entry.prototype.copy_cdqwiw$ = function (eventNbr, event, lane, heat, swimmer, team) { - return new Entry(eventNbr === void 0 ? this.eventNbr : eventNbr, event === void 0 ? this.event : event, lane === void 0 ? this.lane : lane, heat === void 0 ? this.heat : heat, swimmer === void 0 ? this.swimmer : swimmer, team === void 0 ? this.team : team); - }; - Entry.prototype.toString = function () { - return 'Entry(eventNbr=' + Kotlin.toString(this.eventNbr) + (', event=' + Kotlin.toString(this.event)) + (', lane=' + Kotlin.toString(this.lane)) + (', heat=' + Kotlin.toString(this.heat)) + (', swimmer=' + Kotlin.toString(this.swimmer)) + (', team=' + Kotlin.toString(this.team)) + ')'; - }; - Entry.prototype.hashCode = function () { - var result = 0; - result = result * 31 + Kotlin.hashCode(this.eventNbr) | 0; - result = result * 31 + Kotlin.hashCode(this.event) | 0; - result = result * 31 + Kotlin.hashCode(this.lane) | 0; - result = result * 31 + Kotlin.hashCode(this.heat) | 0; - result = result * 31 + Kotlin.hashCode(this.swimmer) | 0; - result = result * 31 + Kotlin.hashCode(this.team) | 0; - return result; - }; - Entry.prototype.equals = function (other) { - return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && (Kotlin.equals(this.eventNbr, other.eventNbr) && Kotlin.equals(this.event, other.event) && Kotlin.equals(this.lane, other.lane) && Kotlin.equals(this.heat, other.heat) && Kotlin.equals(this.swimmer, other.swimmer) && Kotlin.equals(this.team, other.team))))); - }; - function Meet(meet, entries) { - this.meet = meet; - this.entries = entries; - } - Meet.$metadata$ = { - kind: Kind_CLASS, - simpleName: 'Meet', - interfaces: [] - }; - Meet.prototype.component1 = function () { - return this.meet; - }; - Meet.prototype.component2 = function () { - return this.entries; - }; - Meet.prototype.copy_khic54$ = function (meet, entries) { - return new Meet(meet === void 0 ? this.meet : meet, entries === void 0 ? this.entries : entries); - }; - Meet.prototype.toString = function () { - return 'Meet(meet=' + Kotlin.toString(this.meet) + (', entries=' + Kotlin.toString(this.entries)) + ')'; - }; - Meet.prototype.hashCode = function () { - var result = 0; - result = result * 31 + Kotlin.hashCode(this.meet) | 0; - result = result * 31 + Kotlin.hashCode(this.entries) | 0; - return result; - }; - Meet.prototype.equals = function (other) { - return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && (Kotlin.equals(this.meet, other.meet) && Kotlin.equals(this.entries, other.entries))))); - }; - function hydrateEntry(entry) { - return new Entry(entry.eventNbr, entry.event, entry.lane, entry.heat, entry.swimmer, entry.team); - } - var collectionSizeOrDefault = Kotlin.kotlin.collections.collectionSizeOrDefault_ba2ldo$; - var ArrayList_init = Kotlin.kotlin.collections.ArrayList_init_ww73n8$; - function iterate(list) { - var tmp$; - var $receiver = until(0, typeof (tmp$ = list.length) === 'number' ? tmp$ : throwCCE()); - var destination = ArrayList_init(collectionSizeOrDefault($receiver, 10)); - var tmp$_0; - tmp$_0 = $receiver.iterator(); - while (tmp$_0.hasNext()) { - var item = tmp$_0.next(); - destination.add_11rb$(list[item]); - } - return destination; - } - function hydrateMeet(meet) { - var tmp$ = meet.meet; - var $receiver = iterate(meet.entries); - var destination = ArrayList_init(collectionSizeOrDefault($receiver, 10)); - var tmp$_0; - tmp$_0 = $receiver.iterator(); - while (tmp$_0.hasNext()) { - var item = tmp$_0.next(); - destination.add_11rb$(hydrateEntry(item)); - } - return new Meet(tmp$, destination); - } - function main$lambda(req, res) { - var doc = new (require('pdfkit'))({autoFirstPage: false}); - var meetInfo = hydrateMeet(req.body); - res.setHeader('Content-Disposition', 'attachment;filename=' + '"' + 'lane-slips-' + meetInfo.meet + '.pdf' + '"'); - res.setHeader('Content-Type', 'application/pdf'); - doc.pipe(res); - var tmp$; - tmp$ = chunked(meetInfo.entries, 6).iterator(); - while (tmp$.hasNext()) { - var element = tmp$.next(); - doc.addPage(); - var tmp$_0, tmp$_0_0; - var index = 0; - tmp$_0 = element.iterator(); - while (tmp$_0.hasNext()) { - var item = tmp$_0.next(); - var index_0 = (tmp$_0_0 = index, index = tmp$_0_0 + 1 | 0, tmp$_0_0); - writeSlip(item, doc, index_0 % 2, index_0 / 2 | 0); - } - drawDashes(doc); - } - return doc.end(); - } - function main(args) { - var fireFunctions = require('firebase-functions'); - fireFunctions.config(); - exports.laneslips = fireFunctions.https.onRequest(main$lambda); - } - function drawDashes(doc) { - var dashOptions = {}; - dashOptions.space = 10; - doc.moveTo(get_asPoints(get_cm(10.25)), get_asPoints(get_cm(1.0))).lineTo(get_asPoints(get_cm(10.25)), get_asPoints(get_cm(27.0))).dash(5, dashOptions).stroke(); - doc.moveTo(get_asPoints(get_cm(1.0)), get_asPoints(get_cm(9.5))).lineTo(get_asPoints(get_cm(21.0)), get_asPoints(get_cm(9.5))).dash(5, dashOptions).stroke(); - doc.moveTo(get_asPoints(get_cm(1.0)), get_asPoints(get_cm(18.5))).lineTo(get_asPoints(get_cm(21.0)), get_asPoints(get_cm(18.5))).dash(5, dashOptions).stroke(); - } - function writeSlip($receiver, doc, x, y) { - var xOffset = get_asPoints(get_cm(10.0)) * x; - var yOffset = get_asPoints(get_cm(8.0)) * y; - var leftMargin = get_asPoints(get_cm(0.9)) + xOffset; - var opts = {}; - opts.width = get_asPoints(get_cm(8.5)); - opts.align = 'center'; - doc.fontSize(13); - doc.font('Helvetica-Bold'); - doc.text('Southern Ohio Swim League', leftMargin, get_asPoints(get_cm(1.5)) + yOffset, opts); - doc.fontSize(11); - doc.font('Times-Roman'); - var eventY = get_asPoints(get_cm(2.3)) + yOffset; - doc.text('EVENT #' + $receiver.eventNbr + ' - ' + $receiver.event, leftMargin, eventY); - var lineSeparation = get_asPoints(get_cm(1.0)); - var laneY = eventY + lineSeparation; - doc.text('Lane:', leftMargin, laneY); - var colWidth = get_asPoints(get_cm(1.3)); - doc.text('1', leftMargin + colWidth * 1, laneY); - doc.text('2', leftMargin + colWidth * 2, laneY); - doc.text('3', leftMargin + colWidth * 3, laneY); - doc.text('4', leftMargin + colWidth * 4, laneY); - doc.text('5', leftMargin + colWidth * 5, laneY); - doc.text('6', leftMargin + colWidth * 6, laneY); - doc.circle(leftMargin + colWidth * $receiver.lane + get_asPoints(get_cm(0.1)), laneY + get_asPoints(get_cm(0.15)), get_asPoints(get_cm(0.3))); - doc.stroke(); - var heatY = laneY + lineSeparation; - doc.text('Heat:', leftMargin, heatY); - doc.text('1', leftMargin + colWidth * 1, heatY); - doc.text('2', leftMargin + colWidth * 2, heatY); - doc.text('3', leftMargin + colWidth * 3, heatY); - doc.text('4', leftMargin + colWidth * 4, heatY); - doc.text('5', leftMargin + colWidth * 5, heatY); - doc.text('6', leftMargin + colWidth * 6, heatY); - doc.circle(leftMargin + colWidth * $receiver.heat + get_asPoints(get_cm(0.1)), heatY + get_asPoints(get_cm(0.15)), get_asPoints(get_cm(0.3))); - doc.stroke(); - var nameY = heatY + lineSeparation; - doc.text('Name: ' + $receiver.swimmer, leftMargin, nameY); - var teamY = nameY + lineSeparation; - doc.text('Team: ' + $receiver.team, leftMargin, teamY); - var timesY = teamY + lineSeparation * 1.5; - doc.text('Times:', leftMargin, timesY); - doc.moveTo(leftMargin + colWidth, timesY + 14).lineTo(leftMargin + colWidth + get_asPoints(get_cm(2.0)), timesY + 14).stroke(); - doc.moveTo(leftMargin + colWidth + get_asPoints(get_cm(2.7)), timesY + 14).lineTo(leftMargin + colWidth + get_asPoints(get_cm(4.7)), timesY + 14).stroke(); - doc.moveTo(leftMargin + colWidth + get_asPoints(get_cm(5.4)), timesY + 14).lineTo(leftMargin + colWidth + get_asPoints(get_cm(7.4)), timesY + 14).stroke(); - var officialTimesY = timesY + lineSeparation * 1.5; - doc.text('Official Time:', leftMargin, officialTimesY); - doc.moveTo(leftMargin + colWidth * 2, officialTimesY + 14).lineTo(leftMargin + colWidth * 2 + get_asPoints(get_cm(4.0)), officialTimesY + 14).stroke(); - var placeY = officialTimesY + lineSeparation * 1.25; - doc.text('Place:', leftMargin, placeY); - doc.text('1', leftMargin + colWidth * 1, placeY); - doc.text('2', leftMargin + colWidth * 2, placeY); - doc.text('3', leftMargin + colWidth * 3, placeY); - doc.text('4', leftMargin + colWidth * 4, placeY); - doc.text('5', leftMargin + colWidth * 5, placeY); - doc.text('6', leftMargin + colWidth * 6, placeY); - } - var package$online = _.online || (_.online = {}); - var package$cinphart = package$online.cinphart || (package$online.cinphart = {}); - var package$laneslips = package$cinphart.laneslips || (package$cinphart.laneslips = {}); - package$laneslips.get_cm_yrwdxr$ = get_cm; - package$laneslips.get_asPoints_yrwdxr$ = get_asPoints; - package$laneslips.Entry = Entry; - package$laneslips.Meet = Meet; - package$laneslips.hydrateEntry_za3rmp$ = hydrateEntry; - package$laneslips.iterate_za3rmp$ = iterate; - package$laneslips.hydrateMeet_za3rmp$ = hydrateMeet; - package$laneslips.main_kand9s$ = main; - package$laneslips.drawDashes_za3rmp$ = drawDashes; - package$laneslips.writeSlip_dmpztf$ = writeSlip; - main([]); - Kotlin.defineModule('index', _); - return _; -}(module.exports, require('kotlin'))); - -//# sourceMappingURL=index.js.map diff --git a/functions/index.js.map b/functions/index.js.map deleted file mode 100644 index 0407c75..0000000 --- a/functions/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../src/main/kotlin/online/cinphart/laneslips/Generator.kt","_CollectionsJs.kt"],"sourcesContent":[null,"@file:kotlin.jvm.JvmMultifileClass\n@file:kotlin.jvm.JvmName(\"CollectionsKt\")\n\npackage kotlin.collections\n\n//\n// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt\n// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib\n//\n\nimport kotlin.js.*\nimport kotlin.comparisons.*\n\n/**\n * Returns 1st *element* from the collection.\n */\n@kotlin.internal.InlineOnly\npublic inline operator fun List.component1(): T {\n return get(0)\n}\n\n/**\n * Returns 2nd *element* from the collection.\n */\n@kotlin.internal.InlineOnly\npublic inline operator fun List.component2(): T {\n return get(1)\n}\n\n/**\n * Returns 3rd *element* from the collection.\n */\n@kotlin.internal.InlineOnly\npublic inline operator fun List.component3(): T {\n return get(2)\n}\n\n/**\n * Returns 4th *element* from the collection.\n */\n@kotlin.internal.InlineOnly\npublic inline operator fun List.component4(): T {\n return get(3)\n}\n\n/**\n * Returns 5th *element* from the collection.\n */\n@kotlin.internal.InlineOnly\npublic inline operator fun List.component5(): T {\n return get(4)\n}\n\n/**\n * Returns `true` if [element] is found in the collection.\n */\npublic operator fun <@kotlin.internal.OnlyInputTypes T> Iterable.contains(element: T): Boolean {\n if (this is Collection)\n return contains(element)\n return indexOf(element) >= 0\n}\n\n/**\n * Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this collection.\n */\npublic fun Iterable.elementAt(index: Int): T {\n if (this is List)\n return get(index)\n return elementAtOrElse(index) { throw IndexOutOfBoundsException(\"Collection doesn't contain element at index $index.\") }\n}\n\n/**\n * Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this list.\n */\n@kotlin.internal.InlineOnly\npublic inline fun List.elementAt(index: Int): T {\n return get(index)\n}\n\n/**\n * Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this collection.\n */\npublic fun Iterable.elementAtOrElse(index: Int, defaultValue: (Int) -> T): T {\n if (this is List)\n return this.getOrElse(index, defaultValue)\n if (index < 0)\n return defaultValue(index)\n val iterator = iterator()\n var count = 0\n while (iterator.hasNext()) {\n val element = iterator.next()\n if (index == count++)\n return element\n }\n return defaultValue(index)\n}\n\n/**\n * Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this list.\n */\n@kotlin.internal.InlineOnly\npublic inline fun List.elementAtOrElse(index: Int, defaultValue: (Int) -> T): T {\n return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)\n}\n\n/**\n * Returns an element at the given [index] or `null` if the [index] is out of bounds of this collection.\n */\npublic fun Iterable.elementAtOrNull(index: Int): T? {\n if (this is List)\n return this.getOrNull(index)\n if (index < 0)\n return null\n val iterator = iterator()\n var count = 0\n while (iterator.hasNext()) {\n val element = iterator.next()\n if (index == count++)\n return element\n }\n return null\n}\n\n/**\n * Returns an element at the given [index] or `null` if the [index] is out of bounds of this list.\n */\n@kotlin.internal.InlineOnly\npublic inline fun List.elementAtOrNull(index: Int): T? {\n return this.getOrNull(index)\n}\n\n/**\n * Returns the first element matching the given [predicate], or `null` if no such element was found.\n */\n@kotlin.internal.InlineOnly\npublic inline fun Iterable.find(predicate: (T) -> Boolean): T? {\n return firstOrNull(predicate)\n}\n\n/**\n * Returns the last element matching the given [predicate], or `null` if no such element was found.\n */\n@kotlin.internal.InlineOnly\npublic inline fun Iterable.findLast(predicate: (T) -> Boolean): T? {\n return lastOrNull(predicate)\n}\n\n/**\n * Returns the last element matching the given [predicate], or `null` if no such element was found.\n */\n@kotlin.internal.InlineOnly\npublic inline fun List.findLast(predicate: (T) -> Boolean): T? {\n return lastOrNull(predicate)\n}\n\n/**\n * Returns first element.\n * @throws [NoSuchElementException] if the collection is empty.\n */\npublic fun Iterable.first(): T {\n when (this) {\n is List -> return this.first()\n else -> {\n val iterator = iterator()\n if (!iterator.hasNext())\n throw NoSuchElementException(\"Collection is empty.\")\n return iterator.next()\n }\n }\n}\n\n/**\n * Returns first element.\n * @throws [NoSuchElementException] if the list is empty.\n */\npublic fun List.first(): T {\n if (isEmpty())\n throw NoSuchElementException(\"List is empty.\")\n return this[0]\n}\n\n/**\n * Returns the first element matching the given [predicate].\n * @throws [NoSuchElementException] if no such element is found.\n */\npublic inline fun Iterable.first(predicate: (T) -> Boolean): T {\n for (element in this) if (predicate(element)) return element\n throw NoSuchElementException(\"Collection contains no element matching the predicate.\")\n}\n\n/**\n * Returns the first element, or `null` if the collection is empty.\n */\npublic fun Iterable.firstOrNull(): T? {\n when (this) {\n is List -> {\n if (isEmpty())\n return null\n else\n return this[0]\n }\n else -> {\n val iterator = iterator()\n if (!iterator.hasNext())\n return null\n return iterator.next()\n }\n }\n}\n\n/**\n * Returns the first element, or `null` if the list is empty.\n */\npublic fun List.firstOrNull(): T? {\n return if (isEmpty()) null else this[0]\n}\n\n/**\n * Returns the first element matching the given [predicate], or `null` if element was not found.\n */\npublic inline fun Iterable.firstOrNull(predicate: (T) -> Boolean): T? {\n for (element in this) if (predicate(element)) return element\n return null\n}\n\n/**\n * Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this list.\n */\n@kotlin.internal.InlineOnly\npublic inline fun List.getOrElse(index: Int, defaultValue: (Int) -> T): T {\n return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)\n}\n\n/**\n * Returns an element at the given [index] or `null` if the [index] is out of bounds of this list.\n */\npublic fun List.getOrNull(index: Int): T? {\n return if (index >= 0 && index <= lastIndex) get(index) else null\n}\n\n/**\n * Returns first index of [element], or -1 if the collection does not contain element.\n */\npublic fun <@kotlin.internal.OnlyInputTypes T> Iterable.indexOf(element: T): Int {\n if (this is List) return this.indexOf(element)\n var index = 0\n for (item in this) {\n if (element == item)\n return index\n index++\n }\n return -1\n}\n\n/**\n * Returns first index of [element], or -1 if the list does not contain element.\n */\n@Suppress(\"EXTENSION_SHADOWED_BY_MEMBER\") // false warning, extension takes precedence in some cases\npublic fun <@kotlin.internal.OnlyInputTypes T> List.indexOf(element: T): Int {\n return indexOf(element)\n}\n\n/**\n * Returns index of the first element matching the given [predicate], or -1 if the collection does not contain such element.\n */\npublic inline fun Iterable.indexOfFirst(predicate: (T) -> Boolean): Int {\n var index = 0\n for (item in this) {\n if (predicate(item))\n return index\n index++\n }\n return -1\n}\n\n/**\n * Returns index of the first element matching the given [predicate], or -1 if the list does not contain such element.\n */\npublic inline fun List.indexOfFirst(predicate: (T) -> Boolean): Int {\n var index = 0\n for (item in this) {\n if (predicate(item))\n return index\n index++\n }\n return -1\n}\n\n/**\n * Returns index of the last element matching the given [predicate], or -1 if the collection does not contain such element.\n */\npublic inline fun Iterable.indexOfLast(predicate: (T) -> Boolean): Int {\n var lastIndex = -1\n var index = 0\n for (item in this) {\n if (predicate(item))\n lastIndex = index\n index++\n }\n return lastIndex\n}\n\n/**\n * Returns index of the last element matching the given [predicate], or -1 if the list does not contain such element.\n */\npublic inline fun List.indexOfLast(predicate: (T) -> Boolean): Int {\n val iterator = this.listIterator(size)\n while (iterator.hasPrevious()) {\n if (predicate(iterator.previous())) {\n return iterator.nextIndex()\n }\n }\n return -1\n}\n\n/**\n * Returns the last element.\n * @throws [NoSuchElementException] if the collection is empty.\n */\npublic fun Iterable.last(): T {\n when (this) {\n is List -> return this.last()\n else -> {\n val iterator = iterator()\n if (!iterator.hasNext())\n throw NoSuchElementException(\"Collection is empty.\")\n var last = iterator.next()\n while (iterator.hasNext())\n last = iterator.next()\n return last\n }\n }\n}\n\n/**\n * Returns the last element.\n * @throws [NoSuchElementException] if the list is empty.\n */\npublic fun List.last(): T {\n if (isEmpty())\n throw NoSuchElementException(\"List is empty.\")\n return this[lastIndex]\n}\n\n/**\n * Returns the last element matching the given [predicate].\n * @throws [NoSuchElementException] if no such element is found.\n */\npublic inline fun Iterable.last(predicate: (T) -> Boolean): T {\n var last: T? = null\n var found = false\n for (element in this) {\n if (predicate(element)) {\n last = element\n found = true\n }\n }\n if (!found) throw NoSuchElementException(\"Collection contains no element matching the predicate.\")\n @Suppress(\"UNCHECKED_CAST\")\n return last as T\n}\n\n/**\n * Returns the last element matching the given [predicate].\n * @throws [NoSuchElementException] if no such element is found.\n */\npublic inline fun List.last(predicate: (T) -> Boolean): T {\n val iterator = this.listIterator(size)\n while (iterator.hasPrevious()) {\n val element = iterator.previous()\n if (predicate(element)) return element\n }\n throw NoSuchElementException(\"List contains no element matching the predicate.\")\n}\n\n/**\n * Returns last index of [element], or -1 if the collection does not contain element.\n */\npublic fun <@kotlin.internal.OnlyInputTypes T> Iterable.lastIndexOf(element: T): Int {\n if (this is List) return this.lastIndexOf(element)\n var lastIndex = -1\n var index = 0\n for (item in this) {\n if (element == item)\n lastIndex = index\n index++\n }\n return lastIndex\n}\n\n/**\n * Returns last index of [element], or -1 if the list does not contain element.\n */\n@Suppress(\"EXTENSION_SHADOWED_BY_MEMBER\") // false warning, extension takes precedence in some cases\npublic fun <@kotlin.internal.OnlyInputTypes T> List.lastIndexOf(element: T): Int {\n return lastIndexOf(element)\n}\n\n/**\n * Returns the last element, or `null` if the collection is empty.\n */\npublic fun Iterable.lastOrNull(): T? {\n when (this) {\n is List -> return if (isEmpty()) null else this[size - 1]\n else -> {\n val iterator = iterator()\n if (!iterator.hasNext())\n return null\n var last = iterator.next()\n while (iterator.hasNext())\n last = iterator.next()\n return last\n }\n }\n}\n\n/**\n * Returns the last element, or `null` if the list is empty.\n */\npublic fun List.lastOrNull(): T? {\n return if (isEmpty()) null else this[size - 1]\n}\n\n/**\n * Returns the last element matching the given [predicate], or `null` if no such element was found.\n */\npublic inline fun Iterable.lastOrNull(predicate: (T) -> Boolean): T? {\n var last: T? = null\n for (element in this) {\n if (predicate(element)) {\n last = element\n }\n }\n return last\n}\n\n/**\n * Returns the last element matching the given [predicate], or `null` if no such element was found.\n */\npublic inline fun List.lastOrNull(predicate: (T) -> Boolean): T? {\n val iterator = this.listIterator(size)\n while (iterator.hasPrevious()) {\n val element = iterator.previous()\n if (predicate(element)) return element\n }\n return null\n}\n\n/**\n * Returns the single element, or throws an exception if the collection is empty or has more than one element.\n */\npublic fun Iterable.single(): T {\n when (this) {\n is List -> return this.single()\n else -> {\n val iterator = iterator()\n if (!iterator.hasNext())\n throw NoSuchElementException(\"Collection is empty.\")\n val single = iterator.next()\n if (iterator.hasNext())\n throw IllegalArgumentException(\"Collection has more than one element.\")\n return single\n }\n }\n}\n\n/**\n * Returns the single element, or throws an exception if the list is empty or has more than one element.\n */\npublic fun List.single(): T {\n return when (size) {\n 0 -> throw NoSuchElementException(\"List is empty.\")\n 1 -> this[0]\n else -> throw IllegalArgumentException(\"List has more than one element.\")\n }\n}\n\n/**\n * Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.\n */\npublic inline fun Iterable.single(predicate: (T) -> Boolean): T {\n var single: T? = null\n var found = false\n for (element in this) {\n if (predicate(element)) {\n if (found) throw IllegalArgumentException(\"Collection contains more than one matching element.\")\n single = element\n found = true\n }\n }\n if (!found) throw NoSuchElementException(\"Collection contains no element matching the predicate.\")\n @Suppress(\"UNCHECKED_CAST\")\n return single as T\n}\n\n/**\n * Returns single element, or `null` if the collection is empty or has more than one element.\n */\npublic fun Iterable.singleOrNull(): T? {\n when (this) {\n is List -> return if (size == 1) this[0] else null\n else -> {\n val iterator = iterator()\n if (!iterator.hasNext())\n return null\n val single = iterator.next()\n if (iterator.hasNext())\n return null\n return single\n }\n }\n}\n\n/**\n * Returns single element, or `null` if the list is empty or has more than one element.\n */\npublic fun List.singleOrNull(): T? {\n return if (size == 1) this[0] else null\n}\n\n/**\n * Returns the single element matching the given [predicate], or `null` if element was not found or more than one element was found.\n */\npublic inline fun Iterable.singleOrNull(predicate: (T) -> Boolean): T? {\n var single: T? = null\n var found = false\n for (element in this) {\n if (predicate(element)) {\n if (found) return null\n single = element\n found = true\n }\n }\n if (!found) return null\n return single\n}\n\n/**\n * Returns a list containing all elements except first [n] elements.\n * \n * @sample samples.collections.Collections.Transformations.drop\n */\npublic fun Iterable.drop(n: Int): List {\n require(n >= 0) { \"Requested element count $n is less than zero.\" }\n if (n == 0) return toList()\n val list: ArrayList\n if (this is Collection<*>) {\n val resultSize = size - n\n if (resultSize <= 0)\n return emptyList()\n if (resultSize == 1)\n return listOf(last())\n list = ArrayList(resultSize)\n if (this is List) {\n if (this is RandomAccess) {\n for (index in n until size)\n list.add(this[index])\n } else {\n for (item in listIterator(n))\n list.add(item)\n }\n return list\n }\n }\n else {\n list = ArrayList()\n }\n var count = 0\n for (item in this) {\n if (count++ >= n) list.add(item)\n }\n return list.optimizeReadOnlyList()\n}\n\n/**\n * Returns a list containing all elements except last [n] elements.\n * \n * @sample samples.collections.Collections.Transformations.drop\n */\npublic fun List.dropLast(n: Int): List {\n require(n >= 0) { \"Requested element count $n is less than zero.\" }\n return take((size - n).coerceAtLeast(0))\n}\n\n/**\n * Returns a list containing all elements except last elements that satisfy the given [predicate].\n * \n * @sample samples.collections.Collections.Transformations.drop\n */\npublic inline fun List.dropLastWhile(predicate: (T) -> Boolean): List {\n if (!isEmpty()) {\n val iterator = listIterator(size)\n while (iterator.hasPrevious()) {\n if (!predicate(iterator.previous())) {\n return take(iterator.nextIndex() + 1)\n }\n }\n }\n return emptyList()\n}\n\n/**\n * Returns a list containing all elements except first elements that satisfy the given [predicate].\n * \n * @sample samples.collections.Collections.Transformations.drop\n */\npublic inline fun Iterable.dropWhile(predicate: (T) -> Boolean): List {\n var yielding = false\n val list = ArrayList()\n for (item in this)\n if (yielding)\n list.add(item)\n else if (!predicate(item)) {\n list.add(item)\n yielding = true\n }\n return list\n}\n\n/**\n * Returns a list containing only elements matching the given [predicate].\n */\npublic inline fun Iterable.filter(predicate: (T) -> Boolean): List {\n return filterTo(ArrayList(), predicate)\n}\n\n/**\n * Returns a list containing only elements matching the given [predicate].\n * @param [predicate] function that takes the index of an element and the element itself\n * and returns the result of predicate evaluation on the element.\n */\npublic inline fun Iterable.filterIndexed(predicate: (index: Int, T) -> Boolean): List {\n return filterIndexedTo(ArrayList(), predicate)\n}\n\n/**\n * Appends all elements matching the given [predicate] to the given [destination].\n * @param [predicate] function that takes the index of an element and the element itself\n * and returns the result of predicate evaluation on the element.\n */\npublic inline fun > Iterable.filterIndexedTo(destination: C, predicate: (index: Int, T) -> Boolean): C {\n forEachIndexed { index, element ->\n if (predicate(index, element)) destination.add(element)\n }\n return destination\n}\n\n/**\n * Returns a list containing all elements that are instances of specified type parameter R.\n */\npublic inline fun Iterable<*>.filterIsInstance(): List<@kotlin.internal.NoInfer R> {\n return filterIsInstanceTo(ArrayList())\n}\n\n/**\n * Appends all elements that are instances of specified type parameter R to the given [destination].\n */\npublic inline fun > Iterable<*>.filterIsInstanceTo(destination: C): C {\n for (element in this) if (element is R) destination.add(element)\n return destination\n}\n\n/**\n * Returns a list containing all elements not matching the given [predicate].\n */\npublic inline fun Iterable.filterNot(predicate: (T) -> Boolean): List {\n return filterNotTo(ArrayList(), predicate)\n}\n\n/**\n * Returns a list containing all elements that are not `null`.\n */\npublic fun Iterable.filterNotNull(): List {\n return filterNotNullTo(ArrayList())\n}\n\n/**\n * Appends all elements that are not `null` to the given [destination].\n */\npublic fun , T : Any> Iterable.filterNotNullTo(destination: C): C {\n for (element in this) if (element != null) destination.add(element)\n return destination\n}\n\n/**\n * Appends all elements not matching the given [predicate] to the given [destination].\n */\npublic inline fun > Iterable.filterNotTo(destination: C, predicate: (T) -> Boolean): C {\n for (element in this) if (!predicate(element)) destination.add(element)\n return destination\n}\n\n/**\n * Appends all elements matching the given [predicate] to the given [destination].\n */\npublic inline fun > Iterable.filterTo(destination: C, predicate: (T) -> Boolean): C {\n for (element in this) if (predicate(element)) destination.add(element)\n return destination\n}\n\n/**\n * Returns a list containing elements at indices in the specified [indices] range.\n */\npublic fun List.slice(indices: IntRange): List {\n if (indices.isEmpty()) return listOf()\n return this.subList(indices.start, indices.endInclusive + 1).toList()\n}\n\n/**\n * Returns a list containing elements at specified [indices].\n */\npublic fun List.slice(indices: Iterable): List {\n val size = indices.collectionSizeOrDefault(10)\n if (size == 0) return emptyList()\n val list = ArrayList(size)\n for (index in indices) {\n list.add(get(index))\n }\n return list\n}\n\n/**\n * Returns a list containing first [n] elements.\n * \n * @sample samples.collections.Collections.Transformations.take\n */\npublic fun Iterable.take(n: Int): List {\n require(n >= 0) { \"Requested element count $n is less than zero.\" }\n if (n == 0) return emptyList()\n if (this is Collection) {\n if (n >= size) return toList()\n if (n == 1) return listOf(first())\n }\n var count = 0\n val list = ArrayList(n)\n for (item in this) {\n if (count++ == n)\n break\n list.add(item)\n }\n return list.optimizeReadOnlyList()\n}\n\n/**\n * Returns a list containing last [n] elements.\n * \n * @sample samples.collections.Collections.Transformations.take\n */\npublic fun List.takeLast(n: Int): List {\n require(n >= 0) { \"Requested element count $n is less than zero.\" }\n if (n == 0) return emptyList()\n val size = size\n if (n >= size) return toList()\n if (n == 1) return listOf(last())\n val list = ArrayList(n)\n if (this is RandomAccess) {\n for (index in size - n until size)\n list.add(this[index])\n } else {\n for (item in listIterator(size - n))\n list.add(item)\n }\n return list\n}\n\n/**\n * Returns a list containing last elements satisfying the given [predicate].\n * \n * @sample samples.collections.Collections.Transformations.take\n */\npublic inline fun List.takeLastWhile(predicate: (T) -> Boolean): List {\n if (isEmpty())\n return emptyList()\n val iterator = listIterator(size)\n while (iterator.hasPrevious()) {\n if (!predicate(iterator.previous())) {\n iterator.next()\n val expectedSize = size - iterator.nextIndex()\n if (expectedSize == 0) return emptyList()\n return ArrayList(expectedSize).apply {\n while (iterator.hasNext())\n add(iterator.next())\n }\n }\n }\n return toList()\n}\n\n/**\n * Returns a list containing first elements satisfying the given [predicate].\n * \n * @sample samples.collections.Collections.Transformations.take\n */\npublic inline fun Iterable.takeWhile(predicate: (T) -> Boolean): List {\n val list = ArrayList()\n for (item in this) {\n if (!predicate(item))\n break\n list.add(item)\n }\n return list\n}\n\n/**\n * Reverses elements in the list in-place.\n */\npublic fun MutableList.reverse(): Unit {\n val midPoint = (size / 2) - 1\n if (midPoint < 0) return\n var reverseIndex = lastIndex\n for (index in 0..midPoint) {\n val tmp = this[index]\n this[index] = this[reverseIndex]\n this[reverseIndex] = tmp\n reverseIndex--\n }\n}\n\n/**\n * Returns a list with elements in reversed order.\n */\npublic fun Iterable.reversed(): List {\n if (this is Collection && size <= 1) return toList()\n val list = toMutableList()\n list.reverse()\n return list\n}\n\n/**\n * Sorts elements in the list in-place according to natural sort order of the value returned by specified [selector] function.\n */\npublic inline fun > MutableList.sortBy(crossinline selector: (T) -> R?): Unit {\n if (size > 1) sortWith(compareBy(selector))\n}\n\n/**\n * Sorts elements in the list in-place descending according to natural sort order of the value returned by specified [selector] function.\n */\npublic inline fun > MutableList.sortByDescending(crossinline selector: (T) -> R?): Unit {\n if (size > 1) sortWith(compareByDescending(selector))\n}\n\n/**\n * Sorts elements in the list in-place descending according to their natural sort order.\n */\npublic fun > MutableList.sortDescending(): Unit {\n sortWith(reverseOrder())\n}\n\n/**\n * Returns a list of all elements sorted according to their natural sort order.\n */\npublic fun > Iterable.sorted(): List {\n if (this is Collection) {\n if (size <= 1) return this.toList()\n @Suppress(\"UNCHECKED_CAST\")\n return (toTypedArray>() as Array).apply { sort() }.asList()\n }\n return toMutableList().apply { sort() }\n}\n\n/**\n * Returns a list of all elements sorted according to natural sort order of the value returned by specified [selector] function.\n */\npublic inline fun > Iterable.sortedBy(crossinline selector: (T) -> R?): List {\n return sortedWith(compareBy(selector))\n}\n\n/**\n * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [selector] function.\n */\npublic inline fun > Iterable.sortedByDescending(crossinline selector: (T) -> R?): List {\n return sortedWith(compareByDescending(selector))\n}\n\n/**\n * Returns a list of all elements sorted descending according to their natural sort order.\n */\npublic fun > Iterable.sortedDescending(): List {\n return sortedWith(reverseOrder())\n}\n\n/**\n * Returns a list of all elements sorted according to the specified [comparator].\n */\npublic fun Iterable.sortedWith(comparator: Comparator): List {\n if (this is Collection) {\n if (size <= 1) return this.toList()\n @Suppress(\"UNCHECKED_CAST\")\n return (toTypedArray() as Array).apply { sortWith(comparator) }.asList()\n }\n return toMutableList().apply { sortWith(comparator) }\n}\n\n/**\n * Returns an array of Boolean containing all of the elements of this collection.\n */\npublic fun Collection.toBooleanArray(): BooleanArray {\n val result = BooleanArray(size)\n var index = 0\n for (element in this)\n result[index++] = element\n return result\n}\n\n/**\n * Returns an array of Byte containing all of the elements of this collection.\n */\npublic fun Collection.toByteArray(): ByteArray {\n val result = ByteArray(size)\n var index = 0\n for (element in this)\n result[index++] = element\n return result\n}\n\n/**\n * Returns an array of Char containing all of the elements of this collection.\n */\npublic fun Collection.toCharArray(): CharArray {\n val result = CharArray(size)\n var index = 0\n for (element in this)\n result[index++] = element\n return result\n}\n\n/**\n * Returns an array of Double containing all of the elements of this collection.\n */\npublic fun Collection.toDoubleArray(): DoubleArray {\n val result = DoubleArray(size)\n var index = 0\n for (element in this)\n result[index++] = element\n return result\n}\n\n/**\n * Returns an array of Float containing all of the elements of this collection.\n */\npublic fun Collection.toFloatArray(): FloatArray {\n val result = FloatArray(size)\n var index = 0\n for (element in this)\n result[index++] = element\n return result\n}\n\n/**\n * Returns an array of Int containing all of the elements of this collection.\n */\npublic fun Collection.toIntArray(): IntArray {\n val result = IntArray(size)\n var index = 0\n for (element in this)\n result[index++] = element\n return result\n}\n\n/**\n * Returns an array of Long containing all of the elements of this collection.\n */\npublic fun Collection.toLongArray(): LongArray {\n val result = LongArray(size)\n var index = 0\n for (element in this)\n result[index++] = element\n return result\n}\n\n/**\n * Returns an array of Short containing all of the elements of this collection.\n */\npublic fun Collection.toShortArray(): ShortArray {\n val result = ShortArray(size)\n var index = 0\n for (element in this)\n result[index++] = element\n return result\n}\n\n/**\n * Returns a [Map] containing key-value pairs provided by [transform] function\n * applied to elements of the given collection.\n * \n * If any of two pairs would have the same key the last one gets added to the map.\n * \n * The returned map preserves the entry iteration order of the original collection.\n */\npublic inline fun Iterable.associate(transform: (T) -> Pair): Map {\n val capacity = mapCapacity(collectionSizeOrDefault(10)).coerceAtLeast(16)\n return associateTo(LinkedHashMap(capacity), transform)\n}\n\n/**\n * Returns a [Map] containing the elements from the given collection indexed by the key\n * returned from [keySelector] function applied to each element.\n * \n * If any two elements would have the same key returned by [keySelector] the last one gets added to the map.\n * \n * The returned map preserves the entry iteration order of the original collection.\n */\npublic inline fun Iterable.associateBy(keySelector: (T) -> K): Map {\n val capacity = mapCapacity(collectionSizeOrDefault(10)).coerceAtLeast(16)\n return associateByTo(LinkedHashMap(capacity), keySelector)\n}\n\n/**\n * Returns a [Map] containing the values provided by [valueTransform] and indexed by [keySelector] functions applied to elements of the given collection.\n * \n * If any two elements would have the same key returned by [keySelector] the last one gets added to the map.\n * \n * The returned map preserves the entry iteration order of the original collection.\n */\npublic inline fun Iterable.associateBy(keySelector: (T) -> K, valueTransform: (T) -> V): Map {\n val capacity = mapCapacity(collectionSizeOrDefault(10)).coerceAtLeast(16)\n return associateByTo(LinkedHashMap(capacity), keySelector, valueTransform)\n}\n\n/**\n * Populates and returns the [destination] mutable map with key-value pairs,\n * where key is provided by the [keySelector] function applied to each element of the given collection\n * and value is the element itself.\n * \n * If any two elements would have the same key returned by [keySelector] the last one gets added to the map.\n */\npublic inline fun > Iterable.associateByTo(destination: M, keySelector: (T) -> K): M {\n for (element in this) {\n destination.put(keySelector(element), element)\n }\n return destination\n}\n\n/**\n * Populates and returns the [destination] mutable map with key-value pairs,\n * where key is provided by the [keySelector] function and\n * and value is provided by the [valueTransform] function applied to elements of the given collection.\n * \n * If any two elements would have the same key returned by [keySelector] the last one gets added to the map.\n */\npublic inline fun > Iterable.associateByTo(destination: M, keySelector: (T) -> K, valueTransform: (T) -> V): M {\n for (element in this) {\n destination.put(keySelector(element), valueTransform(element))\n }\n return destination\n}\n\n/**\n * Populates and returns the [destination] mutable map with key-value pairs\n * provided by [transform] function applied to each element of the given collection.\n * \n * If any of two pairs would have the same key the last one gets added to the map.\n */\npublic inline fun > Iterable.associateTo(destination: M, transform: (T) -> Pair): M {\n for (element in this) {\n destination += transform(element)\n }\n return destination\n}\n\n/**\n * Appends all elements to the given [destination] collection.\n */\npublic fun > Iterable.toCollection(destination: C): C {\n for (item in this) {\n destination.add(item)\n }\n return destination\n}\n\n/**\n * Returns a [HashSet] of all elements.\n */\npublic fun Iterable.toHashSet(): HashSet {\n return toCollection(HashSet(mapCapacity(collectionSizeOrDefault(12))))\n}\n\n/**\n * Returns a [List] containing all elements.\n */\npublic fun Iterable.toList(): List {\n if (this is Collection) {\n return when (size) {\n 0 -> emptyList()\n 1 -> listOf(if (this is List) get(0) else iterator().next())\n else -> this.toMutableList()\n }\n }\n return this.toMutableList().optimizeReadOnlyList()\n}\n\n/**\n * Returns a [MutableList] filled with all elements of this collection.\n */\npublic fun Iterable.toMutableList(): MutableList {\n if (this is Collection)\n return this.toMutableList()\n return toCollection(ArrayList())\n}\n\n/**\n * Returns a [MutableList] filled with all elements of this collection.\n */\npublic fun Collection.toMutableList(): MutableList {\n return ArrayList(this)\n}\n\n/**\n * Returns a [Set] of all elements.\n * \n * The returned set preserves the element iteration order of the original collection.\n */\npublic fun Iterable.toSet(): Set {\n if (this is Collection) {\n return when (size) {\n 0 -> emptySet()\n 1 -> setOf(if (this is List) this[0] else iterator().next())\n else -> toCollection(LinkedHashSet(mapCapacity(size)))\n }\n }\n return toCollection(LinkedHashSet()).optimizeReadOnlySet()\n}\n\n/**\n * Returns a single list of all elements yielded from results of [transform] function being invoked on each element of original collection.\n */\npublic inline fun Iterable.flatMap(transform: (T) -> Iterable): List {\n return flatMapTo(ArrayList(), transform)\n}\n\n/**\n * Appends all elements yielded from results of [transform] function being invoked on each element of original collection, to the given [destination].\n */\npublic inline fun > Iterable.flatMapTo(destination: C, transform: (T) -> Iterable): C {\n for (element in this) {\n val list = transform(element)\n destination.addAll(list)\n }\n return destination\n}\n\n/**\n * Groups elements of the original collection by the key returned by the given [keySelector] function\n * applied to each element and returns a map where each group key is associated with a list of corresponding elements.\n * \n * The returned map preserves the entry iteration order of the keys produced from the original collection.\n * \n * @sample samples.collections.Collections.Transformations.groupBy\n */\npublic inline fun Iterable.groupBy(keySelector: (T) -> K): Map> {\n return groupByTo(LinkedHashMap>(), keySelector)\n}\n\n/**\n * Groups values returned by the [valueTransform] function applied to each element of the original collection\n * by the key returned by the given [keySelector] function applied to the element\n * and returns a map where each group key is associated with a list of corresponding values.\n * \n * The returned map preserves the entry iteration order of the keys produced from the original collection.\n * \n * @sample samples.collections.Collections.Transformations.groupByKeysAndValues\n */\npublic inline fun Iterable.groupBy(keySelector: (T) -> K, valueTransform: (T) -> V): Map> {\n return groupByTo(LinkedHashMap>(), keySelector, valueTransform)\n}\n\n/**\n * Groups elements of the original collection by the key returned by the given [keySelector] function\n * applied to each element and puts to the [destination] map each group key associated with a list of corresponding elements.\n * \n * @return The [destination] map.\n * \n * @sample samples.collections.Collections.Transformations.groupBy\n */\npublic inline fun >> Iterable.groupByTo(destination: M, keySelector: (T) -> K): M {\n for (element in this) {\n val key = keySelector(element)\n val list = destination.getOrPut(key) { ArrayList() }\n list.add(element)\n }\n return destination\n}\n\n/**\n * Groups values returned by the [valueTransform] function applied to each element of the original collection\n * by the key returned by the given [keySelector] function applied to the element\n * and puts to the [destination] map each group key associated with a list of corresponding values.\n * \n * @return The [destination] map.\n * \n * @sample samples.collections.Collections.Transformations.groupByKeysAndValues\n */\npublic inline fun >> Iterable.groupByTo(destination: M, keySelector: (T) -> K, valueTransform: (T) -> V): M {\n for (element in this) {\n val key = keySelector(element)\n val list = destination.getOrPut(key) { ArrayList() }\n list.add(valueTransform(element))\n }\n return destination\n}\n\n/**\n * Creates a [Grouping] source from a collection to be used later with one of group-and-fold operations\n * using the specified [keySelector] function to extract a key from each element.\n * \n * @sample samples.collections.Collections.Transformations.groupingByEachCount\n */\n@SinceKotlin(\"1.1\")\npublic inline fun Iterable.groupingBy(crossinline keySelector: (T) -> K): Grouping {\n return object : Grouping {\n override fun sourceIterator(): Iterator = this@groupingBy.iterator()\n override fun keyOf(element: T): K = keySelector(element)\n }\n}\n\n/**\n * Returns a list containing the results of applying the given [transform] function\n * to each element in the original collection.\n */\npublic inline fun Iterable.map(transform: (T) -> R): List {\n return mapTo(ArrayList(collectionSizeOrDefault(10)), transform)\n}\n\n/**\n * Returns a list containing the results of applying the given [transform] function\n * to each element and its index in the original collection.\n * @param [transform] function that takes the index of an element and the element itself\n * and returns the result of the transform applied to the element.\n */\npublic inline fun Iterable.mapIndexed(transform: (index: Int, T) -> R): List {\n return mapIndexedTo(ArrayList(collectionSizeOrDefault(10)), transform)\n}\n\n/**\n * Returns a list containing only the non-null results of applying the given [transform] function\n * to each element and its index in the original collection.\n * @param [transform] function that takes the index of an element and the element itself\n * and returns the result of the transform applied to the element.\n */\npublic inline fun Iterable.mapIndexedNotNull(transform: (index: Int, T) -> R?): List {\n return mapIndexedNotNullTo(ArrayList(), transform)\n}\n\n/**\n * Applies the given [transform] function to each element and its index in the original collection\n * and appends only the non-null results to the given [destination].\n * @param [transform] function that takes the index of an element and the element itself\n * and returns the result of the transform applied to the element.\n */\npublic inline fun > Iterable.mapIndexedNotNullTo(destination: C, transform: (index: Int, T) -> R?): C {\n forEachIndexed { index, element -> transform(index, element)?.let { destination.add(it) } }\n return destination\n}\n\n/**\n * Applies the given [transform] function to each element and its index in the original collection\n * and appends the results to the given [destination].\n * @param [transform] function that takes the index of an element and the element itself\n * and returns the result of the transform applied to the element.\n */\npublic inline fun > Iterable.mapIndexedTo(destination: C, transform: (index: Int, T) -> R): C {\n var index = 0\n for (item in this)\n destination.add(transform(index++, item))\n return destination\n}\n\n/**\n * Returns a list containing only the non-null results of applying the given [transform] function\n * to each element in the original collection.\n */\npublic inline fun Iterable.mapNotNull(transform: (T) -> R?): List {\n return mapNotNullTo(ArrayList(), transform)\n}\n\n/**\n * Applies the given [transform] function to each element in the original collection\n * and appends only the non-null results to the given [destination].\n */\npublic inline fun > Iterable.mapNotNullTo(destination: C, transform: (T) -> R?): C {\n forEach { element -> transform(element)?.let { destination.add(it) } }\n return destination\n}\n\n/**\n * Applies the given [transform] function to each element of the original collection\n * and appends the results to the given [destination].\n */\npublic inline fun > Iterable.mapTo(destination: C, transform: (T) -> R): C {\n for (item in this)\n destination.add(transform(item))\n return destination\n}\n\n/**\n * Returns a lazy [Iterable] of [IndexedValue] for each element of the original collection.\n */\npublic fun Iterable.withIndex(): Iterable> {\n return IndexingIterable { iterator() }\n}\n\n/**\n * Returns a list containing only distinct elements from the given collection.\n * \n * The elements in the resulting list are in the same order as they were in the source collection.\n */\npublic fun Iterable.distinct(): List {\n return this.toMutableSet().toList()\n}\n\n/**\n * Returns a list containing only elements from the given collection\n * having distinct keys returned by the given [selector] function.\n * \n * The elements in the resulting list are in the same order as they were in the source collection.\n */\npublic inline fun Iterable.distinctBy(selector: (T) -> K): List {\n val set = HashSet()\n val list = ArrayList()\n for (e in this) {\n val key = selector(e)\n if (set.add(key))\n list.add(e)\n }\n return list\n}\n\n/**\n * Returns a set containing all elements that are contained by both this set and the specified collection.\n * \n * The returned set preserves the element iteration order of the original collection.\n */\npublic infix fun Iterable.intersect(other: Iterable): Set {\n val set = this.toMutableSet()\n set.retainAll(other)\n return set\n}\n\n/**\n * Returns a set containing all elements that are contained by this collection and not contained by the specified collection.\n * \n * The returned set preserves the element iteration order of the original collection.\n */\npublic infix fun Iterable.subtract(other: Iterable): Set {\n val set = this.toMutableSet()\n set.removeAll(other)\n return set\n}\n\n/**\n * Returns a mutable set containing all distinct elements from the given collection.\n * \n * The returned set preserves the element iteration order of the original collection.\n */\npublic fun Iterable.toMutableSet(): MutableSet {\n return when (this) {\n is Collection -> LinkedHashSet(this)\n else -> toCollection(LinkedHashSet())\n }\n}\n\n/**\n * Returns a set containing all distinct elements from both collections.\n * \n * The returned set preserves the element iteration order of the original collection.\n * Those elements of the [other] collection that are unique are iterated in the end\n * in the order of the [other] collection.\n */\npublic infix fun Iterable.union(other: Iterable): Set {\n val set = this.toMutableSet()\n set.addAll(other)\n return set\n}\n\n/**\n * Returns `true` if all elements match the given [predicate].\n * \n * @sample samples.collections.Collections.Aggregates.all\n */\npublic inline fun Iterable.all(predicate: (T) -> Boolean): Boolean {\n if (this is Collection && isEmpty()) return true\n for (element in this) if (!predicate(element)) return false\n return true\n}\n\n/**\n * Returns `true` if collection has at least one element.\n * \n * @sample samples.collections.Collections.Aggregates.any\n */\npublic fun Iterable.any(): Boolean {\n if (this is Collection) return !isEmpty()\n return iterator().hasNext()\n}\n\n/**\n * Returns `true` if at least one element matches the given [predicate].\n * \n * @sample samples.collections.Collections.Aggregates.anyWithPredicate\n */\npublic inline fun Iterable.any(predicate: (T) -> Boolean): Boolean {\n if (this is Collection && isEmpty()) return false\n for (element in this) if (predicate(element)) return true\n return false\n}\n\n/**\n * Returns the number of elements in this collection.\n */\npublic fun Iterable.count(): Int {\n if (this is Collection) return size\n var count = 0\n for (element in this) count++\n return count\n}\n\n/**\n * Returns the number of elements in this collection.\n */\n@kotlin.internal.InlineOnly\npublic inline fun Collection.count(): Int {\n return size\n}\n\n/**\n * Returns the number of elements matching the given [predicate].\n */\npublic inline fun Iterable.count(predicate: (T) -> Boolean): Int {\n if (this is Collection && isEmpty()) return 0\n var count = 0\n for (element in this) if (predicate(element)) count++\n return count\n}\n\n/**\n * Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each element.\n */\npublic inline fun Iterable.fold(initial: R, operation: (acc: R, T) -> R): R {\n var accumulator = initial\n for (element in this) accumulator = operation(accumulator, element)\n return accumulator\n}\n\n/**\n * Accumulates value starting with [initial] value and applying [operation] from left to right\n * to current accumulator value and each element with its index in the original collection.\n * @param [operation] function that takes the index of an element, current accumulator value\n * and the element itself, and calculates the next accumulator value.\n */\npublic inline fun Iterable.foldIndexed(initial: R, operation: (index: Int, acc: R, T) -> R): R {\n var index = 0\n var accumulator = initial\n for (element in this) accumulator = operation(index++, accumulator, element)\n return accumulator\n}\n\n/**\n * Accumulates value starting with [initial] value and applying [operation] from right to left to each element and current accumulator value.\n */\npublic inline fun List.foldRight(initial: R, operation: (T, acc: R) -> R): R {\n var accumulator = initial\n if (!isEmpty()) {\n val iterator = listIterator(size)\n while (iterator.hasPrevious()) {\n accumulator = operation(iterator.previous(), accumulator)\n }\n }\n return accumulator\n}\n\n/**\n * Accumulates value starting with [initial] value and applying [operation] from right to left\n * to each element with its index in the original list and current accumulator value.\n * @param [operation] function that takes the index of an element, the element itself\n * and current accumulator value, and calculates the next accumulator value.\n */\npublic inline fun List.foldRightIndexed(initial: R, operation: (index: Int, T, acc: R) -> R): R {\n var accumulator = initial\n if (!isEmpty()) {\n val iterator = listIterator(size)\n while (iterator.hasPrevious()) {\n val index = iterator.previousIndex()\n accumulator = operation(index, iterator.previous(), accumulator)\n }\n }\n return accumulator\n}\n\n/**\n * Performs the given [action] on each element.\n */\n@kotlin.internal.HidesMembers\npublic inline fun Iterable.forEach(action: (T) -> Unit): Unit {\n for (element in this) action(element)\n}\n\n/**\n * Performs the given [action] on each element, providing sequential index with the element.\n * @param [action] function that takes the index of an element and the element itself\n * and performs the desired action on the element.\n */\npublic inline fun Iterable.forEachIndexed(action: (index: Int, T) -> Unit): Unit {\n var index = 0\n for (item in this) action(index++, item)\n}\n\n/**\n * Returns the largest element or `null` if there are no elements.\n * \n * If any of elements is `NaN` returns `NaN`.\n */\n@SinceKotlin(\"1.1\")\npublic fun Iterable.max(): Double? {\n val iterator = iterator()\n if (!iterator.hasNext()) return null\n var max = iterator.next()\n if (max.isNaN()) return max\n while (iterator.hasNext()) {\n val e = iterator.next()\n if (e.isNaN()) return e\n if (max < e) max = e\n }\n return max\n}\n\n/**\n * Returns the largest element or `null` if there are no elements.\n * \n * If any of elements is `NaN` returns `NaN`.\n */\n@SinceKotlin(\"1.1\")\npublic fun Iterable.max(): Float? {\n val iterator = iterator()\n if (!iterator.hasNext()) return null\n var max = iterator.next()\n if (max.isNaN()) return max\n while (iterator.hasNext()) {\n val e = iterator.next()\n if (e.isNaN()) return e\n if (max < e) max = e\n }\n return max\n}\n\n/**\n * Returns the largest element or `null` if there are no elements.\n */\npublic fun > Iterable.max(): T? {\n val iterator = iterator()\n if (!iterator.hasNext()) return null\n var max = iterator.next()\n while (iterator.hasNext()) {\n val e = iterator.next()\n if (max < e) max = e\n }\n return max\n}\n\n/**\n * Returns the first element yielding the largest value of the given function or `null` if there are no elements.\n */\npublic inline fun > Iterable.maxBy(selector: (T) -> R): T? {\n val iterator = iterator()\n if (!iterator.hasNext()) return null\n var maxElem = iterator.next()\n var maxValue = selector(maxElem)\n while (iterator.hasNext()) {\n val e = iterator.next()\n val v = selector(e)\n if (maxValue < v) {\n maxElem = e\n maxValue = v\n }\n }\n return maxElem\n}\n\n/**\n * Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.\n */\npublic fun Iterable.maxWith(comparator: Comparator): T? {\n val iterator = iterator()\n if (!iterator.hasNext()) return null\n var max = iterator.next()\n while (iterator.hasNext()) {\n val e = iterator.next()\n if (comparator.compare(max, e) < 0) max = e\n }\n return max\n}\n\n/**\n * Returns the smallest element or `null` if there are no elements.\n * \n * If any of elements is `NaN` returns `NaN`.\n */\n@SinceKotlin(\"1.1\")\npublic fun Iterable.min(): Double? {\n val iterator = iterator()\n if (!iterator.hasNext()) return null\n var min = iterator.next()\n if (min.isNaN()) return min\n while (iterator.hasNext()) {\n val e = iterator.next()\n if (e.isNaN()) return e\n if (min > e) min = e\n }\n return min\n}\n\n/**\n * Returns the smallest element or `null` if there are no elements.\n * \n * If any of elements is `NaN` returns `NaN`.\n */\n@SinceKotlin(\"1.1\")\npublic fun Iterable.min(): Float? {\n val iterator = iterator()\n if (!iterator.hasNext()) return null\n var min = iterator.next()\n if (min.isNaN()) return min\n while (iterator.hasNext()) {\n val e = iterator.next()\n if (e.isNaN()) return e\n if (min > e) min = e\n }\n return min\n}\n\n/**\n * Returns the smallest element or `null` if there are no elements.\n */\npublic fun > Iterable.min(): T? {\n val iterator = iterator()\n if (!iterator.hasNext()) return null\n var min = iterator.next()\n while (iterator.hasNext()) {\n val e = iterator.next()\n if (min > e) min = e\n }\n return min\n}\n\n/**\n * Returns the first element yielding the smallest value of the given function or `null` if there are no elements.\n */\npublic inline fun > Iterable.minBy(selector: (T) -> R): T? {\n val iterator = iterator()\n if (!iterator.hasNext()) return null\n var minElem = iterator.next()\n var minValue = selector(minElem)\n while (iterator.hasNext()) {\n val e = iterator.next()\n val v = selector(e)\n if (minValue > v) {\n minElem = e\n minValue = v\n }\n }\n return minElem\n}\n\n/**\n * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.\n */\npublic fun Iterable.minWith(comparator: Comparator): T? {\n val iterator = iterator()\n if (!iterator.hasNext()) return null\n var min = iterator.next()\n while (iterator.hasNext()) {\n val e = iterator.next()\n if (comparator.compare(min, e) > 0) min = e\n }\n return min\n}\n\n/**\n * Returns `true` if the collection has no elements.\n * \n * @sample samples.collections.Collections.Aggregates.none\n */\npublic fun Iterable.none(): Boolean {\n if (this is Collection) return isEmpty()\n return !iterator().hasNext()\n}\n\n/**\n * Returns `true` if no elements match the given [predicate].\n * \n * @sample samples.collections.Collections.Aggregates.noneWithPredicate\n */\npublic inline fun Iterable.none(predicate: (T) -> Boolean): Boolean {\n if (this is Collection && isEmpty()) return true\n for (element in this) if (predicate(element)) return false\n return true\n}\n\n/**\n * Performs the given [action] on each element and returns the collection itself afterwards.\n */\n@SinceKotlin(\"1.1\")\npublic inline fun > C.onEach(action: (T) -> Unit): C {\n return apply { for (element in this) action(element) }\n}\n\n/**\n * Accumulates value starting with the first element and applying [operation] from left to right to current accumulator value and each element.\n */\npublic inline fun Iterable.reduce(operation: (acc: S, T) -> S): S {\n val iterator = this.iterator()\n if (!iterator.hasNext()) throw UnsupportedOperationException(\"Empty collection can't be reduced.\")\n var accumulator: S = iterator.next()\n while (iterator.hasNext()) {\n accumulator = operation(accumulator, iterator.next())\n }\n return accumulator\n}\n\n/**\n * Accumulates value starting with the first element and applying [operation] from left to right\n * to current accumulator value and each element with its index in the original collection.\n * @param [operation] function that takes the index of an element, current accumulator value\n * and the element itself and calculates the next accumulator value.\n */\npublic inline fun Iterable.reduceIndexed(operation: (index: Int, acc: S, T) -> S): S {\n val iterator = this.iterator()\n if (!iterator.hasNext()) throw UnsupportedOperationException(\"Empty collection can't be reduced.\")\n var index = 1\n var accumulator: S = iterator.next()\n while (iterator.hasNext()) {\n accumulator = operation(index++, accumulator, iterator.next())\n }\n return accumulator\n}\n\n/**\n * Accumulates value starting with last element and applying [operation] from right to left to each element and current accumulator value.\n */\npublic inline fun List.reduceRight(operation: (T, acc: S) -> S): S {\n val iterator = listIterator(size)\n if (!iterator.hasPrevious())\n throw UnsupportedOperationException(\"Empty list can't be reduced.\")\n var accumulator: S = iterator.previous()\n while (iterator.hasPrevious()) {\n accumulator = operation(iterator.previous(), accumulator)\n }\n return accumulator\n}\n\n/**\n * Accumulates value starting with last element and applying [operation] from right to left\n * to each element with its index in the original list and current accumulator value.\n * @param [operation] function that takes the index of an element, the element itself\n * and current accumulator value, and calculates the next accumulator value.\n */\npublic inline fun List.reduceRightIndexed(operation: (index: Int, T, acc: S) -> S): S {\n val iterator = listIterator(size)\n if (!iterator.hasPrevious())\n throw UnsupportedOperationException(\"Empty list can't be reduced.\")\n var accumulator: S = iterator.previous()\n while (iterator.hasPrevious()) {\n val index = iterator.previousIndex()\n accumulator = operation(index, iterator.previous(), accumulator)\n }\n return accumulator\n}\n\n/**\n * Returns the sum of all values produced by [selector] function applied to each element in the collection.\n */\npublic inline fun Iterable.sumBy(selector: (T) -> Int): Int {\n var sum: Int = 0\n for (element in this) {\n sum += selector(element)\n }\n return sum\n}\n\n/**\n * Returns the sum of all values produced by [selector] function applied to each element in the collection.\n */\npublic inline fun Iterable.sumByDouble(selector: (T) -> Double): Double {\n var sum: Double = 0.0\n for (element in this) {\n sum += selector(element)\n }\n return sum\n}\n\n/**\n * Returns an original collection containing all the non-`null` elements, throwing an [IllegalArgumentException] if there are any `null` elements.\n */\npublic fun Iterable.requireNoNulls(): Iterable {\n for (element in this) {\n if (element == null) {\n throw IllegalArgumentException(\"null element found in $this.\")\n }\n }\n @Suppress(\"UNCHECKED_CAST\")\n return this as Iterable\n}\n\n/**\n * Returns an original collection containing all the non-`null` elements, throwing an [IllegalArgumentException] if there are any `null` elements.\n */\npublic fun List.requireNoNulls(): List {\n for (element in this) {\n if (element == null) {\n throw IllegalArgumentException(\"null element found in $this.\")\n }\n }\n @Suppress(\"UNCHECKED_CAST\")\n return this as List\n}\n\n/**\n * Splits this collection into a list of lists each not exceeding the given [size].\n * \n * The last list in the resulting list may have less elements than the given [size].\n * \n * @param size the number of elements to take in each list, must be positive and can be greater than the number of elements in this collection.\n * \n * @sample samples.collections.Collections.Transformations.chunked\n */\n@SinceKotlin(\"1.2\")\npublic fun Iterable.chunked(size: Int): List> {\n return windowed(size, size, partialWindows = true)\n}\n\n/**\n * Splits this collection into several lists each not exceeding the given [size]\n * and applies the given [transform] function to an each.\n * \n * @return list of results of the [transform] applied to an each list.\n * \n * Note that the list passed to the [transform] function is ephemeral and is valid only inside that function.\n * You should not store it or allow it to escape in some way, unless you made a snapshot of it.\n * The last list may have less elements than the given [size].\n * \n * @param size the number of elements to take in each list, must be positive and can be greater than the number of elements in this collection.\n * \n * @sample samples.text.Strings.chunkedTransform\n */\n@SinceKotlin(\"1.2\")\npublic fun Iterable.chunked(size: Int, transform: (List) -> R): List {\n return windowed(size, size, partialWindows = true, transform = transform)\n}\n\n/**\n * Returns a list containing all elements of the original collection without the first occurrence of the given [element].\n */\npublic operator fun Iterable.minus(element: T): List {\n val result = ArrayList(collectionSizeOrDefault(10))\n var removed = false\n return this.filterTo(result) { if (!removed && it == element) { removed = true; false } else true }\n}\n\n/**\n * Returns a list containing all elements of the original collection except the elements contained in the given [elements] array.\n */\npublic operator fun Iterable.minus(elements: Array): List {\n if (elements.isEmpty()) return this.toList()\n val other = elements.toHashSet()\n return this.filterNot { it in other }\n}\n\n/**\n * Returns a list containing all elements of the original collection except the elements contained in the given [elements] collection.\n */\npublic operator fun Iterable.minus(elements: Iterable): List {\n val other = elements.convertToSetForSetOperationWith(this)\n if (other.isEmpty())\n return this.toList()\n return this.filterNot { it in other }\n}\n\n/**\n * Returns a list containing all elements of the original collection except the elements contained in the given [elements] sequence.\n */\npublic operator fun Iterable.minus(elements: Sequence): List {\n val other = elements.toHashSet()\n if (other.isEmpty())\n return this.toList()\n return this.filterNot { it in other }\n}\n\n/**\n * Returns a list containing all elements of the original collection without the first occurrence of the given [element].\n */\n@kotlin.internal.InlineOnly\npublic inline fun Iterable.minusElement(element: T): List {\n return minus(element)\n}\n\n/**\n * Splits the original collection into pair of lists,\n * where *first* list contains elements for which [predicate] yielded `true`,\n * while *second* list contains elements for which [predicate] yielded `false`.\n */\npublic inline fun Iterable.partition(predicate: (T) -> Boolean): Pair, List> {\n val first = ArrayList()\n val second = ArrayList()\n for (element in this) {\n if (predicate(element)) {\n first.add(element)\n } else {\n second.add(element)\n }\n }\n return Pair(first, second)\n}\n\n/**\n * Returns a list containing all elements of the original collection and then the given [element].\n */\npublic operator fun Iterable.plus(element: T): List {\n if (this is Collection) return this.plus(element)\n val result = ArrayList()\n result.addAll(this)\n result.add(element)\n return result\n}\n\n/**\n * Returns a list containing all elements of the original collection and then the given [element].\n */\npublic operator fun Collection.plus(element: T): List {\n val result = ArrayList(size + 1)\n result.addAll(this)\n result.add(element)\n return result\n}\n\n/**\n * Returns a list containing all elements of the original collection and then all elements of the given [elements] array.\n */\npublic operator fun Iterable.plus(elements: Array): List {\n if (this is Collection) return this.plus(elements)\n val result = ArrayList()\n result.addAll(this)\n result.addAll(elements)\n return result\n}\n\n/**\n * Returns a list containing all elements of the original collection and then all elements of the given [elements] array.\n */\npublic operator fun Collection.plus(elements: Array): List {\n val result = ArrayList(this.size + elements.size)\n result.addAll(this)\n result.addAll(elements)\n return result\n}\n\n/**\n * Returns a list containing all elements of the original collection and then all elements of the given [elements] collection.\n */\npublic operator fun Iterable.plus(elements: Iterable): List {\n if (this is Collection) return this.plus(elements)\n val result = ArrayList()\n result.addAll(this)\n result.addAll(elements)\n return result\n}\n\n/**\n * Returns a list containing all elements of the original collection and then all elements of the given [elements] collection.\n */\npublic operator fun Collection.plus(elements: Iterable): List {\n if (elements is Collection) {\n val result = ArrayList(this.size + elements.size)\n result.addAll(this)\n result.addAll(elements)\n return result\n } else {\n val result = ArrayList(this)\n result.addAll(elements)\n return result\n }\n}\n\n/**\n * Returns a list containing all elements of the original collection and then all elements of the given [elements] sequence.\n */\npublic operator fun Iterable.plus(elements: Sequence): List {\n val result = ArrayList()\n result.addAll(this)\n result.addAll(elements)\n return result\n}\n\n/**\n * Returns a list containing all elements of the original collection and then all elements of the given [elements] sequence.\n */\npublic operator fun Collection.plus(elements: Sequence): List {\n val result = ArrayList(this.size + 10)\n result.addAll(this)\n result.addAll(elements)\n return result\n}\n\n/**\n * Returns a list containing all elements of the original collection and then the given [element].\n */\n@kotlin.internal.InlineOnly\npublic inline fun Iterable.plusElement(element: T): List {\n return plus(element)\n}\n\n/**\n * Returns a list containing all elements of the original collection and then the given [element].\n */\n@kotlin.internal.InlineOnly\npublic inline fun Collection.plusElement(element: T): List {\n return plus(element)\n}\n\n/**\n * Returns a list of snapshots of the window of the given [size]\n * sliding along this collection with the given [step], where each\n * snapshot is a list.\n * \n * Several last lists may have less elements than the given [size].\n * \n * Both [size] and [step] must be positive and can be greater than the number of elements in this collection.\n * @param size the number of elements to take in each window\n * @param step the number of elements to move the window forward by on an each step, by default 1\n * @param partialWindows controls whether or not to keep partial windows in the end if any,\n * by default `false` which means partial windows won't be preserved\n * \n * @sample samples.collections.Sequences.Transformations.takeWindows\n */\n@SinceKotlin(\"1.2\")\npublic fun Iterable.windowed(size: Int, step: Int = 1, partialWindows: Boolean = false): List> {\n checkWindowSizeStep(size, step)\n if (this is RandomAccess && this is List) {\n val thisSize = this.size\n val result = ArrayList>((thisSize + step - 1) / step)\n var index = 0\n while (index < thisSize) {\n val windowSize = size.coerceAtMost(thisSize - index)\n if (windowSize < size && !partialWindows) break\n result.add(List(windowSize) { this[it + index] })\n index += step\n }\n return result\n }\n val result = ArrayList>()\n windowedIterator(iterator(), size, step, partialWindows, reuseBuffer = false).forEach {\n result.add(it)\n }\n return result\n}\n\n/**\n * Returns a list of results of applying the given [transform] function to\n * an each list representing a view over the window of the given [size]\n * sliding along this collection with the given [step].\n * \n * Note that the list passed to the [transform] function is ephemeral and is valid only inside that function.\n * You should not store it or allow it to escape in some way, unless you made a snapshot of it.\n * Several last lists may have less elements than the given [size].\n * \n * Both [size] and [step] must be positive and can be greater than the number of elements in this collection.\n * @param size the number of elements to take in each window\n * @param step the number of elements to move the window forward by on an each step, by default 1\n * @param partialWindows controls whether or not to keep partial windows in the end if any,\n * by default `false` which means partial windows won't be preserved\n * \n * @sample samples.collections.Sequences.Transformations.averageWindows\n */\n@SinceKotlin(\"1.2\")\npublic fun Iterable.windowed(size: Int, step: Int = 1, partialWindows: Boolean = false, transform: (List) -> R): List {\n checkWindowSizeStep(size, step)\n if (this is RandomAccess && this is List) {\n val thisSize = this.size\n val result = ArrayList((thisSize + step - 1) / step)\n val window = MovingSubList(this)\n var index = 0\n while (index < thisSize) {\n window.move(index, (index + size).coerceAtMost(thisSize))\n if (!partialWindows && window.size < size) break\n result.add(transform(window))\n index += step\n }\n return result\n }\n val result = ArrayList()\n windowedIterator(iterator(), size, step, partialWindows, reuseBuffer = true).forEach {\n result.add(transform(it))\n }\n return result\n}\n\n/**\n * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.\n */\npublic infix fun Iterable.zip(other: Array): List> {\n return zip(other) { t1, t2 -> t1 to t2 }\n}\n\n/**\n * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.\n */\npublic inline fun Iterable.zip(other: Array, transform: (a: T, b: R) -> V): List {\n val arraySize = other.size\n val list = ArrayList(minOf(collectionSizeOrDefault(10), arraySize))\n var i = 0\n for (element in this) {\n if (i >= arraySize) break\n list.add(transform(element, other[i++]))\n }\n return list\n}\n\n/**\n * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.\n */\npublic infix fun Iterable.zip(other: Iterable): List> {\n return zip(other) { t1, t2 -> t1 to t2 }\n}\n\n/**\n * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.\n */\npublic inline fun Iterable.zip(other: Iterable, transform: (a: T, b: R) -> V): List {\n val first = iterator()\n val second = other.iterator()\n val list = ArrayList(minOf(collectionSizeOrDefault(10), other.collectionSizeOrDefault(10)))\n while (first.hasNext() && second.hasNext()) {\n list.add(transform(first.next(), second.next()))\n }\n return list\n}\n\n/**\n * Returns a list of pairs of each two adjacent elements in this collection.\n * \n * The returned list is empty if this collection contains less than two elements.\n * \n * @sample samples.collections.Collections.Transformations.zipWithNext\n */\n@SinceKotlin(\"1.2\")\npublic fun Iterable.zipWithNext(): List> {\n return zipWithNext { a, b -> a to b }\n}\n\n/**\n * Returns a list containing the results of applying the given [transform] function\n * to an each pair of two adjacent elements in this collection.\n * \n * The returned list is empty if this collection contains less than two elements.\n * \n * @sample samples.collections.Collections.Transformations.zipWithNextToFindDeltas\n */\n@SinceKotlin(\"1.2\")\npublic inline fun Iterable.zipWithNext(transform: (a: T, b: T) -> R): List {\n val iterator = iterator()\n if (!iterator.hasNext()) return emptyList()\n val result = mutableListOf()\n var current = iterator.next()\n while (iterator.hasNext()) {\n val next = iterator.next()\n result.add(transform(current, next))\n current = next\n }\n return result\n}\n\n/**\n * Appends the string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied.\n * \n * If the collection could be huge, you can specify a non-negative value of [limit], in which case only the first [limit]\n * elements will be appended, followed by the [truncated] string (which defaults to \"...\").\n * \n * @sample samples.collections.Collections.Transformations.joinTo\n */\npublic fun Iterable.joinTo(buffer: A, separator: CharSequence = \", \", prefix: CharSequence = \"\", postfix: CharSequence = \"\", limit: Int = -1, truncated: CharSequence = \"...\", transform: ((T) -> CharSequence)? = null): A {\n buffer.append(prefix)\n var count = 0\n for (element in this) {\n if (++count > 1) buffer.append(separator)\n if (limit < 0 || count <= limit) {\n buffer.appendElement(element, transform)\n } else break\n }\n if (limit >= 0 && count > limit) buffer.append(truncated)\n buffer.append(postfix)\n return buffer\n}\n\n/**\n * Creates a string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied.\n * \n * If the collection could be huge, you can specify a non-negative value of [limit], in which case only the first [limit]\n * elements will be appended, followed by the [truncated] string (which defaults to \"...\").\n * \n * @sample samples.collections.Collections.Transformations.joinToString\n */\npublic fun Iterable.joinToString(separator: CharSequence = \", \", prefix: CharSequence = \"\", postfix: CharSequence = \"\", limit: Int = -1, truncated: CharSequence = \"...\", transform: ((T) -> CharSequence)? = null): String {\n return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()\n}\n\n/**\n * Returns this collection as an [Iterable].\n */\n@kotlin.internal.InlineOnly\npublic inline fun Iterable.asIterable(): Iterable {\n return this\n}\n\n/**\n * Creates a [Sequence] instance that wraps the original collection returning its elements when being iterated.\n * \n * @sample samples.collections.Sequences.Building.sequenceFromCollection\n */\npublic fun Iterable.asSequence(): Sequence {\n return Sequence { this.iterator() }\n}\n\n/**\n * Returns an average value of elements in the collection.\n */\n@kotlin.jvm.JvmName(\"averageOfByte\")\npublic fun Iterable.average(): Double {\n var sum: Double = 0.0\n var count: Int = 0\n for (element in this) {\n sum += element\n count += 1\n }\n return if (count == 0) Double.NaN else sum / count\n}\n\n/**\n * Returns an average value of elements in the collection.\n */\n@kotlin.jvm.JvmName(\"averageOfShort\")\npublic fun Iterable.average(): Double {\n var sum: Double = 0.0\n var count: Int = 0\n for (element in this) {\n sum += element\n count += 1\n }\n return if (count == 0) Double.NaN else sum / count\n}\n\n/**\n * Returns an average value of elements in the collection.\n */\n@kotlin.jvm.JvmName(\"averageOfInt\")\npublic fun Iterable.average(): Double {\n var sum: Double = 0.0\n var count: Int = 0\n for (element in this) {\n sum += element\n count += 1\n }\n return if (count == 0) Double.NaN else sum / count\n}\n\n/**\n * Returns an average value of elements in the collection.\n */\n@kotlin.jvm.JvmName(\"averageOfLong\")\npublic fun Iterable.average(): Double {\n var sum: Double = 0.0\n var count: Int = 0\n for (element in this) {\n sum += element\n count += 1\n }\n return if (count == 0) Double.NaN else sum / count\n}\n\n/**\n * Returns an average value of elements in the collection.\n */\n@kotlin.jvm.JvmName(\"averageOfFloat\")\npublic fun Iterable.average(): Double {\n var sum: Double = 0.0\n var count: Int = 0\n for (element in this) {\n sum += element\n count += 1\n }\n return if (count == 0) Double.NaN else sum / count\n}\n\n/**\n * Returns an average value of elements in the collection.\n */\n@kotlin.jvm.JvmName(\"averageOfDouble\")\npublic fun Iterable.average(): Double {\n var sum: Double = 0.0\n var count: Int = 0\n for (element in this) {\n sum += element\n count += 1\n }\n return if (count == 0) Double.NaN else sum / count\n}\n\n/**\n * Returns the sum of all elements in the collection.\n */\n@kotlin.jvm.JvmName(\"sumOfByte\")\npublic fun Iterable.sum(): Int {\n var sum: Int = 0\n for (element in this) {\n sum += element\n }\n return sum\n}\n\n/**\n * Returns the sum of all elements in the collection.\n */\n@kotlin.jvm.JvmName(\"sumOfShort\")\npublic fun Iterable.sum(): Int {\n var sum: Int = 0\n for (element in this) {\n sum += element\n }\n return sum\n}\n\n/**\n * Returns the sum of all elements in the collection.\n */\n@kotlin.jvm.JvmName(\"sumOfInt\")\npublic fun Iterable.sum(): Int {\n var sum: Int = 0\n for (element in this) {\n sum += element\n }\n return sum\n}\n\n/**\n * Returns the sum of all elements in the collection.\n */\n@kotlin.jvm.JvmName(\"sumOfLong\")\npublic fun Iterable.sum(): Long {\n var sum: Long = 0L\n for (element in this) {\n sum += element\n }\n return sum\n}\n\n/**\n * Returns the sum of all elements in the collection.\n */\n@kotlin.jvm.JvmName(\"sumOfFloat\")\npublic fun Iterable.sum(): Float {\n var sum: Float = 0.0f\n for (element in this) {\n sum += element\n }\n return sum\n}\n\n/**\n * Returns the sum of all elements in the collection.\n */\n@kotlin.jvm.JvmName(\"sumOfDouble\")\npublic fun Iterable.sum(): Double {\n var sum: Double = 0.0\n for (element in this) {\n sum += element\n }\n return sum\n}\n\n"],"names":[],"mappings":"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"} \ No newline at end of file diff --git a/functions/index.meta.js b/functions/index.meta.js deleted file mode 100644 index 7cb6169..0000000 --- a/functions/index.meta.js +++ /dev/null @@ -1 +0,0 @@ -// Kotlin.kotlin_module_metadata(66049, "index", "H4sIAAAAAAAAAJVUTVMTQRDNfmR30knIuAiEBRVBRVFwCWh5BcFCSikraJXXZTNFttzsxN1ByN3iB3jy4MmDR8/+Af0J/B57JkNY8ORl35t+Pd39eqq2RCzvJ8BvCxyeJnHKgERx2u+GmYBKEqYsT+J+DuXtVGQDcD5wgUlgbaQDIOwTS8XeQQbWy1RAWR3B2RdZnB6CLS+D3WWhADc/jns9loEtWNgDiHivz1PMXi3wVoGvFfh6gT8p8KdgR7yPM7GPR2GSg7vJecLCFMpcdLEX6YZ59znvoCPBz4d6zZgAuye/LtbIYpZDNeJJwiIR8zQH+1WcS+2kzzOBRfewmLzpDZ2vbA3SsBdHbwd9rBvmb3icYpqzxY8OEgZmhO46WXi8hb2xtP0ujQVYHR5BrTtAQbDhIstMQVUH1VhuLJg84OrkDHYvxE3bYXaI69/IsnAAboZe44yB0+OdI+xXOc7w0j4+ERgnYAy8DExaApuUqIFfg5rgEJNazRLGbeQ2LSOX6GqsaJxUaFK/Ke/b9AaegN7U6pzGBY33ND5ulvxvpj9N7/pmMNYao4s+zN1esptGUA5qv0gJpfsoWSg9+FdaQqmC0sxVaZE+9KlX8wrhoIqJj64mTtFl1blGV3zi2Z4ZuEFDCrM0KOa2HLqKie7O6ZxUl2lLXlsaTrZ4JXMNNQdxXSKmz0/QW8WU96efDRlu0HnMqGOV+rMXw8CdS4GvxJz/bpJT0rRaZlDeDDyHOrIoIpHjIII+VzXWdLwucbdCx2R854+FtKEcKEovotcuqHeRMH5Ot+l19QAEH1f1Vkx1VwxGseqI1UZqfVjG2B2nE0hJi9ApX61h50y2aarmZwbSaZV6ZrS1t7b22tbe2tprW3tsa49ycT8MuaSKWtIkmp9RS6jRWf2oVlDVq1CeGriKkSADC8pkRY2s7rbGkM0Wk/7LwqXObT0PDvqFmFDy9W/wL9qlo788BQAA"); diff --git a/functions/index/online/cinphart/laneslips/laneslips.kjsm b/functions/index/online/cinphart/laneslips/laneslips.kjsm deleted file mode 100644 index 33dad65..0000000 Binary files a/functions/index/online/cinphart/laneslips/laneslips.kjsm and /dev/null differ diff --git a/local-test-curl.sh b/local-test-curl.sh index 886bd7a..527a507 100644 --- a/local-test-curl.sh +++ b/local-test-curl.sh @@ -9,7 +9,7 @@ curl -O -J -H "Content-Type: application/json" 'http://localhost:5000/swimteamma "event":"Girls 8&U 100 Yd Medley Relay", "lane":1, "heat":1, -"swimmer":"A", +"swimmer":"This is a really really really long name to see what happens", "team":"Delshire" }, { diff --git a/local-test-heats.sh b/local-test-heats.sh new file mode 100644 index 0000000..0b241bc --- /dev/null +++ b/local-test-heats.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +curl -O -J -H "Content-Type: application/json" 'http://localhost:5000/swimteammanager-179e8/us-central1/heatSheets' -d ' +{ +"meet":"Delshire vs Woodhaven", +"entries":[ +{ +"eventNbr":1, +"event":"Girls 8&U 100 Yd Medley Relay", +"lane":1, +"heat":1, +"swimmer":"This is a really really really long name to see what happens", +"team":"Delshire" +}, +{ +"eventNbr":1, +"event":"Girls 8&U 100 Yd Medley Relay", +"lane":1, +"heat":1, +"swimmer":"A", +"team":"Delshire" +}, +{ +"eventNbr":1, +"event":"Girls 8&U 100 Yd Medley Relay", +"lane":1, +"heat":1, +"swimmer":"A", +"team":"Delshire" +}, +{ +"eventNbr":1, +"event":"Girls 8&U 100 Yd Medley Relay", +"lane":1, +"heat":1, +"swimmer":"A", +"team":"Delshire" +}, +{ +"eventNbr":1, +"event":"Girls 8&U 100 Yd Medley Relay", +"lane":1, +"heat":1, +"swimmer":"A", +"team":"Delshire" +}, +{ +"eventNbr":1, +"event":"Girls 8&U 100 Yd Medley Relay", +"lane":1, +"heat":1, +"swimmer":"A", +"team":"Delshire" +}, +{ +"eventNbr":1, +"event":"Girls 8&U 100 Yd Medley Relay", +"lane":1, +"heat":1, +"swimmer":"A", +"team":"Delshire" +}, +{ +"eventNbr":1, +"event":"Girls 8&U 100 Yd Medley Relay", +"lane":1, +"heat":1, +"swimmer":"A", +"team":"Delshire" +}, +{ +"eventNbr":1, +"event":"Girls 8&U 100 Yd Medley Relay", +"lane":1, +"heat":1, +"swimmer":"A", +"team":"Delshire" +}, +{ +"eventNbr":1, +"event":"Girls 8&U 100 Yd Medley Relay", +"lane":1, +"heat":1, +"swimmer":"A", +"team":"Delshire" +} +] +}' diff --git a/src/main/kotlin/online/cinphart/laneslips/Generator.kt b/src/main/kotlin/online/cinphart/laneslips/Generator.kt index 0bb09fa..6340f5a 100644 --- a/src/main/kotlin/online/cinphart/laneslips/Generator.kt +++ b/src/main/kotlin/online/cinphart/laneslips/Generator.kt @@ -31,7 +31,7 @@ fun main(args: Array) { exports.laneslips = fireFunctions.https.onRequest { req, res -> val doc = js("new (require('pdfkit'))({autoFirstPage:false})") - + val margins = js("{margin:18}") val meetInfo = hydrateMeet(req.body) res.setHeader("Content-Disposition", "attachment;filename=\"lane-slips-${meetInfo.meet}.pdf\"") @@ -39,32 +39,60 @@ fun main(args: Array) { doc.pipe(res) - meetInfo.entries.chunked(6).forEach { - doc.addPage() + meetInfo.entries + .sortedWith(compareBy({it.lane},{it.eventNbr},{it.heat})) + .chunked(6).forEach { + doc.addPage(margins) + drawDashes(doc) it.forEachIndexed { index, slip -> slip.writeSlip(doc, index % 2, index / 2) } - drawDashes(doc) } doc.end() } + + exports.heatSheets = fireFunctions.https.onRequest { req, res -> + val doc = js("new (require('pdfkit'))({autoFirstPage:false})") + val margins = js("{margin:18}") + val meetInfo = hydrateMeet(req.body) + + res.setHeader("Content-Disposition", "attachment;filename=\"heat-sheet-${meetInfo.meet}.pdf\"") + res.setHeader("Content-Type", "application/pdf") + + doc.pipe(res) + + meetInfo.entries + .sortedWith(compareBy({it.eventNbr},{it.heat},{it.lane})) + .chunked(6).forEach { + doc.addPage(margins) + drawDashes(doc) + it.forEachIndexed { index, slip -> + slip.writeSlip(doc, index % 2, index / 2) + } + } + doc.end() + } } fun drawDashes(doc : dynamic) { val dashOptions = js("{}") dashOptions.space = 10 + doc.save() + doc.moveTo(10.25.cm.asPoints, 1.0.cm.asPoints).lineTo(10.25.cm.asPoints, 27.0.cm.asPoints).dash(5, dashOptions).stroke() - doc.moveTo(1.0.cm.asPoints, 9.5.cm.asPoints).lineTo(21.0.cm.asPoints, 9.5.cm.asPoints).dash(5, dashOptions).stroke() + doc.moveTo(1.0.cm.asPoints, 10.0.cm.asPoints).lineTo(21.0.cm.asPoints, 10.0.cm.asPoints).dash(5, dashOptions).stroke() - doc.moveTo(1.0.cm.asPoints, 18.5.cm.asPoints).lineTo(21.0.cm.asPoints, 18.5.cm.asPoints).dash(5, dashOptions).stroke() + doc.moveTo(1.0.cm.asPoints, 19.0.cm.asPoints).lineTo(21.0.cm.asPoints, 19.0.cm.asPoints).dash(5, dashOptions).stroke() + + doc.restore() } fun Entry.writeSlip(doc: dynamic, x: Int, y: Int) { val xOffset = 10.0.cm.asPoints * x - val yOffset = 8.0.cm.asPoints * y - val leftMargin = 0.9.cm.asPoints + xOffset + val yOffset = 9.0.cm.asPoints * y + val leftMargin = 1.0.cm.asPoints + xOffset val opts = js("{}") opts.width=8.5.cm.asPoints @@ -82,7 +110,7 @@ fun Entry.writeSlip(doc: dynamic, x: Int, y: Int) { val eventY = 2.3.cm.asPoints + yOffset doc.text("EVENT #${eventNbr} - ${event}", leftMargin, eventY) - val lineSeparation = 1.0.cm.asPoints + val lineSeparation = 0.75.cm.asPoints val laneY = eventY + lineSeparation doc.text("Lane:", leftMargin, laneY) @@ -111,13 +139,13 @@ fun Entry.writeSlip(doc: dynamic, x: Int, y: Int) { val nameY = heatY + lineSeparation - doc.text("Name: $swimmer", leftMargin, nameY) + doc.text("Name: $swimmer", leftMargin, nameY, js("{width:288,align:'left',height:28}")) - val teamY = nameY + lineSeparation + val teamY = nameY + lineSeparation * 1.25 doc.text("Team: $team", leftMargin, teamY) - val timesY = teamY + lineSeparation * 1.5 + val timesY = teamY + lineSeparation * 1.25 doc.text("Times:", leftMargin, timesY) doc.moveTo(leftMargin + colWidth, timesY + 14)