blob: f5c4ccdcaa6a8401ff68b8435c8b8206da7e0f40 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
package akka.japi
/**
* A Function interface. Used to create first-class-functions is Java (sort of).
*/
trait Function[T, R] {
def apply(param: T): R
}
/**
* A Function interface. Used to create 2-arg first-class-functions is Java (sort of).
*/
trait Function2[T1, T2, R] {
def apply(arg1: T1, arg2: T2): R
}
/**
* A Procedure is like a Function, but it doesn't produce a return value
*/
trait Procedure[T] {
def apply(param: T): Unit
}
/**
* A Procedure is like a Function, but it doesn't produce a return value
*/
trait Procedure2[T1, T2] {
def apply(param: T1, param2: T2): Unit
}
/**
* An executable piece of code that takes no parameters and doesn't return any value.
*/
trait SideEffect {
def apply: Unit
}
/**
* An executable piece of code that takes no parameters and doesn't return any value.
*/
trait Effect {
def apply: Unit
}
/**
* + * A constructor/factory, takes no parameters but creates a new value of type T every call
* +
*/
trait Creator[T] {
def create: T
}
/**
* This class represents optional values. Instances of <code>Option</code>
* are either instances of case class <code>Some</code> or it is case
* object <code>None</code>.
* <p>
* Java API
*/
sealed abstract class Option[A] extends java.lang.Iterable[A] {
import scala.collection.JavaConversions._
def get: A
def isEmpty: Boolean
def isDefined = !isEmpty
def asScala: scala.Option[A]
def iterator = if (isEmpty) Iterator.empty else Iterator.single(get)
}
object Option {
/**
* <code>Option</code> factory that creates <code>Some</code>
*/
def some[A](v: A): Option[A] = Some(v)
/**
* <code>Option</code> factory that creates <code>None</code>
*/
def none[A] = None.asInstanceOf[Option[A]]
/**
* <code>Option</code> factory that creates <code>None</code> if
* <code>v</code> is <code>null</code>, <code>Some(v)</code> otherwise.
*/
def option[A](v: A): Option[A] = if (v == null) none else some(v)
/**
* Class <code>Some[A]</code> represents existing values of type
* <code>A</code>.
*/
final case class Some[A](v: A) extends Option[A] {
def get = v
def isEmpty = false
def asScala = 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
}
implicit def java2ScalaOption[A](o: Option[A]): scala.Option[A] = o.asScala
implicit def scala2JavaOption[A](o: scala.Option[A]): Option[A] = option(o.get)
}
|