Forkhandles (4k)

repository·trunk·Indexed 42 days ago

https://github.com/fork-handles/forkhandles

A suite of foundational, specialized libraries for Kotlin developers providing tools for parsing, data modeling, mocking, and state management. The ecosystem includes Bunting4k for CLI argument parsing, Fs4k for file tree manipulation, Ropes4k for high-performance text sequences, Tx4k for typesafe transaction boundaries, and other utilities like Data4k, Mock4k, and Parser4k.

Tokens
14.1K
Snippets
44
Records
63
Agent score
54%

What's inside Forkhandles

  1. Overview of the Forkhandles (4k) ecosystem

    trunk

    Forkhandles (4k) is a collection of foundational libraries designed for Kotlin development. It provides a suite of specialized tools for common programming tasks, including argument parsing, data-oriented programming, testing utilities, file manipulation, mocking, parsing, and more.

    Key libraries in the ecosystem include:

    • Bunting4k: Command line argument parser
    • Data4k: Typesafe data-oriented programming
    • Fabrikate4k: Test utility to instantiate objects with fake data
    • Fs4k: Simple file tree manipulation DSL
    • Mock4k: A lightweight mocking framework platform
    • Parser4k: Recursive descent parser combinator library
    • Partial4k: Adds partial application of functions to Kotlin
    • Result4k: A usable Result type
    • Ropes4k: A high-performance Rope data type
    • State4k: Simple event/command state machine modelling
    • Time4k: Clock and deterministic scheduler
    • Tuples4k: Tuple classes
    • Tx4k: Typesafe, programmatic transaction boundaries
    • Values4k: Value classes (Microtypes/Tinytypes)
  2. Overview of Fs4k

    trunk
    Fs4k is a super-simple Domain Specific Language (DSL) for file tree manipulation in Kotlin. It provides a pluggable file system abstraction, allowing you to define and manipulate file structures (files and directories) using a declarative syntax. It supports both physical disk operations and in-memory file systems.
  3. What is Ropes4k and when to use it?

    trunk

    Ropes4k is a Kotlin implementation of a Rope data structure. Ropes are optimized for heavy insert and delete operations. Unlike String, StringBuffer, or CharArray, Ropes do not copy the entire data set during these operations, making them significantly faster for large-scale modifications.

    Use Ropes when:

    • You need to perform frequent insertions, prepends, or deletions on large text sequences.
    • You want to avoid the performance penalty of copying large amounts of data during modifications.

    Avoid Ropes when:

    • Your primary access pattern is random-access (getting characters by index), as the tree-based storage makes indexing slower than standard strings.
  4. Requirements for User Products and Installation Information

    trunk

    If you convey an object code work specifically for use in a User Product (a consumer product or something designed for a dwelling) as part of a transaction that transfers possession of the product to the recipient, you must also provide Installation Information.

    Installation Information includes:

    • Methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from its Corresponding Source.
    • This information must ensure that the continued functioning of the modified object code is not prevented or interfered with solely because of the modification.

    Constraints:

    • The information must be in a publicly documented format.
    • It must require no special password or key for unpacking, reading, or copying.
    • This requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (e.g., the work is in ROM).
  5. How TimeSource works as an abstraction

    trunk

    In the ForK ecosystem, TimeSource is used to decouple code from the system clock, enabling easier testing (e.g., simulating specific points in time) and better library composition.

    Instead of using a heavy class or interface like java.time.Clock, TimeSource is defined as a simple typealias to a function that returns an Instant. This allows you to provide time sources using lambdas, function references (like Clock::now), or through function composition.

    typealias TimeSource = () -> Instant
  6. Patent rights and protections

    trunk

    The GPLv3 includes specific provisions regarding patents:

    • Grant of Patent License: Each contributor grants a non-exclusive, worldwide, royalty-free patent license under their essential patent claims to make, use, sell, offer for sale, import, and otherwise run, modify, and propagate the contents of their contributor version.
    • Automatic Extension: If you convey a covered work and grant a patent license to some recipients, that license is automatically extended to all recipients of the covered work and works based on it.
    • Prohibition on Discriminatory Licenses: You may not convey a covered work if you are part of an arrangement with a third-party distributor where you make payments based on the extent of conveying and the third party grants discriminatory patent licenses to recipients.
  7. Important Caveats regarding Immutability

    trunk
    Ropes are designed to be immutable. While Rope.of(CharSequence) does not copy the underlying CharSequence, modifying the original CharSequence after the Rope has been created will result in undefined behavior. To safely use a CharArray, use Rope.ofCopy() to ensure the data is captured at the time of construction.
  8. Understand the core concepts of Tx4k

    trunk

    Tx4k manages typesafe, programmatic transaction boundaries using three primary abstractions:

    • Transactor: The orchestrator. It manages the lifecycle of a transaction: creating a resource, starting the transaction, wrapping the resource in an API, passing that API to your application code, and finally committing or rolling back based on the outcome.
    • Resource: The underlying transactional object being managed (e.g., a JDBC connection or an in-memory serializable transaction implementation).
    • API: The abstraction layer that wraps the Resource. This is the interface your application code interacts with to perform transactional operations.
  9. Understand the GNU General Public License v3 terms

    trunk

    This project is licensed under the GNU General Public License version 3 (GPLv3). This license governs how you may use, modify, and distribute the software. Key concepts include:

    • The Program: The copyrightable work licensed under this license.
    • Modified Version: A work created by copying from or adapting the original work.
    • Covered Work: Either the unmodified Program or a work based on it.
    • Conveying: Any propagation (distribution, copying, etc.) that enables others to receive copies. Mere network interaction without transferring a copy is not conveying.
    • Corresponding Source: The preferred form of the work for making modifications, including all source code needed to generate, install, and run the object code, plus scripts to control those activities.
  10. Choosing between GPL and LGPL for libraries

    trunk
    The GNU General Public License (GPL) does not permit incorporating your program into proprietary programs. If you are developing a subroutine library and want to allow proprietary applications to link with it, you should consider using the GNU Lesser General Public License (LGPL) instead of the standard GPL.
  11. Create a file system structure with Fs4k

    trunk

    You can use the dir function to automatically create a file system structure. Within the dir block, you can define files using text() for text-based files or binary() for binary data. You can also nest dir() calls to create subdirectories.

    To define content for a text file, set the content property to a String. For binary files, set the content property to an InputStream (e.g., using .byteInputStream()).

    When using Automatic as the second argument to dir, the file system is created automatically upon definition.

    val directory = dir("path", Automatic) {
        text("plainfile.txt") {
            content = "hello"
        }
        binary("binary.png") {
            content = "goodbye".byteInputStream()
        }
    
        dir("directory") {
            text("file2.html") {
                content = "<html/>"
            }
        }
    }
    
    // directory is created automatically
    directory.delete()
  12. Include license notices for terminal interaction

    trunk

    If your program uses a terminal interface, it should output a short notice when starting in interactive mode. This notice should direct users to commands (e.g., show w and show c) that display the appropriate parts of the General Public License. For GUI applications, this information is typically placed in an about box.

    <program>  Copyright (C) <year>  <name of author>
    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.