I’m new to using reactive and functional programming in kotlin with libraries. I’m maintaining a project at my company that uses only .orNull() from the arrow.core.Option class.

My question is: why is the project returning the first type instead of the second one?

Single<Option<UserEntity>>
Single<UserEntity?>

Can’t the DAO object return a null type if it doesn’t find the object on a query such as SELECT * FROM users WHERE id = 1 ?

  • slowcakes@programming.dev
    link
    fedilink
    arrow-up
    2
    ·
    3 months ago

    I think you’re giving it to much thought, a nullable type is also a optional.

    But using orNull() to unwrap the option kinda defeats it’s purpose, you’re just making it into another optional type, If that is the case then I would stop using Option and use the nullable operator “?”.

    When I’ve worked with arrow I usually wrap types with Either so I can failfast and only have happy path in my code.

    https://arrow-kt.io/learn/typed-errors/either-and-ior/