Skip to content
This repository was archived by the owner on Aug 17, 2019. It is now read-only.

Commit 82730ca

Browse files
committed
Add conversion to Option[T]
1 parent 3f166b7 commit 82730ca

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/main/scala/com/ckkloverdos/convert/Converter.scala

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package com.ckkloverdos.convert
1818

19-
import com.ckkloverdos.maybe.Maybe
20-
2119
/**
2220
*
2321
* @author Christos KK Loverdos <loverdos@gmail.com>.

src/main/scala/com/ckkloverdos/convert/ConverterBase.scala

+11
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,15 @@ trait ConverterBase {
4747
// logger.debug("ConverterBase::convert(%s: %s): %s".format(sourceValue, sourceValue.getClass, manifest[T]))
4848
convertEx[T](sourceValue)
4949
}
50+
51+
def convertOpt[T: Type](sourceValue: Any): Option[T] = {
52+
try Some(convertEx[T](sourceValue))
53+
catch {
54+
case e: Error
55+
throw e
56+
57+
case e: Throwable
58+
None
59+
}
60+
}
5061
}

0 commit comments

Comments
 (0)