Skip to content

Instantly share code, notes, and snippets.

@SAMMY7th
Created August 28, 2017 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SAMMY7th/fca32ec8ac24f087a9bbcc44227abe57 to your computer and use it in GitHub Desktop.
Save SAMMY7th/fca32ec8ac24f087a9bbcc44227abe57 to your computer and use it in GitHub Desktop.

ScalaのOptionとmap

val name: Option[String] = Some("きの子")
val greet = name.map(n => s"${n}さんこんにちは")  // greet: Option[String] = Some(きの子さんこんにちは)
greet.getOrElse("なまえがないよ")  // Optionから値をとりだした。 res1: String = きの子さんこんにちは

KotlinのNullableとlet

val name: String? = "きの子"
name?.let { n -> "${n}さんこんにちは" }  // nameに値が入っている場合にlet関数を適用している
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment