SecretX
11/14/2021, 7:30 PMOption.applicative()
went with release 1.0? What should I use instead? I'm looking for a way to compose these three Option
into an object, or null
otherwise:
// example of expected input for string: "10 -55 99"
private fun parseLocation(string: String, dungeonName: String): Location? {
val args = string.split(' ', limit = 3)
if (args.size != 3) {
logger.warning("Invalid location '$string' for dungeon '$dungeonName', skipping this location for now")
return null
}
val x = args[0].toIntOrNull().toOption()
val y = args[1].toIntOrNull().toOption()
val z = args[2].toIntOrNull().toOption()
// use x y and z to create a location
}
simon.vergauwen
11/14/2021, 7:53 PMzip
to be more in line with Kotlin Std.
So you can use:
args[0].toIntOrNull().toOption().zip(
args[1].toIntOrNull().toOption(),
args[2].toIntOrNull().toOption()
) { x, y, z -> }
simon.vergauwen
11/14/2021, 7:54 PMNullable.zip(
args[0].toIntOrNull().toOption(),
args[1].toIntOrNull().toOption(),
args[2].toIntOrNull().toOption()
) { x, y, z -> }
SecretX
11/14/2021, 7:59 PM