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.Arrays; | |
import java.util.List; | |
import static java.lang.String.join; | |
import static java.util.Collections.emptyList; | |
import static java.util.Collections.nCopies; | |
import static java.util.stream.Collectors.toList; | |
/** |
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
def f4(implicit v: T) = ... | |
def f5(implicit v: T) = ... | |
for { | |
v1 <- f1 | |
v2 <- f2 | |
implicit v3 <- f3 | |
v4 <- f4 | |
v5 <- f5 | |
} yield { ... } |
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
# To reproduce this Haskell function in Python we need to define some helper | |
# functions first. But Python's list comprehensions support nested loops just | |
# like Haskell. | |
# | |
# combinations :: Int -> [a] -> [[a]] | |
# combinations 0 _ = [ [] ] | |
# combinations n xs = [ y:ys | y:xs' <- tails xs, ys <- combinations (n-1) xs'] | |
def headtail(lst): | |
""" |
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
object Helpers { | |
def backgroundThread(code: => Unit) { | |
val task = new AsyncTask[AnyRef,AnyRef,AnyRef]() { | |
override def doInBackground(params: AnyRef*) = { | |
code | |
null | |
} | |
} | |
task.execute() |
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 t = findViewById(R.id.textView1).asInstanceOf[TextView] | |
val b = findViewById(R.id.button1).asInstanceOf[Button] | |
b setOnClickListener { | |
view: View => | |
backgroundThread { | |
// Do things like network requests here in the background thread... | |
Thread.sleep(3000) | |
uiThread { | |
// Back on the main thread, update the UI... |