This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Optional; | |
import java.util.function.Consumer; | |
import java.util.function.Function; | |
public class Result<Ok, Err> { | |
private Ok ok; | |
private Err err; | |
private boolean isOk; | |
private Result(Ok ok, Err err, boolean isOk){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.{Try, Success, Failure} | |
def divide: Try[Int] = { | |
val dividend = Try(Console.readLine("Enter an Int that you'd like to divide:\n").toInt) | |
val divisor = Try(Console.readLine("Enter an Int that you'd like to divide by:\n").toInt) | |
val problem = for { | |
x <- divident | |
y <- divisor | |
} yield x / y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val name: Option[String] = | |
request.getParameter("name") | |
val upperNameOpt = | |
name.map(_.trim.toUpperCase).filter(_ != "") | |
println(upperNameOpt getOrElse "no name value") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Как улучшить следующий код? | |
val name: Option[String] = | |
request.getParameter("name") | |
if (name.isDefined) { | |
val s = name.get.trim.toUpperCase | |
if (s != "") { | |
println(s) | |
} else { | |
println("no name value") | |
} |