Giter VIP home page Giter VIP logo

forkhandles's Introduction

Forkhandles

build download

GitHub license codebeat badge

Forkhandles (4k) contains foundational libraries for Kotlin

  • Bunting4k - Command line argument parser
  • Data4k - Typesafe data-oriented programming
  • Fabrikate4k - Test utility to instantiate objects with fake data
  • Mock4k - The very cheapest mocking framework platform
  • Parser4k - Recursive descent parser combinator library
  • Partial4k - Adds partial application of functions to Kotlin
  • Result4k - A usable Result type
  • State4k - Simple event/command state machine modelling
  • Time4k - Clock and deterministic scheduler
  • Tuples4k - Tuple classes
  • Values4k - Value classes aka Microtypes aka Tinytypes

Installation

In Gradle, install the BOM and then any other modules in the dependency block:

implementation(platform("dev.forkhandles:forkhandles-bom:X.Y.Z"))
implementation("dev.forkhandles:$libraryName")

forkhandles's People

Contributors

albertlatacz avatar augusto avatar daviddenton avatar dkandalov avatar dmcg avatar garthjacques avatar huanlui avatar johnjohndoe avatar leojo avatar manuelprinz avatar marcusdunn avatar ndchorley avatar npryce avatar oharaandrew314 avatar razvn avatar time4tea avatar tkint avatar tobiaslieber avatar uberto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

forkhandles's Issues

[fabrikate4k] Add boolean Fabricator

Hi everyone,
I was stumbling upon this when trying to create a supposely simple data class. There is a Fabricator instance for every primitive type exception boolean in the library. Is it intentional that there is none for boolean? Adding something like

class BooleanFabricator(private val random: Random = Random) : Fabricator<Boolean> {
    override fun invoke() = random.nextBoolean()
}

should be easy enough. Therefore I wonder is this was intentionally omitted.
Cheers,
Ronny

[Bunting4k] positional argument.

Sometimes having a positional argument is useful.

For example: cp [options] source_file target_file

The source file and target file are positional arguments. It's not set by following a flag, but by its position.

time4k - infinite loop when scheduling 2 tasks with same delay

Fails with an infinite loop..

@Test
fun canExecuteCommandsThatRepeatWithFixedDelay_bug() {
    scheduler.scheduleWithFixedDelay(commandA, 2L, 3L, SECONDS)
    scheduler.scheduleWithFixedDelay(commandB, 2L, 3L, SECONDS)

    scheduler.tick(8L, SECONDS)

    assertEquals(listOf(commandA, commandA, commandA), invoked)
}

[values4k] Forced message in factory

Hello !

I was wondering, what is the purpose of forcing the message ?

private fun <T> attempt(value: () -> T) = try {
value()
} catch (e: Exception) {
throw IllegalArgumentException(
this::class.java.name.substringBeforeLast('$') +
": " + e::class.java.name + " " + e.localizedMessage
)
}
}

Why not let the client decide what to do with exceptions ?

In my case, I want to throw exceptions in the init of the class, by giving meaningful descriptions. Unfortunately, it gets messed up by this forced behavior.

[fabrikate4k] Provide more information when InstanceFabricator cannot create an instance

Current situation

Given this code that fails (because YearMonth is not supported, see Additional comments) :

    data class Foobar(
        val z: YearMonth
    )

    @Test
    fun `supports YearMonth`() {
        assertThat(Fabrikate().random<Foobar>().also(::println), present())
    }

The returned error does not contain too much information about why it failed:

image

Proposed change

Modify InstanceFabricator to provide an exception similar to this:

image

Additional comments

This issue only focuses on the error handling. Supporting YearMonth would be interesting, but perhaps I will propose it in a different issue .

running into NoUsableConstructor after update

Hey there,

I've updated from 2.2.0.0 to 2.3.0.0 and am running into the exception dev.forkhandles.fabrikate.InstanceFabricator$NoUsableConstructor when trying to use Fabrikate().random<XXX>() on any self-written class in the whole project. Are there any changes I need to make to the code after updating the version? What could be the causes if nothing changed codewise? Also what info do you need from me to tackle this?

Thanks!

[values4k] BaseX values

Any interest in adding value classes for common bases, i.e. 16, 32, 36, 64? They have applications not only in encoding binary, but also for setting easily understood constraints on identifiers. All of these values can be built with the existing tools, but it might be nice to have additional shortcuts.

However, there's no single proper way to handle out-of-bound characters; rather than reject the entire string, the developer may choose to have the invalid characters stripped, or coerced (in some cases). Making a single decision on which strategy to use might disqualify the value for many use-cases, but supporting multiple cases with options may be more than we want to handle in this library. Thoughts?

Example: For a base16/36 value, the developer may choose to coerce to uppercase
Example: For a MAC address, the developer may choose to strip the colon separators to coerce it to base16

[fabrikate4k] Nullable properties are randomly set to null

Current status

Nullable properties are randomly set to null using the config Random:

 fun makeRandomInstance(classRef: KClass<*>, type: KType): Any? =
        when {
            type.isMarkedNullable && config.random.nextBoolean() -> null

Proposed change

Allow to make this configurable:

  • Current behaviour (default): randomly set to null.
  • Always set to null.
  • Never set to null.

[parser4k] Add by delegates for .with caching

object MinimalCalculator {
    val cache = OutputCache<BigDecimal>()
    fun binaryExpr(s: String) = inOrder(ref { expr }, token(s), ref { expr })

    val number = oneOrMore(oneOf('0'..'9')).map { it.joinToString("").toBigDecimal() }.with(cache)
}

why not add getValue(k, p, self) for OutputCache:

class OutputCacheBy<out T>(private val p: Parser<T>) {
  fun getValue(k: KClass<*>, p: KProperty<*>, self: OutputCache) = p.with(self)
}

and then:

object MinimalCalculator {
    val cache = OutputCache<BigDecimal>()
    fun binaryExpr(s: String) = inOrder(ref { expr }, token(s), ref { expr })

    val number = by cache { oneOrMore(oneOf('0'..'9')).map { it.joinToString("").toBigDecimal() } }
}

Eh... looks ugly, but in real projects, I think p.with(cache) should have a shorter expression (maybe with a CachedParsers baseclass ext-fun?).

Result4k Kotest Matchers

Hello there. I've recently decided to migrate one of my projects from Arrow to Result4k as all I really need is a Result type. The one thing I miss though are Kotest matchers like shouldBeInvalid, shouldBeValid, shouldBeLeft etc. and I couldn't find anything out of the box for Result4k!

Would this project be interested in a Kotest module? I've made a draft one here under the Result4k folder which provides various shouldBeSuccess and shouldBeFailure functions, usage looks like:

fun exampleDivideByZero() {
    val result = divide(5, 0) //function that returns Failure upon divide by zero

    //all of these would pass
    result.shouldBeFailure()
    result shouldBeFailure DivideByZeroFailure
    result shouldBeFailure { reason ->
        reason shouldBe DivideByZeroFailure
    }

    //but this will fail with the appropriate message
    result shouldBeSuccess 5 //Throws AssertionError like: Failure(DivideByZero) should be Success(5)
}

If you'd rather keep stuff like this out of this repo I'd be happy to just maintain this in a separate repo as it's pretty small in scope ๐Ÿ˜…

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.