{"id":15297326,"url":"https://github.com/datafabricrus/resource-iterator","last_synced_at":"2026-05-04T12:39:31.797Z","repository":{"id":209508661,"uuid":"724213764","full_name":"DataFabricRus/resource-iterator","owner":"DataFabricRus","description":"A simple Kotlin library providing ResourceIterator which is an AutoCloseable kotlin Iterator","archived":false,"fork":false,"pushed_at":"2024-12-20T08:13:24.000Z","size":108,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T13:14:57.012Z","etag":null,"topics":["closeable","iterator","js","jvm","jvm-library","kotlin","kotlin-library","kotlin-sequence","multiplatform-kotlin-library","sequence"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DataFabricRus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-27T16:16:25.000Z","updated_at":"2024-12-19T06:19:22.000Z","dependencies_parsed_at":"2023-11-27T18:51:19.201Z","dependency_job_id":"3af844d1-7a20-4688-a001-06840911db00","html_url":"https://github.com/DataFabricRus/resource-iterator","commit_stats":null,"previous_names":["datafabricrus/resource-iterator"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataFabricRus%2Fresource-iterator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataFabricRus%2Fresource-iterator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataFabricRus%2Fresource-iterator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataFabricRus%2Fresource-iterator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DataFabricRus","download_url":"https://codeload.github.com/DataFabricRus/resource-iterator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245467615,"owners_count":20620216,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["closeable","iterator","js","jvm","jvm-library","kotlin","kotlin-library","kotlin-sequence","multiplatform-kotlin-library","sequence"],"created_at":"2024-09-30T19:16:42.325Z","updated_at":"2026-05-04T12:39:31.718Z","avatar_url":"https://github.com/DataFabricRus.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Resource Iterator\n\n[![](https://jitpack.io/v/DataFabricRus/resource-iterator.svg)](https://jitpack.io/#DataFabricRus/resource-iterator)\n\nA simple kotlin library providing `ResourceIterator`,\nwhich is an extended `kotlin.collections.Iterator` implementing `AutoCloseable` interface:\n\n```kotlin\ninterface ResourceIterator\u003cout X\u003e : Iterator\u003cX\u003e, AutoCloseable {\n    ...\n}\n```\n\nThe standard kotlin-stdlib does not contain `Sequence` or `Iterator` which implement `AutoCloseable` interface\n(e.g., see open discussion: [KT-34719](https://youtrack.jetbrains.com/issue/KT-34719/Closeable-Sequences)).\n\nThis library complements the standard kotlin functionality with an extended iterator\nas well as various utility methods such as `flatMap`, `filter`, etc., similar to `Sequence` methods.\nEach of these methods produces a subsequent `ResourceIterator`, closing which also closes the source iterator.\nThe `ResourceIterator` extends `Iterator`, not `Sequence`, since it is hard to control every standard method-extension\nof `Sequence`.\n\n#### Known alternatives:\n\n- JDK `java.util.stream.Stream`\n- Apache Jena `org.apache.jena.util.iterator.ExtendedIterator`\n- Apache Kafka `org.apache.kafka.common.utils.CloseableIterator`\n\n#### When to use:\n\nIf you have some resources which need to be closed after or during iteration,\nand you don't want to use JDK or some external heavy library.\nFor example, `ResourceIterator` is used by [textfile-utils](https://github.com/DataFabricRus/textfile-utils)\n(see `cc.datafabric.textfileutils.files.LineReade.kt`).\n\n#### Examples of use:\n\n```kotlin\n// with standard collections:\nlistOf\u003cLong\u003e(1, 2).asResourceIterator { println(\"close outer\") }\n    .flatMap { x -\u003e\n        resourceIteratorOf(21 * x, 42 * x) { println(\"close inner for $x\") }\n    }\n    .filter { it \u003e 0 }\n    .use {\n        println(\"it = ${it.firstOrNull()}\")\n    }\n```\n\n```kotlin\n// with jdbc:\nfun \u003cX\u003e Connection.executeQuery(\n    query: String,\n    extractor: (ResultSet) -\u003e X,\n    exec: PreparedStatement.() -\u003e ResultSet\n): ResourceIterator\u003cX\u003e {\n    val statement = prepareStatement(query)\n    val rs = statement.exec()\n    return generateResourceIterator({ if (rs.next()) extractor(rs) else null }) { statement.close() }\n}\n```\n\n#### Available via maven-central:\n\n```kotlin\ndependencies {\n    implementation(\"io.github.datafabricrus:resource-iterator-jvm:{{latest_version}}\")\n}\n```\n\n#### Apache License Version 2.0","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatafabricrus%2Fresource-iterator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatafabricrus%2Fresource-iterator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatafabricrus%2Fresource-iterator/lists"}