This file contains hidden or 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
button.setOnClickListener(new View.OnClickListener { | |
def onClick(v:View) { | |
openUri("http://wikipedia.org") | |
} | |
}) |
This file contains hidden or 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 fetchUserData(userId: Int): Future[UserData] = {...} // method which returns user data in the future | |
def loadFromUrl(url: Url): Future[Bitmap] = {...} // method which returns a bitmap in the future | |
val avatar: Future[Bitmap] = | |
for { | |
userData <- fetchUserData(1) // bind user data to value 'userData' as soon as it is available | |
avatar <- loadFromUrl(userData.avatarUrl) // use 'userData' from above (when it is available) and then | |
// load the bitmap and bind it to 'avatar' as soon as it is available | |
} yield avatar // return the avatar bitmap as a result | |
This file contains hidden or 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
{"questions":[{"id":37278957,"title":"Einfach nur müde","body":"Ich bin seit einigen Wochen einfach nur müde, müde, müde. \r\nGehe abends um 9 ins Bett, schlafe sofort ein und schlafe bis morgens um 7 durch. \r\nMorgens fühle ich mich als hätte ich kaum geschlafen. Auch im Urlaub oder an den Wochenenden bin ich dauer müde, egal wie lange ich schlafe.\r\nBeim Arzt war ich schon, der konnte nichts feststellen, Blutwerte alle super und ich bin kerngesund.\r\nHabe einige Probleme auf der Arbeit, bin ziemlich unterfordert mit mit meinen Aufgaben und langweile mich oft. Versuche seit 2 Jahren einen neuen Job zu finden, doch es ist gar nicht so einfach.\r\nHabt ihr einen Tipp wie sich meine Müdigkeit etwas bessern könnte?\r\n","created_at":"2014-07-18T08:54:42+02:00","creator":{"id":5462512,"nickname":"Polly276"},"tags":[{"id":3460,"name":"schlafen","normalized_tag":"schlafen","question_frequency":27065},{"id":4932,"name":"müde","normalized_tag":"muede","question_frequency":4264},{"id":5206433,"name":"Unterfoderung" |
This file contains hidden or 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
{"questions":[ | |
{"id":36983645,"title":"question title...","body":"...","created_at":"...", "creator":{"id":5626472,"nickname":"..."}, | |
"tags":[{"id":1143,"name":"Sommer"}], | |
"count_of_answers":0, "has_most_helpful_answer":false, | |
"links":[ | |
{"rel":"answers","href":"/answers?questionId=36983645"}, | |
{"rel":"creator","href":"/users/5626472"}]}, | |
... | |
], | |
"total_count": 276, |
This file contains hidden or 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
{ | |
"questions" : [ { "id":4711, "title" : "Why to follow REST principles?", .... }, ...] | |
"links" : [ | |
{ "rel" : "previous", "href" : "/questions?beforeId=4711&limit=20" }, | |
{ "rel" : "next", "href" : "/questions?afterId=4731&limit=20" }, | |
] | |
} |
This file contains hidden or 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
case object ParseError | |
case class Person(firstName: String, lastName: String) | |
val success1 = "first".success[ParseError.type].toValidationNel | |
val failure = ParseError.failure[String].toValidationNel | |
val result = (success1 |@| failure) { Person(_ , _) } | |
println(result) | |
// prints : Failure(NonEmptyList(ParseError)) |
This file contains hidden or 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 scalaz._ | |
import Scalaz._ | |
object validationFailFast { | |
case object ParseError | |
case class Person(firstName: String, lastName: String) | |
val success1 = "first".success[ParseError.type].toValidationNel |
This file contains hidden or 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 success1 = 1.success[String] | |
val failure1 = "failure1".failure[Int] | |
val failure2 = "failure2".failure[Int] | |
// use +++ on Validation | |
val result = success1 +++ | |
failure1 +++ | |
failure2 | |
// result is Failure(failure1failure2) |
This file contains hidden or 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 success1 = 1.success[String] | |
val failure1 = "failure1".failure[Int] | |
val failure2 = "failure2".failure[Int] | |
// use +++ on Validation | |
val result = success1.toValidationNel +++ | |
failure1.toValidationNel +++ | |
failure2.toValidationNel | |
// result is Failure(NonEmptyList(failure1, failure2)) |
This file contains hidden or 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 success1 = 1.success[String] | |
val failure1 = "failure1".failure[Int] | |
val failure2 = "failure2".failure[Int] | |
for { | |
r1 <- success1 | |
r2 <- failure1 | |
r3 <- failure2 | |
} yield r1 + r2 + r3 |