Saving the planet and shufflin'
This commit is contained in:
parent
72f12c89cd
commit
5eba9fceef
10 changed files with 177 additions and 148 deletions
|
|
@ -24,28 +24,14 @@ trait Function2[T1, T2, R] {
|
|||
* A Procedure is like a Function, but it doesn't produce a return value.
|
||||
*/
|
||||
trait Procedure[T] {
|
||||
def apply(param: T)
|
||||
}
|
||||
|
||||
/**
|
||||
* A Procedure is like a Function, but it doesn't produce a return value.
|
||||
*/
|
||||
trait Procedure2[T1, T2] {
|
||||
def apply(param: T1, param2: T2)
|
||||
}
|
||||
|
||||
/**
|
||||
* An executable piece of code that takes no parameters and doesn't return any value.
|
||||
*/
|
||||
trait SideEffect {
|
||||
def apply()
|
||||
def apply(param: T): Unit
|
||||
}
|
||||
|
||||
/**
|
||||
* An executable piece of code that takes no parameters and doesn't return any value.
|
||||
*/
|
||||
trait Effect {
|
||||
def apply()
|
||||
def apply(): Unit
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -67,9 +53,9 @@ sealed abstract class Option[A] extends java.lang.Iterable[A] {
|
|||
|
||||
def get: A
|
||||
def isEmpty: Boolean
|
||||
def isDefined = !isEmpty
|
||||
def isDefined: Boolean = !isEmpty
|
||||
def asScala: scala.Option[A]
|
||||
def iterator = if (isEmpty) Iterator.empty else Iterator.single(get)
|
||||
def iterator: java.util.Iterator[A] = if (isEmpty) Iterator.empty else Iterator.single(get)
|
||||
}
|
||||
|
||||
object Option {
|
||||
|
|
@ -102,18 +88,18 @@ object Option {
|
|||
* <code>A</code>.
|
||||
*/
|
||||
final case class Some[A](v: A) extends Option[A] {
|
||||
def get = v
|
||||
def isEmpty = false
|
||||
def asScala = scala.Some(v)
|
||||
def get: A = v
|
||||
def isEmpty: Boolean = false
|
||||
def asScala: scala.Some[A] = scala.Some(v)
|
||||
}
|
||||
|
||||
/**
|
||||
* This case object represents non-existent values.
|
||||
*/
|
||||
private case object None extends Option[Nothing] {
|
||||
def get = throw new NoSuchElementException("None.get")
|
||||
def isEmpty = true
|
||||
def asScala = scala.None
|
||||
def get: Nothing = throw new NoSuchElementException("None.get")
|
||||
def isEmpty: Boolean = true
|
||||
def asScala: scala.None.type = scala.None
|
||||
}
|
||||
|
||||
implicit def java2ScalaOption[A](o: Option[A]): scala.Option[A] = o.asScala
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue