Skip to content

Instantly share code, notes, and snippets.

scala> Array(1).hashCode
res16: Int = 357917741
scala> Array(1).hashCode
res17: Int = 1064821544
scala> Seq(1).hashCode
res18: Int = 1945410391
scala> Seq(1).hashCode
implicit class Function1Pimps[-T1](fn: Function1[T1, Boolean]) {
def complement: Function1[T1, Boolean] = (param: T1) => !fn(param)
}
scala> (1 to 100).map(n => if(n > 10) None else Some(n))
res1: scala.collection.immutable.IndexedSeq[Option[Int]] = Vector(Some(1), Some(2), Some(3), Some(4), Some(5), Some(6), Some(7), Some(8), Some(9), Some(10), None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None)
scala> (1 to 100).flatMap(n => if(n > 10) None else Some(n))
res2: scala.collection.immutable.IndexedSeq[Int] = Vector(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Here is some text and then some code in fenced style:
```
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world!")
}
}
```
{
"id": "100",
"email": "bigjasonwebb@gmail.com",
"realName": "Jason J Webb",
"avatar": "/100/C0F6B65E73BE49BAA9F940E40550917E.jpg",
"signupDate": "2014-02-11T23:21:01+00:00",
"featureEnrollments": [
{
"id": 1,
"feature": "publish",
{
"id": "CFF5C6158BFD45C9A53459FBAB9996B2",
"delta": "44",
"isDeleted": false,
"revisions": [
{
"revisionId": 44,
"userId": 100,
"date": {
"time": "2014-07-17T22:58:12+00:00",
{
"id": "FFF5C6158BFD45C9A53459FBAB9996B2",
"delta": "41",
"isDeleted": false,
"revisions": [
{
"revisionId": 41,
"userId": 100,
"date": {
"time": "2014-07-17T04:37:16+00:00",
{
"id": "FFF5C6158BFD45C9A53459FBAB9996B2",
"delta": "41",
"isDeleted": false,
"revisions": [
{
"revisionId": 41,
"userId": 100,
"date": {
"time": "2014-07-17T04:37:16+00:00",
{
"code": 500,
"error": "There was an unexpected server error.",
"fields": null
}
def save[A](key: String)(f: CouchValueHandler[A])(implicit formatter: CouchFormat[A], context: CouchContext): Future[A] =
get[A](key).flatMap {
case Some(row) =>
update[A](key, row)(value => f(value.some))
case None =>
val value = f(None)
add(key, value) flatMap {
case false => // Failure to add means there is now a value, start the process over.
save(key)(f)
case true =>