this post was submitted on 02 Sep 2024
0 points (50.0% liked)

Android Development

539 readers
8 users here now

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

founded 1 year ago
MODERATORS
 

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 ?

top 1 comments
sorted by: hot top controversial new old
[–] slowcakes@programming.dev 2 points 2 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/