Skip to content

Add Arrow-kt support module #326

@mkotsbak

Description

@mkotsbak

It would be nice to have a module with extra support for Arrow library: https://arrow-kt.io/ similar to what Kotest has: https://github.com/kotest/kotest/blob/master/doc/matchers/arrow.md

Here are some of them you are free to add:


/**
 * Asserts the Either value is Either.Right. You can pass in an optional lambda to run additional assertions on the right value
 *
 * ```
 * val name = Either.Right("...")
 * assertThat(name).isRight().hasLength(3)
 * ```
 */
fun <B : Any> Assert<Either<*, B>>.isRight(): Assert<B> = transform { actual ->
    actual.getOrElse { expected("to be right") }
}

/**
 * Asserts the Either value is Either.Left. You can pass in an optional lambda to run additional assertions on the left value
 *
 * ```
 * val name = Either.Left("...")
 * assertThat(name).isLeft().hasLength(3)
 * ```
 */
fun <A : Any> Assert<Either<A, *>>.isLeft(): Assert<A> = transform { actual ->
    actual.swap().getOrElse { expected("to be left") }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions