almond icon indicating copy to clipboard operation
almond copied to clipboard

kernel input example from docs/api-jupyter not working

Open angusdavisadobe opened this issue 5 years ago • 1 comments

From the docs https://almond.sh/docs/api-jupyter, there is this example:

final class Password(value: String) { override def toString = "...." } val user = kernel.stdin("user: ") // clear text input val password = kernel.stdin(prompt = "password: ", password = true).map(new Password(_))

However, when I try to run it, I get this:

cmd11.sc:5: type mismatch;
 found   : Char
 required: String
val password = kernel.stdin(prompt = "password: ", password = true).map(new Password(_))
                                                                                     ^Compilation Failed
Compilation Failed

If I remove the '.map(new Password(_))', I get: user: user password: ········ defined class Password user: String = "user" password: String = "password"

I am using the SCALA_VERSION=2.12.8 ALMOND_VERSION=0.9.0 version of the kernel and using Jupyter Lab.

angusdavisadobe avatar Jan 02 '20 19:01 angusdavisadobe

At first sight I misunderstood your question, but it is totally legit. I ran into the same error. If you check the signature of the map function in StringOps has changed between Scala 2.11 and 2.12. I think this causes the confusion. The above code will work with Scala 2.11 but not with 2.12 and above. Try this insted: final class Password(val value: String){ override def toString = "****" } val user = kernel.stdin("User: ") val password = new Password(kernel.stdin("Passwd: ", password = true))

gneusch avatar Jun 24 '20 20:06 gneusch