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 ?

You are viewing a single thread.
View all comments
2 points

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/

permalink
report
reply

Android Development

!android_dev@programming.dev

Create post

Welcome to the programming.dev Android development community!

The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License

Community stats

  • 2

    Monthly active users

  • 15

    Posts

  • 20

    Comments