-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUsefulOption.scala
More file actions
39 lines (33 loc) · 941 Bytes
/
UsefulOption.scala
File metadata and controls
39 lines (33 loc) · 941 Bytes
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
/**
* Contains functions that affect Option.
*
* Purity project by Daniil Tekunov.
*/
object UsefulOption {
/**
* Contains useful functions for built-in Int type
*/
implicit class IntOption(input: Option[Int]) {
def getOrZero: Int = input.getOrElse(0)
def getOrMax: Int = input.getOrElse(2147483647)
}
/**
* Contains useful functions for built-in Long type
*/
implicit class LongOption(input: Option[Long]) {
def getOrZeroL: Long = input.getOrElse(0L)
def getOrMaxL: Long = input.getOrElse(9223372036854775807L)
}
/**
* Contains useful functions for built-in String type
*/
implicit class StringOption(input: Option[String]) {
def getOrEmpty: String = input.getOrElse("")
}
/**
* Contains useful functions for throwable type
*/
implicit class ThrowableOption[T](input: Option[T]) {
def getOrThrow(ex: Throwable) = input.getOrElse(ex)
}
}