def findUser(screenName: String): Future[User] = ...
def findFollowers(user: User): Future[Set[User]] = ...
def unfollowAtRandom(user: User, followers: Set[User]): Future[Unit] = ...
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
scala> import scala.collection._ | |
import scala.collection._ | |
scala> import scala.collection.JavaConverters._ | |
import scala.collection.JavaConverters._ | |
scala> val m: mutable.ConcurrentMap[Int, Int] = new java.util.concurrent.ConcurrentHashMap().asScala | |
m: scala.collection.mutable.ConcurrentMap[Int,Int] = Map() | |
scala> val m2 = m.withDefault(2*) |
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 class Area(code: String, name: String) | |
object Area { | |
val Japan: Set[Area] = Set( | |
Area("01", "北海道"), | |
Area("02", "青森県") | |
// ... | |
) | |
val Us: Set[Area] = Set( | |
Area("AK", "Alaska") |
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
name := "scala-io-test" | |
version := "0.1" | |
scalaVersion := "2.9.2" | |
resolvers ++= Seq( | |
"typesafe-repo" at "http://repo.typesafe.com/typesafe/releases/", | |
"scala-tools" at "https://oss.sonatype.org/content/groups/scala-tools/" | |
) |
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
sealed trait FoldResult[+A] | |
case class Continue[+A](a: A) extends FoldResult[A] | |
case class End[+A](a: A) extends FoldResult[A] | |
class LimitFoldable[+A](underlying: Traversable[A]) { | |
def limitFoldLeft[B](init: B)(f: (B, A) => FoldResult[B]): B = { | |
@tailrec | |
def fold(sentinel: B, rest: Traversable[A]): B = { | |
if (rest.isEmpty) return sentinel | |
f(sentinel, rest.head) match { |
- 1秒後, 5秒後, 15秒後, 60秒後 みたいなリトライがしたかったので interval に Stream[Int] を渡せるようにしてみた。
- 無限 Stream 渡したら無限 retry もできるね。
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
public interface EntityContext { | |
Object get(); | |
void set(Object entity); | |
void remove(); | |
} |
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 class User(id: String, name: String, options: Seq[String]) { | |
def options(os: String*): User = copy(options = options ++ os) | |
} | |
case class Group(id: String, name: String, subgroups: Seq[Group], options: Seq[String]) { | |
def options(os: String*): Group = copy(options = options ++ os) | |
} |
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
// これはNG | |
public class User { | |
private String name; | |
private int age; | |
public User(String name, int age) { | |
this.name = name; | |
this.age = age; |
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
scala> val hoge: (Int, Int, Int) => Int = { | |
| case (0, _, 1) => 2 | |
| case (_, _, _) => 3 | |
| } | |
hoge: (Int, Int, Int) => Int = <function3> | |
scala> hoge(0, 2, 1) | |
res0: Int = 2 |