hey y’all, is there a nice way to handle a nullabl...
# arrow
b
hey y’all, is there a nice way to handle a nullable type that also has an
isEmpty
method that is functionally equivalent in our case to null? For example:
Copy code
val files: Map<UUID, MultipartFile>;

val fileUrls = if (files?.isNotEmpty()) {
  uploadFiles(files).bind() // returns Either<MyError, Map<UUID, Url>>
} else null
c
You could also do
(files?.isNotEmpty() ?: false)
, but I also think you might want to reconsider using null here. Why not just have
uploadFiles(files).bind()
return an empty map? or even do validation and return
MyError.left()
if this constitutes an error.
b
good points
null is not an exception case, it’s valid to not have an uploaded file, so i wouldn’t want a left, but there isn’t much semantic difference in our case between a null and an empty map in this case
so ill probably just have uploadFiles return an empty map (i think it’s doing a parTraverseValidated internally, so it wouldnt execute anything and just return an empty map)