Skip to content

Instantly share code, notes, and snippets.

@daneko
Last active December 31, 2015 08:38
Show Gist options
  • Save daneko/7961311 to your computer and use it in GitHub Desktop.
Save daneko/7961311 to your computer and use it in GitHub Desktop.
たろー先生助けて!
fun hoge(i : Int) = if(i % 3 == 0 ) null else i
val sum = (1 .. 10).map(::hoge).filterNotNull().reduce{ a, b -> a + b}
println(sum)
def hoge(i :Int ) = if( i % 3 == 0) None else Some(i)
val sum = (1 to 10).map(hoge).flatten.reduce(_ + _)
@ngsw-taro
Copy link

(1..10).map(::hoge).filterNotNull().reduce{a, b -> a + b}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment