have a question about ensure
function, somehow it doesn't make null safe after check in either block.
What I am doing wrong, or is there a better way to ensure that value is not null except of using !!
here is my code
suspend fun checkCanConnectDirectChat(
senderId: Int?,
receiverId: Int?,
chatRoomId: Int?
) = either {
ensure(chatRoomId != null && receiverId != null) {
BadRequestExceptionResponse(message = ErrorConstants.INVALID_PAYLOAD)
}
val isSenderInChat = isUserInChat(chatRoomId, senderId).bind()
val isReceiverInChat = isUserInChat(chatRoomId, receiverId).bind()
ensure(isSenderInChat && isReceiverInChat){
BadRequestExceptionResponse(message = ErrorConstants.INVALID_PAYLOAD)
}
}