{"id":20340381,"url":"https://github.com/toolisticon/krid","last_synced_at":"2025-06-20T02:37:56.576Z","repository":{"id":36967092,"uuid":"406118926","full_name":"toolisticon/krid","owner":"toolisticon","description":"library to support two dimensional kotlin grids","archived":false,"fork":false,"pushed_at":"2024-10-07T06:53:27.000Z","size":362,"stargazers_count":0,"open_issues_count":13,"forks_count":1,"subscribers_count":5,"default_branch":"develop","last_synced_at":"2025-06-02T18:17:35.695Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/toolisticon.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":"2021-09-13T20:25:17.000Z","updated_at":"2024-06-28T07:05:04.000Z","dependencies_parsed_at":"2023-02-18T05:05:20.603Z","dependency_job_id":"1051ca43-ba17-4b69-9d43-e582c6891a12","html_url":"https://github.com/toolisticon/krid","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/toolisticon/krid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolisticon%2Fkrid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolisticon%2Fkrid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolisticon%2Fkrid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolisticon%2Fkrid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toolisticon","download_url":"https://codeload.github.com/toolisticon/krid/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolisticon%2Fkrid/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260867835,"owners_count":23074914,"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":[],"created_at":"2024-11-14T21:21:34.924Z","updated_at":"2025-06-20T02:37:51.554Z","avatar_url":"https://github.com/toolisticon.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# krid\n\n[![stable](https://img.shields.io/badge/lifecycle-STABLE-green.svg)](https://github.com/toolisticon#stable)\n\nYour one-stop library to support two dimensional **K**otlin g**RID**s.\n\n[![Build Status](https://github.com/toolisticon/krid/workflows/Development%20branches/badge.svg)](https://github.com/toolisticon/krid/actions)\n[![sponsored](https://img.shields.io/badge/sponsoredBy-Holisticon-RED.svg)](https://holisticon.de/)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.toolisticon.lib/krid/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.toolisticon.lib/krid)\n\n## Documentation\n\n```ascii\n.##..##..#####...######..#####..\n.##.##...##..##....##....##..##.\n.####....#####.....##....##..##.\n.##.##...##..##....##....##..##.\n.##..##..##..##..######..#####..\n................................\n```\n\nsee it in action here: [KridReadme](./src/test/kotlin/KridReadme.kt)\n\n```kotlin\n\n  // create a 2dim-array of type Boolean where '.' is false and '#' is true\n  val krid: Krid\u003cBoolean\u003e = Krids.krid(\n    \"\"\"\n      .##..##..#####...######..#####..\n      .##.##...##..##....##....##..##.\n      .####....#####.....##....##..##.\n      .##.##...##..##....##....##..##.\n      .##..##..##..##..######..#####..\n      ................................\n    \"\"\".trimIndent(), false\n  ) { it == '#' }\n\n  // list all cells and values where cell is filled and x==y\n  println(krid.sequence().filter { it.value \u0026\u0026 it.x == it.y }.toList())\n  // [CellValue(x=1, y=1, value=true), CellValue(x=2, y=2, value=true)]\n\n  // create a second krid representing the letter `O` programmatically\n  val o: Krid\u003cBoolean\u003e = Krids.krid(8, 5, false)\n    .plus(\n      // upper line of O\n      generateSequence(1) { it + 1 }\n        .map { Krids.cell(it, 0, true) }\n        .take(5).toList()\n    ).plus(\n      // lower line of O\n      generateSequence(1) { it + 1 }\n        .map { Krids.cell(it, 4, true) }\n        .take(5).toList()\n    ).plus(\n      // left side of O\n      generateSequence(0) { it + 1 }.map { Krids.cell(1, it, true) }.take(5).toList()\n    ).plus(\n      // right side of O\n      generateSequence(0) { it + 1 }.map { Krids.cell(6, it, true) }.take(5).toList()\n    )\n\n  println(o.ascii())\n  //    fttttttf\n  //    ftfffftf\n  //    ftfffftf\n  //    ftfffftf\n  //    fttttttf\n\n  // add the second krid to the first with an offset of 16 columns, replacing letter `I`\n  val krod = krid + o.toAddKrid(offset = Krids.cell(16, 0))\n\n  // print `KROD` with '*'s instead of '#'s.\n  println(krod.ascii { if (it) '*' else '.' })\n  //   .**..**..*****...******..*****..\n  //   .**.**...**..**..**..**..**..**.\n  //   .****....*****...**..**..**..**.\n  //   .**.**...**..**..**..**..**..**.\n  //   .**..**..**..**..******..*****..\n  //   ................................\n\n  // jump like a chess knight, 2 right, 1 down\n  val knightStep = RIGHT(2) + DOWN\n  println(knightStep)\n  // prints: RIGHT(2) + DOWN(1)\n\n  // starting in top left\n  val cellsInKnightsReach = krod.walk(stepFn = knightStep)\n    .toList()\n  println(cellsInKnightsReach)\n  // prints: [CellValue(x=2, y=1, value=true), CellValue(x=4, y=2, value=true), CellValue(x=6, y=3, value=false), CellValue(x=8, y=4, value=false), CellValue(x=10, y=5, value=false)]\n```\n\n\n\n## Motivation\n\nTwo dimensional grids are everywhere. Whether you render a table, find possible moves on a chessboard, implement a tetris game, navigate santa clause through a maze of `#` and `.` characters during [AoC](https://adventofcode.com/), ... I had dozens of use cases in the past where I had to identify and move cells in a 2D array. But ... it's not a use case natively  supported by my favorite programming language.\n\nSure, it's not a \"hard\" task to store values in a list or array and use width/height attributes to correctly address elements by their `x,y`-coordinates, but it is a repetitive and error prone task that has to be implemented over and over again. \n\nSo here is (the) solution: **krid** - your friendly neighborhoods kotlin library for creating, calculating, expanding and travelling two-dimensional arrays (aka grids) with kotlin.\n\n### Naming things\n\nThis lib follows the tradition that kotlin libs might also just start with the letter `k` and since my first motivation for creating this where boardgame-implementations, I liked that according to  [wisdomlib.org](https://www.wisdomlib.org/definition/krid), `krid` in the Sanskrit dictionary means: _1) To play, amuse oneself, 2) To gamble, play at dice 3) To jest, joke or trifle with_ \n\n_Disclaimer_: This lib is not in any way related to the seemingly popular data analysis project [kgrid](https://github.com/kgrid). \n\u003cbr/\u003eI was aware of [Vincent Carriers kgrid library](https://github.com/Vincent-Carrier/kgrid) while writing krid, though. It was for sure an inspiration, although, putting the same vocabulary aside, I took a different approach using immutable and sealed base classes.\n\n### Scope\n\nAlthough you could use a krid of type Number to do mathematical matrix operations, there might be other libs out there that will be more useful. Keep in mind that krid focusses on addressing cells, navigating via steps and transforming by adding and substracting (sub-)krids, basically just setting the foundation for things to build on top.\n\n### Design Decisions\n\n* This lib is designed to be as usable as possible, without being too invasive to your code base and dependency tree. Consequentially, it does not require any transitive dependencies.\u003cbr/\u003eIt just uses the core features provided by **JDK 11.x** and **[Kotlin 1.6.x](https://blog.jetbrains.com/kotlin/2021/11/kotlin-1-6-0-is-released/)**.\n\n* Immutability - modification of Krids is not possible, there are no setters for any attributes, instead, whenever something has to be changed, a new copy is created containing the new state.\n\n* Operator overloading - instead of coming up with clever function names, wherever possible `krid` uses [operator overloads](https://kotlinlang.org/docs/operator-overloading.html)  for composing new objects\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoolisticon%2Fkrid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoolisticon%2Fkrid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoolisticon%2Fkrid/lists"}