summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRocky Madden <git@rockymadden.com>2014-01-05 10:52:00 -0700
committerRocky Madden <git@rockymadden.com>2014-01-05 10:52:00 -0700
commit3d99c638fb6101cf21248417fb73b6eeb9a864ac (patch)
treeac1d774be00760778108c3a48979da0ac65d8dd7
parent7c3c0c9288657fc5fbbe59321cf1fdd8d43bf232 (diff)
downloadstringmetric-3d99c638fb6101cf21248417fb73b6eeb9a864ac.tar.gz
stringmetric-3d99c638fb6101cf21248417fb73b6eeb9a864ac.tar.bz2
stringmetric-3d99c638fb6101cf21248417fb73b6eeb9a864ac.zip
Moved implicits to source type.
-rwxr-xr-xcore/src/main/scala/com/rockymadden/stringmetric/Algorithm.scala21
-rwxr-xr-xcore/src/main/scala/com/rockymadden/stringmetric/Metric.scala22
-rwxr-xr-xcore/src/main/scala/com/rockymadden/stringmetric/package.scala11
3 files changed, 38 insertions, 16 deletions
diff --git a/core/src/main/scala/com/rockymadden/stringmetric/Algorithm.scala b/core/src/main/scala/com/rockymadden/stringmetric/Algorithm.scala
index 1200926..a6d6d6e 100755
--- a/core/src/main/scala/com/rockymadden/stringmetric/Algorithm.scala
+++ b/core/src/main/scala/com/rockymadden/stringmetric/Algorithm.scala
@@ -2,7 +2,7 @@ package com.rockymadden.stringmetric
object Algorithm {
import scala.collection.immutable.Map
- import Transform.StringTransform
+ import Transform._
trait Algorithm[A] {
@@ -10,6 +10,12 @@ object Algorithm {
}
+ object Algorithm {
+ implicit def stringAlgorithmToDecorated(sa: StringAlgorithm): StringAlgorithmDecorator =
+ new StringAlgorithmDecorator(sa)
+ }
+
+
trait StringAlgorithm extends Algorithm[Array[Char]] {
def compute(a: String): Option[String]
}
@@ -34,8 +40,15 @@ object Algorithm {
}
- final class StringAlgorithmDecorator(val sa: StringAlgorithm) {
- val withMemoization: StringAlgorithm = new StringAlgorithm {
+ trait AlgorithmDecorator[A] {
+ val withMemoization: Algorithm[A]
+
+ val withTransform: (Transform[A] => Algorithm[A])
+ }
+
+
+ final case class StringAlgorithmDecorator(sa: StringAlgorithm) extends AlgorithmDecorator[Array[Char]] {
+ override val withMemoization: StringAlgorithm = new StringAlgorithm {
private val base: StringAlgorithm = sa
private var memo: Map[String, Option[String]] = Map()
@@ -50,7 +63,7 @@ object Algorithm {
}
}
- val withTransform: (StringTransform => StringAlgorithm) = (st) => new StringAlgorithm {
+ override val withTransform: (StringTransform => StringAlgorithm) = (st) => new StringAlgorithm {
private val base: StringAlgorithm = sa
private val transform: StringTransform = st
diff --git a/core/src/main/scala/com/rockymadden/stringmetric/Metric.scala b/core/src/main/scala/com/rockymadden/stringmetric/Metric.scala
index f217f52..686ebc9 100755
--- a/core/src/main/scala/com/rockymadden/stringmetric/Metric.scala
+++ b/core/src/main/scala/com/rockymadden/stringmetric/Metric.scala
@@ -1,7 +1,7 @@
package com.rockymadden.stringmetric
object Metric {
- import Transform.StringTransform
+ import Transform._
trait Metric[A, B] {
@@ -9,6 +9,12 @@ object Metric {
}
+ object Metric {
+ implicit def stringMetricToDecorated[A](sa: StringMetric[A]): StringMetricDecorator[A] =
+ new StringMetricDecorator[A](sa)
+ }
+
+
trait StringMetric[A] extends Metric[Array[Char], A] {
def compare(a: String, b: String): Option[A]
}
@@ -62,8 +68,16 @@ object Metric {
WeightedLevenshtein(delete, insert, substitute).compare(a, b)
}
- final class StringMetricDecorator[A](val sm: StringMetric[A]) {
- val withMemoization: StringMetric[A] = new StringMetric[A] {
+
+ sealed trait MetricDecorator[A, B] {
+ val withMemoization: Metric[A, B]
+
+ val withTransform: (Transform[A] => Metric[A, B])
+ }
+
+
+ final case class StringMetricDecorator[A](sm: StringMetric[A]) extends MetricDecorator[Array[Char], A] {
+ override val withMemoization: StringMetric[A] = new StringMetric[A] {
private val base: StringMetric[A] = sm
private var memo: Map[(String, String), Option[A]] = Map()
@@ -80,7 +94,7 @@ object Metric {
}
}
- val withTransform: (StringTransform => StringMetric[A]) = (st) => new StringMetric[A] {
+ override val withTransform: (StringTransform => StringMetric[A]) = (st) => new StringMetric[A] {
private val base: StringMetric[A] = sm
private val transform: StringTransform = st
diff --git a/core/src/main/scala/com/rockymadden/stringmetric/package.scala b/core/src/main/scala/com/rockymadden/stringmetric/package.scala
index e5bc19d..54bef55 100755
--- a/core/src/main/scala/com/rockymadden/stringmetric/package.scala
+++ b/core/src/main/scala/com/rockymadden/stringmetric/package.scala
@@ -2,16 +2,11 @@ package com.rockymadden
package object stringmetric {
import scala.language.implicitConversions
- import Algorithm._
- import Metric._
+
type CompareTuple[T] = (Array[T], Array[T])
type MatchTuple[T] = (Array[T], Array[T])
- implicit def stringToCharArray(s: String): Array[Char] =
- s.toCharArray
- implicit def stringAlgorithmToDecoratedStringAlgorithm(sa: StringAlgorithm): StringAlgorithmDecorator =
- new StringAlgorithmDecorator(sa)
- implicit def stringMetricToDecoratedStringMetric[A](sa: StringMetric[A]): StringMetricDecorator[A] =
- new StringMetricDecorator[A](sa)
+
+ implicit def stringToCharArray(s: String): Array[Char] = s.toCharArray
}