I'm writing a little program in scala that would simulate a doctors practice. One of the requirements is that a user can set consultations with a doctor. I have implemented a solution that gives you the consultation object if you succeed and also prints a message saying that the action was successful.
This is where a little "bug" (more a minor but annoying inconveniece) appears. When I tell my scala worksheet to make a new variable like so:
var consultation: Consultation = patient.makeConsultation(x, y, z)
Well this works perfectly BUT the message that it should print is printed at the top of the output window and not at the point in the worksheet were the variable is actually created. Does anyone know a solution for this?
Thanks in advance.
println in scala using Intellij showing weird behaviour
nr: #1 dodano: 2017-12-31 12:12
This is not a bug but the expected behaviour. The println in your makeConsultation function is a side-effect which has nothing to do with the creation of Consultation.
You can use Scala's type system (check Option or Try) to represent that makeConsultation could fail.