Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

migrated banana-rdf to Scala 2.10 Futures + Try -- not yet the depend…

…encies
  • Loading branch information...
commit 05e5a0207a4053e0caf622d1a98b861c296468ca 1 parent b300b13
Alexandre Bertails betehess authored
Showing with 136 additions and 433 deletions.
  1. +3 −0  .gitignore
  2. +0 −26 rdf/src/main/scala/BananaException.scala
  3. +4 −4 rdf/src/main/scala/BooleanWriter.scala
  4. +7 −8 rdf/src/main/scala/CommonBinders.scala
  5. +35 −21 rdf/src/main/scala/Diesel.scala
  6. +2 −3 rdf/src/main/scala/EitherBinder.scala
  7. +1 −1  rdf/src/main/scala/GraphStoreCommand.scala
  8. +3 −3 rdf/src/main/scala/LangLiteralBinder.scala
  9. +9 −10 rdf/src/main/scala/LinkedDataStore.scala
  10. +3 −4 rdf/src/main/scala/ListBinder.scala
  11. +4 −4 rdf/src/main/scala/LiteralBinder.scala
  12. +2 −3 rdf/src/main/scala/MapBinder.scala
  13. +4 −4 rdf/src/main/scala/NodeBinder.scala
  14. +2 −3 rdf/src/main/scala/OptionBinder.scala
  15. +3 −3 rdf/src/main/scala/PointedGraphBinder.scala
  16. +2 −2 rdf/src/main/scala/Prefix.scala
  17. +2 −2 rdf/src/main/scala/Property.scala
  18. +4 −5 rdf/src/main/scala/RDFReader.scala
  19. +15 −15 rdf/src/main/scala/RecordBinder.scala
  20. +3 −3 rdf/src/main/scala/SparqlOps.scala
  21. +8 −8 rdf/src/main/scala/SparqlQueryResultsReader.scala
  22. +2 −2 rdf/src/main/scala/SparqlSolutionSyntax.scala
  23. +0 −2  rdf/src/main/scala/SparqlSolutionsSyntax.scala
  24. +4 −4 rdf/src/main/scala/StringBinder.scala
  25. +3 −4 rdf/src/main/scala/TupleBinder.scala
  26. +3 −3 rdf/src/main/scala/TypedLiteralBinder.scala
  27. +4 −4 rdf/src/main/scala/UriBinder.scala
  28. +4 −4 rdf/src/main/scala/Writer.scala
  29. +0 −18 rdf/src/main/scala/package.scala
  30. +0 −40 rdf/src/main/scala/util/AkkaDefaults.scala
  31. +0 −16 rdf/src/main/scala/util/AnySyntax.scala
  32. +0 −43 rdf/src/main/scala/util/FutureSyntax.scala
  33. +0 −110 rdf/src/main/scala/util/FutureValidation.scala
  34. +0 −9 rdf/src/main/scala/util/UnsafeExtractor.scala
  35. +0 −22 rdf/src/main/scala/util/ValidationSyntax.scala
  36. +0 −20 rdf/src/main/scala/util/package.scala
3  .gitignore
View
@@ -22,3 +22,6 @@ sbt-launch*.jar
bin
.ensime
*.egp
+
+# just for convenience
+ldp
26 rdf/src/main/scala/BananaException.scala
View
@@ -1,21 +1,5 @@
package org.w3.banana
-import scalaz.{ Validation, Success, Failure }
-import scalaz.Validation._
-import scalaz.Semigroup.firstSemigroup
-
-object BananaException {
-
- implicit val bananaExceptionSemiGroup = firstSemigroup[BananaException]
-
- def bananaCatch[T](a: => T): BananaValidation[T] = try {
- Success(a)
- } catch {
- case e: Throwable => Failure(StoreProblem(e))
- }
-
-}
-
trait BananaException extends Exception
case class FailedConversion(message: String) extends Exception(message) with BananaException
@@ -26,16 +10,6 @@ case class WrappedThrowable(t: Throwable) extends Exception(t) with BananaExcept
case class NoReader(mimetype: String) extends Exception("No RDFReader for " + mimetype) with BananaException
-object WrappedThrowable {
- def fromTryCatch[T](body: => T): Validation[WrappedThrowable, T] =
- try {
- Success(body)
- } catch {
- // only catch exceptions that should be caught, let VM throwables through.
- case t: Exception => Failure(WrappedThrowable(t))
- }
-}
-
case class LocalNameException(message: String) extends Exception(message) with BananaException
case class VarNotFound(message: String) extends Exception(message) with BananaException
8 rdf/src/main/scala/BooleanWriter.scala
View
@@ -1,15 +1,15 @@
package org.w3.banana
import scalax.io._
+import scala.util._
trait BooleanWriter[T] extends Writer[Boolean, T] {
def format(bool: Boolean): String
- def write[R](bool: Boolean, wcr: WriteCharsResource[R], base: String): BananaValidation[Unit] =
- WrappedThrowable.fromTryCatch {
- wcr.write(format(bool))
- }
+ def write[R](bool: Boolean, wcr: WriteCharsResource[R], base: String): Try[Unit] = Try {
+ wcr.write(format(bool))
+ }
}
15 rdf/src/main/scala/CommonBinders.scala
View
@@ -1,7 +1,6 @@
package org.w3.banana
-import scalaz._
-import scalaz.Validation._
+import scala.util._
import org.joda.time.DateTime
import java.util.UUID
@@ -12,7 +11,7 @@ trait CommonBinders[Rdf <: RDF] {
implicit val StringLiteralBinder: TypedLiteralBinder[Rdf, String] = new TypedLiteralBinder[Rdf, String] {
- def fromTypedLiteral(literal: Rdf#TypedLiteral): BananaValidation[String] = {
+ def fromTypedLiteral(literal: Rdf#TypedLiteral): Try[String] = {
val TypedLiteral(lexicalForm, datatype) = literal
if (datatype == xsd.string)
Success(lexicalForm)
@@ -36,7 +35,7 @@ trait CommonBinders[Rdf <: RDF] {
implicit val BooleanLiteralBinder: TypedLiteralBinder[Rdf, Boolean] = new TypedLiteralBinder[Rdf, Boolean] {
- def fromTypedLiteral(literal: Rdf#TypedLiteral): BananaValidation[Boolean] = {
+ def fromTypedLiteral(literal: Rdf#TypedLiteral): Try[Boolean] = {
val TypedLiteral(lexicalForm, datatype) = literal
if (datatype == xsd.boolean)
lexicalForm match {
@@ -55,7 +54,7 @@ trait CommonBinders[Rdf <: RDF] {
// TODO: find a better datatype than xsd:string
implicit val UUIDBinder: TypedLiteralBinder[Rdf, UUID] = new TypedLiteralBinder[Rdf, UUID] {
- def fromTypedLiteral(literal: Rdf#TypedLiteral): BananaValidation[UUID] = {
+ def fromTypedLiteral(literal: Rdf#TypedLiteral): Try[UUID] = {
val TypedLiteral(lexicalForm, datatype) = literal
if (datatype == xsd.string)
try { Success(UUID.fromString(lexicalForm)) } catch { case _: IllegalArgumentException => Failure(FailedConversion(lexicalForm + " cannot be made a java.util.UUID")) }
@@ -69,7 +68,7 @@ trait CommonBinders[Rdf <: RDF] {
implicit val IntBinder: TypedLiteralBinder[Rdf, Int] = new TypedLiteralBinder[Rdf, Int] {
- def fromTypedLiteral(literal: Rdf#TypedLiteral): BananaValidation[Int] = {
+ def fromTypedLiteral(literal: Rdf#TypedLiteral): Try[Int] = {
val TypedLiteral(lexicalForm, datatype) = literal
if (datatype == xsd.integer)
Success(lexicalForm.toInt)
@@ -83,7 +82,7 @@ trait CommonBinders[Rdf <: RDF] {
implicit val DoubleBinder: TypedLiteralBinder[Rdf, Double] = new TypedLiteralBinder[Rdf, Double] {
- def fromTypedLiteral(literal: Rdf#TypedLiteral): BananaValidation[Double] = {
+ def fromTypedLiteral(literal: Rdf#TypedLiteral): Try[Double] = {
val TypedLiteral(lexicalForm, datatype) = literal
if (datatype == xsd.double)
Success(lexicalForm.toDouble)
@@ -97,7 +96,7 @@ trait CommonBinders[Rdf <: RDF] {
implicit val DateTimeBinder: TypedLiteralBinder[Rdf, DateTime] = new TypedLiteralBinder[Rdf, DateTime] {
- def fromTypedLiteral(literal: Rdf#TypedLiteral): BananaValidation[DateTime] = {
+ def fromTypedLiteral(literal: Rdf#TypedLiteral): Try[DateTime] = {
val TypedLiteral(lexicalForm, datatype) = literal
if (datatype == xsd.dateTime)
try {
56 rdf/src/main/scala/Diesel.scala
View
@@ -1,10 +1,7 @@
package org.w3.banana
-import scalaz._
-import scalaz.Scalaz._
-import scalaz.Validation._
import NodeBinder._
-import org.w3.banana.util._
+import scala.util._
object Diesel {
def apply[Rdf <: RDF](implicit ops: RDFOps[Rdf]): Diesel[Rdf] = new Diesel()(ops)
@@ -33,11 +30,14 @@ class Diesel[Rdf <: RDF]()(implicit val ops: RDFOps[Rdf])
import pointed.graph
- def as[T](implicit binder: PointedGraphBinder[Rdf, T]): BananaValidation[T] =
+ def as[T](implicit binder: PointedGraphBinder[Rdf, T]): Try[T] =
binder.fromPointedGraph(pointed)
- def as2[T1, T2](implicit b1: PointedGraphBinder[Rdf, T1], b2: PointedGraphBinder[Rdf, T2]): BananaValidation[(T1, T2)] =
- ^[BananaValidation, T1, T2, (T1, T2)](b1.fromPointedGraph(pointed), b2.fromPointedGraph(pointed))(Tuple2.apply)
+ def as2[T1, T2](implicit b1: PointedGraphBinder[Rdf, T1], b2: PointedGraphBinder[Rdf, T2]): Try[(T1, T2)] =
+ for {
+ t1 <- b1.fromPointedGraph(pointed)
+ t2 <- b2.fromPointedGraph(pointed)
+ } yield (t1, t2)
def a(clazz: Rdf#URI): PointedGraph[Rdf] = {
val newGraph = graph union Graph(Triple(pointer, rdf("type"), clazz))
@@ -80,7 +80,7 @@ class Diesel[Rdf <: RDF]()(implicit val ops: RDFOps[Rdf])
new PointedGraphs(ns, graph)
}
- def takeOnePointedGraph: BananaValidation[PointedGraph[Rdf]] = {
+ def takeOnePointedGraph: Try[PointedGraph[Rdf]] = {
val it = nodes.iterator
if (!it.hasNext) {
Failure(WrongExpectation("expected exactly one node but got 0"))
@@ -90,10 +90,10 @@ class Diesel[Rdf <: RDF]()(implicit val ops: RDFOps[Rdf])
}
}
- def exactlyOneAs[T](implicit binder: PointedGraphBinder[Rdf, T]): BananaValidation[T] =
+ def exactlyOneAs[T](implicit binder: PointedGraphBinder[Rdf, T]): Try[T] =
exactlyOnePointedGraph flatMap (_.as[T])
- def exactlyOnePointedGraph: BananaValidation[PointedGraph[Rdf]] = {
+ def exactlyOnePointedGraph: Try[PointedGraph[Rdf]] = {
val it = nodes.iterator
if (!it.hasNext) {
Failure(WrongExpectation("expected exactly one node but got 0"))
@@ -106,10 +106,10 @@ class Diesel[Rdf <: RDF]()(implicit val ops: RDFOps[Rdf])
}
}
- def as[T](implicit binder: PointedGraphBinder[Rdf, T]): BananaValidation[T] =
+ def as[T](implicit binder: PointedGraphBinder[Rdf, T]): Try[T] =
takeOnePointedGraph flatMap (_.as[T])
- def as2[T1, T2](implicit b1: PointedGraphBinder[Rdf, T1], b2: PointedGraphBinder[Rdf, T2]): BananaValidation[(T1, T2)] =
+ def as2[T1, T2](implicit b1: PointedGraphBinder[Rdf, T1], b2: PointedGraphBinder[Rdf, T2]): Try[(T1, T2)] =
takeOnePointedGraph flatMap { _.as2[T1, T2] }
/**
@@ -118,14 +118,18 @@ class Diesel[Rdf <: RDF]()(implicit val ops: RDFOps[Rdf])
*
* note: this is very different from as[Option[T]], which is an encoding of an Option in RDF
*/
- def asOption[T](implicit binder: PointedGraphBinder[Rdf, T]): BananaValidation[Option[T]] = headOption match {
+ def asOption[T](implicit binder: PointedGraphBinder[Rdf, T]): Try[Option[T]] = headOption match {
case None => Success(None)
case Some(pointed) => pointed.as[T] map (Some(_))
}
- def asOption2[T1, T2](implicit b1: PointedGraphBinder[Rdf, T1], b2: PointedGraphBinder[Rdf, T2]): BananaValidation[Option[(T1, T2)]] = headOption match {
+ def asOption2[T1, T2](implicit b1: PointedGraphBinder[Rdf, T1], b2: PointedGraphBinder[Rdf, T2]): Try[Option[(T1, T2)]] = headOption match {
case None => Success(None)
- case Some(pointed) => ^[BananaValidation, T1, T2, (T1, T2)](pointed.as[T1], pointed.as[T2])(Tuple2.apply) map { Some(_) }
+ case Some(pointed) =>
+ for {
+ t1 <- pointed.as[T1]
+ t2 <- pointed.as[T2]
+ } yield Some((t1, t2))
}
/**
@@ -135,12 +139,22 @@ class Diesel[Rdf <: RDF]()(implicit val ops: RDFOps[Rdf])
*
* note: this is very different from as[List[T]], which is an encoding of a List in RDF
*/
- def asSet[T](implicit binder: PointedGraphBinder[Rdf, T]): BananaValidation[Set[T]] =
- this.iterator.toList.map(_.as[T]).sequence[BananaValidation, T].map(_.toSet)
-
- def asSet2[T1, T2](implicit b1: PointedGraphBinder[Rdf, T1], b2: PointedGraphBinder[Rdf, T2]): BananaValidation[Set[(T1, T2)]] =
- this.iterator.toList.map { pg => ^[BananaValidation, T1, T2, (T1, T2)](pg.as[T1], pg.as[T2])(Tuple2.apply) }.sequence[BananaValidation, (T1, T2)].map(_.toSet)
+ def asSet[T](implicit binder: PointedGraphBinder[Rdf, T]): Try[Set[T]] =
+ this.iterator.foldLeft[Try[Set[T]]](Success(Set.empty[T])){ case (accT, g) =>
+ for {
+ acc <- accT
+ t <- g.as[T]
+ } yield acc + t
+ }
+ def asSet2[T1, T2](implicit b1: PointedGraphBinder[Rdf, T1], b2: PointedGraphBinder[Rdf, T2]): Try[Set[(T1, T2)]] =
+ this.iterator.foldLeft[Try[Set[(T1, T2)]]](Success(Set.empty)){ case (accT, g) =>
+ for {
+ acc <- accT
+ t1 <- g.as[T1]
+ t2 <- g.as[T2]
+ } yield acc + ((t1, t2))
+ }
}
class PointedGraphPredicate(pointed: PointedGraph[Rdf], p: Rdf#URI) {
@@ -220,7 +234,7 @@ class Diesel[Rdf <: RDF]()(implicit val ops: RDFOps[Rdf])
implicit val PGBPointedGraphBinder: PointedGraphBinder[Rdf, PointedGraph[Rdf]] =
new PointedGraphBinder[Rdf, PointedGraph[Rdf]] {
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[PointedGraph[Rdf]] = Success(pointed)
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[PointedGraph[Rdf]] = Success(pointed)
def toPointedGraph(t: PointedGraph[Rdf]): PointedGraph[Rdf] = t
}
5 rdf/src/main/scala/EitherBinder.scala
View
@@ -1,7 +1,6 @@
package org.w3.banana
-import scalaz._
-import scalaz.Validation._
+import scala.util._
trait EitherBinder[Rdf <: RDF] {
this: Diesel[Rdf] =>
@@ -10,7 +9,7 @@ trait EitherBinder[Rdf <: RDF] {
implicit def EitherBinder[T1, T2](implicit b1: PointedGraphBinder[Rdf, T1], b2: PointedGraphBinder[Rdf, T2]): PointedGraphBinder[Rdf, Either[T1, T2]] = new PointedGraphBinder[Rdf, Either[T1, T2]] {
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[Either[T1, T2]] = {
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[Either[T1, T2]] = {
if (pointed isA rdf("Left"))
(pointed / rdf("left")).as[T1] flatMap (v => Success(Left(v)))
else if (pointed isA rdf("Right"))
2  rdf/src/main/scala/GraphStoreCommand.scala
View
@@ -54,7 +54,7 @@ object Command {
def POSTToCollection[Rdf <: RDF](collection: Rdf#URI, pointed: PointedGraph[Rdf])(implicit diesel: Diesel[Rdf]): Free[({type l[+x] = Command[Rdf, x]})#l, Rdf#URI] = {
import diesel._
import ops._
- val fragment = pointed.pointer.as[Rdf#URI].fold(t => throw t, s => s)
+ val fragment = pointed.pointer.as[Rdf#URI].get
// was:
// pointed.pointer.as[Rdf#URI] flatMap { uri =>
// if (uri.isPureFragment) Success(uri) else Failure(NotPureFragment)
6 rdf/src/main/scala/LangLiteralBinder.scala
View
@@ -1,9 +1,9 @@
package org.w3.banana
-import scalaz._
+import scala.util._
trait LangLiteralBinder[Rdf <: RDF, T] {
- def fromLangLiteral(node: Rdf#LangLiteral): BananaValidation[T]
+ def fromLangLiteral(node: Rdf#LangLiteral): Try[T]
def toLangLiteral(t: T): Rdf#LangLiteral
}
@@ -12,7 +12,7 @@ object LangLiteralBinder {
def toLiteralBinder[Rdf <: RDF, T](implicit ops: RDFOps[Rdf], binder: LangLiteralBinder[Rdf, T]): LiteralBinder[Rdf, T] =
new LiteralBinder[Rdf, T] {
- def fromLiteral(literal: Rdf#Literal): BananaValidation[T] =
+ def fromLiteral(literal: Rdf#Literal): Try[T] =
ops.foldLiteral(literal)(
tl => Failure(FailedConversion(literal.toString + " is a TypedLiteral, not a LangLiteral")),
ll => binder.fromLangLiteral(ll)
19 rdf/src/main/scala/LinkedDataStore.scala
View
@@ -1,18 +1,17 @@
package org.w3.banana
-import org.w3.banana.util._
import scalaz._
import scalaz.Scalaz._
import scala.concurrent._
object LinkedDataStore {
- implicit def apply[Rdf <: RDF](store: RDFStore[Rdf, BananaFuture])(implicit diesel: Diesel[Rdf], ec: ExecutionContext): LinkedDataStore[Rdf] =
+ implicit def apply[Rdf <: RDF](store: RDFStore[Rdf, Future])(implicit diesel: Diesel[Rdf], ec: ExecutionContext): LinkedDataStore[Rdf] =
new LinkedDataStore[Rdf](store)(diesel, ec)
}
-class LinkedDataStore[Rdf <: RDF](store: RDFStore[Rdf, BananaFuture])(implicit diesel: Diesel[Rdf], ec: ExecutionContext) {
+class LinkedDataStore[Rdf <: RDF](store: RDFStore[Rdf, Future])(implicit diesel: Diesel[Rdf], ec: ExecutionContext) {
import diesel._
import ops._
@@ -23,11 +22,11 @@ class LinkedDataStore[Rdf <: RDF](store: RDFStore[Rdf, BananaFuture])(implicit d
* - the document content represents the graph itself
* - the given is the pointer in the graph
*/
- def GET(hyperlink: Rdf#URI): BananaFuture[LinkedDataResource[Rdf]] = {
+ def GET(hyperlink: Rdf#URI): Future[LinkedDataResource[Rdf]] = {
store.execute(Command.GET[Rdf](hyperlink))
}
- def GET(hyperlinks: Iterable[Rdf#URI]): BananaFuture[Set[LinkedDataResource[Rdf]]] = {
+ def GET(hyperlinks: Iterable[Rdf#URI]): Future[Set[LinkedDataResource[Rdf]]] = {
store.execute(Command.GET[Rdf](hyperlinks))
}
@@ -37,26 +36,26 @@ class LinkedDataStore[Rdf <: RDF](store: RDFStore[Rdf, BananaFuture])(implicit d
* - the graph at the underlying document is not overriden, we only append triples
* - if the graph did not previously exist, it is created
*/
- def POST(uri: Rdf#URI, pointed: PointedGraph[Rdf]): BananaFuture[Unit] = {
+ def POST(uri: Rdf#URI, pointed: PointedGraph[Rdf]): Future[Unit] = {
store.execute(Command.POST[Rdf](uri, pointed))
}
- def PATCH(uri: Rdf#URI, delete: Iterable[TripleMatch[Rdf]]): BananaFuture[Unit] = {
+ def PATCH(uri: Rdf#URI, delete: Iterable[TripleMatch[Rdf]]): Future[Unit] = {
store.execute(Command.PATCH[Rdf](uri, delete))
}
/**
*
*/
- def POSTToCollection(collection: Rdf#URI, pointed: PointedGraph[Rdf]): BananaFuture[Rdf#URI] = {
+ def POSTToCollection(collection: Rdf#URI, pointed: PointedGraph[Rdf]): Future[Rdf#URI] = {
store.execute(Command.POSTToCollection[Rdf](collection, pointed))
}
- def DELETE(uri: Rdf#URI): BananaFuture[Unit] = {
+ def DELETE(uri: Rdf#URI): Future[Unit] = {
store.execute(Command.DELETE[Rdf](uri))
}
- def PUT(ldr: LinkedDataResource[Rdf]): BananaFuture[Unit] = {
+ def PUT(ldr: LinkedDataResource[Rdf]): Future[Unit] = {
store.execute(Command.PUT[Rdf](ldr))
}
7 rdf/src/main/scala/ListBinder.scala
View
@@ -1,7 +1,6 @@
package org.w3.banana
-import scalaz._
-import scalaz.Validation._
+import scala.util._
trait ListBinder[Rdf <: RDF] {
this: Diesel[Rdf] =>
@@ -10,7 +9,7 @@ trait ListBinder[Rdf <: RDF] {
implicit def ListBinder[T](implicit binder: PointedGraphBinder[Rdf, T]): PointedGraphBinder[Rdf, List[T]] = new PointedGraphBinder[Rdf, List[T]] {
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[List[T]] = {
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[List[T]] = {
import pointed.{ pointer, graph }
var elems = List[T]()
var current = pointer
@@ -19,7 +18,7 @@ trait ListBinder[Rdf <: RDF] {
(getObjects(graph, current, rdf.first).toList, getObjects(graph, current, rdf.rest).toList) match {
case (List(first), List(rest)) => {
val firstPointed = PointedGraph(first, pointed.graph)
- elems ::= binder.fromPointedGraph(firstPointed).fold(be => throw be, e => e)
+ elems ::= binder.fromPointedGraph(firstPointed).get
current = rest
}
case other => throw new FailedConversion("asList: couldn't decode a list")
8 rdf/src/main/scala/LiteralBinder.scala
View
@@ -1,9 +1,9 @@
package org.w3.banana
-import scalaz._
+import scala.util._
trait LiteralBinder[Rdf <: RDF, T] {
- def fromLiteral(literal: Rdf#Literal): BananaValidation[T]
+ def fromLiteral(literal: Rdf#Literal): Try[T]
def toLiteral(t: T): Rdf#Literal
}
@@ -12,7 +12,7 @@ object LiteralBinder {
implicit def toNodeBinder[Rdf <: RDF, T](implicit ops: RDFOps[Rdf], binder: LiteralBinder[Rdf, T]): NodeBinder[Rdf, T] =
new NodeBinder[Rdf, T] {
- def fromNode(node: Rdf#Node): BananaValidation[T] =
+ def fromNode(node: Rdf#Node): Try[T] =
ops.foldNode(node)(
uri => Failure(FailedConversion(node + " is a URI, not a Literal")),
bnode => Failure(FailedConversion(node + " is a BNode, not a Literal")),
@@ -25,7 +25,7 @@ object LiteralBinder {
def naturalBinder[Rdf <: RDF](implicit ops: RDFOps[Rdf]): LiteralBinder[Rdf, Rdf#Literal] =
new LiteralBinder[Rdf, Rdf#Literal] {
- def fromLiteral(literal: Rdf#Literal): BananaValidation[Rdf#Literal] =
+ def fromLiteral(literal: Rdf#Literal): Try[Rdf#Literal] =
Success(literal)
def toLiteral(t: Rdf#Literal): Rdf#Literal = t
5 rdf/src/main/scala/MapBinder.scala
View
@@ -1,7 +1,6 @@
package org.w3.banana
-import scalaz._
-import scalaz.Validation._
+import scala.util._
trait MapBinder[Rdf <: RDF] {
this: Diesel[Rdf] =>
@@ -12,7 +11,7 @@ trait MapBinder[Rdf <: RDF] {
val binder = implicitly[PointedGraphBinder[Rdf, List[(K, V)]]]
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[Map[K, V]] = binder.fromPointedGraph(pointed) map { l => Map() ++ l }
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[Map[K, V]] = binder.fromPointedGraph(pointed) map { l => Map() ++ l }
def toPointedGraph(t: Map[K, V]): PointedGraph[Rdf] =
binder.toPointedGraph(t.toList)
8 rdf/src/main/scala/NodeBinder.scala
View
@@ -1,9 +1,9 @@
package org.w3.banana
-import scalaz._
+import scala.util._
trait NodeBinder[Rdf <: RDF, T] {
- def fromNode(node: Rdf#Node): BananaValidation[T]
+ def fromNode(node: Rdf#Node): Try[T]
def toNode(t: T): Rdf#Node
}
@@ -12,7 +12,7 @@ object NodeBinder {
def toPointedGraphBinder[Rdf <: RDF, T](implicit ops: RDFOps[Rdf], binder: NodeBinder[Rdf, T]): PointedGraphBinder[Rdf, T] =
new PointedGraphBinder[Rdf, T] {
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[T] =
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[T] =
binder.fromNode(pointed.pointer)
def toPointedGraph(t: T): PointedGraph[Rdf] = PointedGraph(binder.toNode(t))
@@ -21,7 +21,7 @@ object NodeBinder {
def naturalBinder[Rdf <: RDF](implicit ops: RDFOps[Rdf]): NodeBinder[Rdf, Rdf#Node] =
new NodeBinder[Rdf, Rdf#Node] {
- def fromNode(node: Rdf#Node): BananaValidation[Rdf#Node] =
+ def fromNode(node: Rdf#Node): Try[Rdf#Node] =
Success(node)
def toNode(t: Rdf#Node): Rdf#Node = t
5 rdf/src/main/scala/OptionBinder.scala
View
@@ -1,7 +1,6 @@
package org.w3.banana
-import scalaz._
-import scalaz.Validation._
+import scala.util._
trait OptionBinder[Rdf <: RDF] {
this: Diesel[Rdf] =>
@@ -12,7 +11,7 @@ trait OptionBinder[Rdf <: RDF] {
val listBinder = implicitly[PointedGraphBinder[Rdf, List[T]]]
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[Option[T]] = {
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[Option[T]] = {
listBinder.fromPointedGraph(pointed) map { _.headOption }
}
6 rdf/src/main/scala/PointedGraphBinder.scala
View
@@ -1,13 +1,13 @@
package org.w3.banana
-import scalaz.Validation
+import scala.util._
trait ToPointedGraph[Rdf <: RDF, T] {
def toPointedGraph(t: T): PointedGraph[Rdf]
}
trait FromPointedGraph[Rdf <: RDF, T] {
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[T]
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[T]
}
trait PointedGraphBinder[Rdf <: RDF, T] extends FromPointedGraph[Rdf, T] with ToPointedGraph[Rdf, T]
@@ -33,7 +33,7 @@ class PointedGraphBinderCombinator[Rdf <: RDF, T](binder: PointedGraphBinder[Rdf
def withClasses(classUris: ClassUrisFor[Rdf, T]): PointedGraphBinder[Rdf, T] =
new PointedGraphBinder[Rdf, T] {
// Q: do we want to check the classes here?
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[T] =
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[T] =
binder.fromPointedGraph(pointed)
def toPointedGraph(t: T): PointedGraph[Rdf] = {
4 rdf/src/main/scala/Prefix.scala
View
@@ -1,6 +1,6 @@
package org.w3.banana
-import scalaz._
+import scala.util._
trait Prefix[Rdf <: RDF] {
def prefixName: String
@@ -30,7 +30,7 @@ class PrefixBuilder[Rdf <: RDF](val prefixName: String, val prefixIri: String)(i
None
}
- def getLocalName(iri: Rdf#URI): BananaValidation[String] =
+ def getLocalName(iri: Rdf#URI): Try[String] =
unapply(iri) match {
case None => Failure(LocalNameException(this.toString + " couldn't extract localname for " + iri.toString))
case Some(localname) => Success(localname)
4 rdf/src/main/scala/Property.scala
View
@@ -1,6 +1,6 @@
package org.w3.banana
-import org.w3.banana.util._
+import scala.util._
trait Property[Rdf <: RDF, T] {
@@ -8,7 +8,7 @@ trait Property[Rdf <: RDF, T] {
def pos(t: T): Iterable[(Rdf#URI, PointedGraph[Rdf])]
- def extract(pointed: PointedGraph[Rdf]): BananaValidation[T]
+ def extract(pointed: PointedGraph[Rdf]): Try[T]
}
9 rdf/src/main/scala/RDFReader.scala
View
@@ -2,8 +2,7 @@ package org.w3.banana
import java.io._
import scalax.io._
-import scalaz.Validation
-import scalaz.Validation._
+import scala.util._
object RDFReader {
@@ -15,12 +14,12 @@ trait RDFReader[Rdf <: RDF, +S] {
def syntax: Syntax[S]
- def read[R <: Reader](resource: ReadCharsResource[R], base: String): BananaValidation[Rdf#Graph]
+ def read[R <: Reader](resource: ReadCharsResource[R], base: String): Try[Rdf#Graph]
- def read[R](inputResource: InputResource[R], base: String): BananaValidation[Rdf#Graph] =
+ def read[R](inputResource: InputResource[R], base: String): Try[Rdf#Graph] =
read(inputResource.reader(Codec.UTF8), base)
- def read(input: String, base: String): BananaValidation[Rdf#Graph] = {
+ def read(input: String, base: String): Try[Rdf#Graph] = {
val reader = new StringReader(input)
read(Resource.fromReader(reader), base)
}
30 rdf/src/main/scala/RecordBinder.scala
View
@@ -1,6 +1,6 @@
package org.w3.banana
-import scalaz.{ Validation, Success, Failure }
+import scala.util._
/**
* helper functions for binding Scala records (typically case classes)
@@ -28,7 +28,7 @@ trait RecordBinder[Rdf <: RDF] {
def constant[T](constT: T, constUri: Rdf#URI): PointedGraphBinder[Rdf, T] = {
val uriBinder = new URIBinder[Rdf, T] {
- def fromUri(uri: Rdf#URI): BananaValidation[T] =
+ def fromUri(uri: Rdf#URI): Try[T] =
if (constUri == uri)
Success(constT)
else
@@ -47,7 +47,7 @@ trait RecordBinder[Rdf <: RDF] {
def property[T](predicate: Rdf#URI)(implicit objectBinder: PointedGraphBinder[Rdf, T]): Property[Rdf, T] = new Property[Rdf, T] {
val uri = predicate
def pos(t: T): Iterable[(Rdf#URI, PointedGraph[Rdf])] = Set((predicate, t.toPG))
- def extract(pointed: PointedGraph[Rdf]): BananaValidation[T] =
+ def extract(pointed: PointedGraph[Rdf]): Try[T] =
(pointed / predicate).as[T]
}
@@ -57,7 +57,7 @@ trait RecordBinder[Rdf <: RDF] {
case None => Set()
case Some(t) => Set((predicate, t.toPG))
}
- def extract(pointed: PointedGraph[Rdf]): BananaValidation[Option[T]] =
+ def extract(pointed: PointedGraph[Rdf]): Try[Option[T]] =
(pointed / predicate).asOption[T]
}
@@ -65,7 +65,7 @@ trait RecordBinder[Rdf <: RDF] {
val uri = predicate
def pos(ts: Set[T]): Iterable[(Rdf#URI, PointedGraph[Rdf])] =
ts map { t => (predicate, t.toPG) }
- def extract(pointed: PointedGraph[Rdf]): BananaValidation[Set[T]] =
+ def extract(pointed: PointedGraph[Rdf]): Try[Set[T]] =
(pointed / predicate).asSet[T]
}
@@ -111,7 +111,7 @@ trait RecordBinder[Rdf <: RDF] {
make(p1.pos(t1))
}
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[T] = {
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[T] = {
def v1 = p1.extract(pointed)
for (t1 <- v1) yield apply(t1)
}
@@ -125,7 +125,7 @@ trait RecordBinder[Rdf <: RDF] {
make(p1.pos(t1), p2.pos(t2))
}
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[T] = {
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[T] = {
def v1 = p1.extract(pointed)
def v2 = p2.extract(pointed)
for (t1 <- v1; t2 <- v2) yield apply(t1, t2)
@@ -140,7 +140,7 @@ trait RecordBinder[Rdf <: RDF] {
make(p1.pos(t1), p2.pos(t2), p3.pos(t3))
}
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[T] = {
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[T] = {
def v1 = p1.extract(pointed)
def v2 = p2.extract(pointed)
def v3 = p3.extract(pointed)
@@ -156,7 +156,7 @@ trait RecordBinder[Rdf <: RDF] {
make(p1.pos(t1), p2.pos(t2), p3.pos(t3), p4.pos(t4))
}
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[T] = {
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[T] = {
def v1 = p1.extract(pointed)
def v2 = p2.extract(pointed)
def v3 = p3.extract(pointed)
@@ -173,7 +173,7 @@ trait RecordBinder[Rdf <: RDF] {
make(p1.pos(t1), p2.pos(t2), p3.pos(t3), p4.pos(t4), p5.pos(t5))
}
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[T] = {
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[T] = {
def v1 = p1.extract(pointed)
def v2 = p2.extract(pointed)
def v3 = p3.extract(pointed)
@@ -191,7 +191,7 @@ trait RecordBinder[Rdf <: RDF] {
make(p1.pos(t1), p2.pos(t2), p3.pos(t3), p4.pos(t4), p5.pos(t5), p6.pos(t6))
}
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[T] = {
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[T] = {
def v1 = p1.extract(pointed)
def v2 = p2.extract(pointed)
def v3 = p3.extract(pointed)
@@ -210,7 +210,7 @@ trait RecordBinder[Rdf <: RDF] {
make(p1.pos(t1), p2.pos(t2), p3.pos(t3), p4.pos(t4), p5.pos(t5), p6.pos(t6), p7.pos(t7))
}
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[T] = {
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[T] = {
def v1 = p1.extract(pointed)
def v2 = p2.extract(pointed)
def v3 = p3.extract(pointed)
@@ -230,7 +230,7 @@ trait RecordBinder[Rdf <: RDF] {
make(p1.pos(t1), p2.pos(t2), p3.pos(t3), p4.pos(t4), p5.pos(t5), p6.pos(t6), p7.pos(t7), p8.pos(t8))
}
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[T] = {
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[T] = {
def v1 = p1.extract(pointed)
def v2 = p2.extract(pointed)
def v3 = p3.extract(pointed)
@@ -251,7 +251,7 @@ trait RecordBinder[Rdf <: RDF] {
make(p1.pos(t1), p2.pos(t2), p3.pos(t3), p4.pos(t4), p5.pos(t5), p6.pos(t6), p7.pos(t7), p8.pos(t8), p9.pos(t9))
}
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[T] = {
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[T] = {
def v1 = p1.extract(pointed)
def v2 = p2.extract(pointed)
def v3 = p3.extract(pointed)
@@ -273,7 +273,7 @@ trait RecordBinder[Rdf <: RDF] {
make(p1.pos(t1), p2.pos(t2), p3.pos(t3), p4.pos(t4), p5.pos(t5), p6.pos(t6), p7.pos(t7), p8.pos(t8), p9.pos(t9), p10.pos(t10))
}
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[T] = {
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[T] = {
def v1 = p1.extract(pointed)
def v2 = p2.extract(pointed)
def v3 = p3.extract(pointed)
6 rdf/src/main/scala/SparqlOps.scala
View
@@ -1,6 +1,6 @@
package org.w3.banana
-import scalaz.Validation
+import scala.util._
trait SparqlOps[Rdf <: RDF] {
@@ -18,7 +18,7 @@ trait SparqlOps[Rdf <: RDF] {
* @param query a Sparql query
* @return A validation containing the Query
*/
- def Query(query: String): Validation[Exception, Rdf#Query]
+ def Query(query: String): Try[Rdf#Query]
/**
* A fold operation.
@@ -29,7 +29,7 @@ trait SparqlOps[Rdf <: RDF] {
construct: Rdf#ConstructQuery => T,
ask: Rdf#AskQuery => T): T
- def getNode(solution: Rdf#Solution, v: String): BananaValidation[Rdf#Node]
+ def getNode(solution: Rdf#Solution, v: String): Try[Rdf#Node]
def varnames(solution: Rdf#Solution): Set[String]
16 rdf/src/main/scala/SparqlQueryResultsReader.scala
View
@@ -1,6 +1,6 @@
package org.w3.banana
-import scalaz.Validation
+import scala.util._
import java.io._
/**
@@ -11,23 +11,23 @@ import java.io._
*/
trait SparqlQueryResultsReader[Rdf <: RDF, +S] {
- def read(is: InputStream, base: String): BananaValidation[Either[Rdf#Solutions, Boolean]]
+ def read(is: InputStream, base: String): Try[Either[Rdf#Solutions, Boolean]]
- def read(reader: java.io.Reader, base: String): BananaValidation[Either[Rdf#Solutions, Boolean]]
+ def read(reader: java.io.Reader, base: String): Try[Either[Rdf#Solutions, Boolean]]
- def read(file: File, base: String): BananaValidation[Either[Rdf#Solutions, Boolean]] =
+ def read(file: File, base: String): Try[Either[Rdf#Solutions, Boolean]] =
for {
- fis <- WrappedThrowable.fromTryCatch { new BufferedInputStream(new FileInputStream(file)) }
+ fis <- Try { new BufferedInputStream(new FileInputStream(file)) }
graph <- read(fis, base)
} yield graph
- def read(file: File, base: String, encoding: String): BananaValidation[Either[Rdf#Solutions, Boolean]] =
+ def read(file: File, base: String, encoding: String): Try[Either[Rdf#Solutions, Boolean]] =
for {
- fis <- WrappedThrowable.fromTryCatch { new InputStreamReader(new BufferedInputStream(new FileInputStream(file)), encoding) }
+ fis <- Try { new InputStreamReader(new BufferedInputStream(new FileInputStream(file)), encoding) }
graph <- read(fis, base)
} yield graph
- def read(s: String, base: String): BananaValidation[Either[Rdf#Solutions, Boolean]] = {
+ def read(s: String, base: String): Try[Either[Rdf#Solutions, Boolean]] = {
val reader = new StringReader(s)
read(reader, base)
}
4 rdf/src/main/scala/SparqlSolutionSyntax.scala
View
@@ -1,6 +1,6 @@
package org.w3.banana
-import scalaz.Validation
+import scala.util._
object SparqlSolutionSyntax {
@@ -10,7 +10,7 @@ object SparqlSolutionSyntax {
class SparqlSolutionSyntax[Rdf <: RDF](solution: Rdf#Solution)(implicit sparqlOps: SparqlOps[Rdf]) {
- def apply(v: String): BananaValidation[Rdf#Node] =
+ def apply(v: String): Try[Rdf#Node] =
sparqlOps.getNode(solution, v)
def vars: Set[String] = sparqlOps.varnames(solution)
2  rdf/src/main/scala/SparqlSolutionsSyntax.scala
View
@@ -1,7 +1,5 @@
package org.w3.banana
-import scalaz.Validation
-
object SparqlSolutionsSyntax {
def apply[Rdf <: RDF](solutions: Rdf#Solutions)(implicit sparqlOps: SparqlOps[Rdf]) =
8 rdf/src/main/scala/StringBinder.scala
View
@@ -1,17 +1,17 @@
package org.w3.banana
-import scalaz.Validation
+import scala.util._
trait StringBinder[T] {
- def fromString(s: String): BananaValidation[T]
+ def fromString(s: String): Try[T]
def toString(t: T): String
}
object StringBinder {
- def apply[T](f: String => BananaValidation[T]): StringBinder[T] =
+ def apply[T](f: String => Try[T]): StringBinder[T] =
new StringBinder[T] {
- def fromString(s: String): BananaValidation[T] = f(s)
+ def fromString(s: String): Try[T] = f(s)
def toString(t: T): String = t.toString()
}
7 rdf/src/main/scala/TupleBinder.scala
View
@@ -1,7 +1,6 @@
package org.w3.banana
-import scalaz._
-import scalaz.Validation._
+import scala.util._
trait TupleBinder[Rdf <: RDF] {
this: Diesel[Rdf] =>
@@ -10,7 +9,7 @@ trait TupleBinder[Rdf <: RDF] {
implicit def Tuple2Binder[T1, T2](implicit b1: PointedGraphBinder[Rdf, T1], b2: PointedGraphBinder[Rdf, T2]): PointedGraphBinder[Rdf, (T1, T2)] = new PointedGraphBinder[Rdf, (T1, T2)] {
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[(T1, T2)] =
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[(T1, T2)] =
for {
t1 <- (pointed / rdf("_1")).as[T1]
t2 <- (pointed / rdf("_2")).as[T2]
@@ -29,7 +28,7 @@ trait TupleBinder[Rdf <: RDF] {
b2: PointedGraphBinder[Rdf, T2],
b3: PointedGraphBinder[Rdf, T3]): PointedGraphBinder[Rdf, (T1, T2, T3)] = new PointedGraphBinder[Rdf, (T1, T2, T3)] {
- def fromPointedGraph(pointed: PointedGraph[Rdf]): BananaValidation[(T1, T2, T3)] =
+ def fromPointedGraph(pointed: PointedGraph[Rdf]): Try[(T1, T2, T3)] =
for {
t1 <- (pointed / rdf("_1")).as[T1]
t2 <- (pointed / rdf("_2")).as[T2]
6 rdf/src/main/scala/TypedLiteralBinder.scala
View
@@ -1,9 +1,9 @@
package org.w3.banana
-import scalaz._
+import scala.util._
trait TypedLiteralBinder[Rdf <: RDF, T] {
- def fromTypedLiteral(node: Rdf#TypedLiteral): BananaValidation[T]
+ def fromTypedLiteral(node: Rdf#TypedLiteral): Try[T]
def toTypedLiteral(t: T): Rdf#TypedLiteral
}
@@ -12,7 +12,7 @@ object TypedLiteralBinder {
def toLiteralBinder[Rdf <: RDF, T](implicit ops: RDFOps[Rdf], binder: TypedLiteralBinder[Rdf, T]): LiteralBinder[Rdf, T] =
new LiteralBinder[Rdf, T] {
- def fromLiteral(literal: Rdf#Literal): BananaValidation[T] =
+ def fromLiteral(literal: Rdf#Literal): Try[T] =
ops.foldLiteral(literal)(
tl => binder.fromTypedLiteral(tl),
ll => Failure(FailedConversion(ll.toString + " is a LangLiteral, not a TypedLiteral"))
8 rdf/src/main/scala/UriBinder.scala
View
@@ -1,13 +1,13 @@
package org.w3.banana
-import scalaz._
+import scala.util._
trait ToURI[Rdf <: RDF, T] {
def toUri(t: T): Rdf#URI
}
trait FromURI[Rdf <: RDF, T] {
- def fromUri(uri: Rdf#URI): BananaValidation[T]
+ def fromUri(uri: Rdf#URI): Try[T]
}
trait URIBinder[Rdf <: RDF, T] extends FromURI[Rdf, T] with ToURI[Rdf, T]
@@ -25,7 +25,7 @@ object URIBinder {
def toNodeBinder[Rdf <: RDF, T](implicit ops: RDFOps[Rdf], binder: URIBinder[Rdf, T]): NodeBinder[Rdf, T] =
new NodeBinder[Rdf, T] {
- def fromNode(node: Rdf#Node): BananaValidation[T] =
+ def fromNode(node: Rdf#Node): Try[T] =
ops.foldNode(node)(
uri => binder.fromUri(uri),
bnode => Failure(FailedConversion(node + " is a BNode, not a URI")),
@@ -38,7 +38,7 @@ object URIBinder {
def naturalBinder[Rdf <: RDF](implicit ops: RDFOps[Rdf]): URIBinder[Rdf, Rdf#URI] =
new URIBinder[Rdf, Rdf#URI] {
- def fromUri(uri: Rdf#URI): BananaValidation[Rdf#URI] = Success(uri)
+ def fromUri(uri: Rdf#URI): Try[Rdf#URI] = Success(uri)
def toUri(t: Rdf#URI): Rdf#URI = t
8 rdf/src/main/scala/Writer.scala
View
@@ -2,7 +2,7 @@ package org.w3.banana
import java.io.{ Writer => jWriter }
import scalax.io._
-import scalaz.Validation
+import scala.util.Try
/**
* @tparam O the type of object that this Writer can serialize
@@ -12,12 +12,12 @@ trait Writer[-O, +T] {
def syntax: Syntax[T]
- def write[R <: jWriter](obj: O, wcr: WriteCharsResource[R], base: String): BananaValidation[Unit]
+ def write[R <: jWriter](obj: O, wcr: WriteCharsResource[R], base: String): Try[Unit]
- def write[R](obj: O, outputResource: OutputResource[R], base: String): BananaValidation[Unit] =
+ def write[R](obj: O, outputResource: OutputResource[R], base: String): Try[Unit] =
write(obj, outputResource.writer(Codec.UTF8), base)
- def asString(obj: O, base: String): BananaValidation[String] = {
+ def asString(obj: O, base: String): Try[String] = {
val stringWriter = new java.io.StringWriter
write(obj, Resource.fromWriter(stringWriter), base).map(_ => stringWriter.toString)
}
18 rdf/src/main/scala/package.scala
View
@@ -9,26 +9,8 @@ with BananaSparqlSolutionWriterSelector {
type TripleMatch[Rdf <: RDF] = (Rdf#NodeMatch, Rdf#NodeMatch, Rdf#NodeMatch)
- type BananaValidation[T] = Validation[BananaException, T]
-
- type BananaFuture[T] = util.FutureValidation[BananaException, T]
-
- type SyncRDFStore[Rdf <: RDF] = RDFStore[Rdf, Id]
-
- type AsyncRDFStore[Rdf <: RDF] = RDFStore[Rdf, BananaFuture]
-
- type SyncGraphStore[Rdf <: RDF] = GraphStore[Rdf, Id]
-
- type AsyncGraphStore[Rdf <: RDF] = GraphStore[Rdf, BananaFuture]
-
- type SyncSparqlEngine[Rdf <: RDF] = SparqlEngine[Rdf, Id]
-
- type AsyncSparqlEngine[Rdf <: RDF] = SparqlEngine[Rdf, BananaFuture]
-
-
type SparqlSolutionsWriter[Rdf <: RDF, +T] = Writer[Rdf#Solutions, T]
-
type RDFWriterSelector[Rdf <: RDF] = WriterSelector[Rdf#Graph]
type SparqlSolutionsWriterSelector[Rdf <: RDF] = WriterSelector[Rdf#Solutions]
40 rdf/src/main/scala/util/AkkaDefaults.scala
View
@@ -1,40 +0,0 @@
-package org.w3.banana.util
-
-import akka.actor.ActorSystem
-import akka.dispatch.MessageDispatcher
-import scala.concurrent.util._
-
-trait AkkaDefaults {
- def defaultActorSystem = AkkaDefaults.actorSystem
- implicit def defaultFutureDispatch = AkkaDefaults.defaultFutureDispatch
-}
-
-object AkkaDefaults {
- val actorSystem = ActorSystem("banana-dispatcher")
-
- val defaultFutureDispatch: MessageDispatcher = actorSystem.dispatchers.lookup("banana-async")
-
- val DEFAULT_CONFIG = com.typesafe.config.ConfigFactory.parseString("""
-akka.actor.deployment {
- /rdfstore {
- router = round-robin
- nr-of-instances = 1
- }
-}
-
-banana-dispatcher {
- executor = "fork-join-executor"
- type = "Dispatcher"
- # this makes sure that there is only one actor at a time
- fork-join-executor {
- # Min number of threads to cap factor-based parallelism number to
- parallelism-min = 1
- # Parallelism (threads) ... ceil(available processors * factor)
- parallelism-factor = 3.0
- # Max number of threads to cap factor-based parallelism number to
- parallelism-max = 1
- }
-}
-""")
-
-}
16 rdf/src/main/scala/util/AnySyntax.scala
View
@@ -1,16 +0,0 @@
-package org.w3.banana.util
-
-import org.w3.banana._
-
-import scala.concurrent._
-import scalaz.{ Validation, Success }
-
-class AnyW[T](t: T) {
- def bf(implicit ec: ExecutionContext): BananaFuture[T] = FutureValidation(Future.successful(Success(t)))
-}
-
-trait AnySyntax {
- implicit def anyToAnyW[T](t: T): AnyW[T] = new AnyW(t)
-}
-
-object AnySyntax extends AnySyntax
43 rdf/src/main/scala/util/FutureSyntax.scala
View
@@ -1,43 +0,0 @@
-package org.w3.banana.util
-
-import org.w3.banana.BananaException
-
-import scala.concurrent._
-import akka.dispatch._
-import scala.concurrent.util._
-import scalaz.Validation
-import scalaz.syntax.validation._
-
-trait FutureSyntax /*extends AkkaDefaults*/ {
-
- class FutureW[A](inner: Future[A]) {
- implicit val defaultDuration = Duration("3s")
-
- def await: A = await()
-
- def await(duration: Duration = defaultDuration): A =
- Await.result(inner, duration)
-
- def awaitOption: Option[A] = awaitOption()
-
- def awaitOption(duration: Duration = defaultDuration): Option[A] =
- try {
- Some(await(duration))
- } catch {
- case exn: Exception => None
- }
-
- }
-
- implicit def futureToFutureW[A](f: Future[A]) =
- new FutureW(f)
-
- implicit def futureOfValidationToFutureValidation[F, S](in: Future[Validation[F, S]]): FutureValidation[F, S] =
- FutureValidation(in)
-
- implicit def validationToFutureValidation[F, S](in: Validation[F, S])(implicit ec: ExecutionContext): FutureValidation[F, S] =
- FutureValidation(Future.successful(in))
-
-}
-
-object FutureSyntax extends FutureSyntax
110 rdf/src/main/scala/util/FutureValidation.scala
View
@@ -1,110 +0,0 @@
-package org.w3.banana.util
-
-import akka.dispatch._
-import scala.concurrent._
-import scala.concurrent.util._
-import scalaz._
-import scalaz.Scalaz._
-import java.util.concurrent.TimeoutException
-import org.w3.banana._
-
-case class FutureValidation[F, S](inner: Future[Validation[F, S]]) /*extends AkkaDefaults */ {
-
- implicit val defaultDuration = FutureValidation.defaultDuration
-
- def map[T](fn: (S) => T)(implicit ec: ExecutionContext): FutureValidation[F, T] =
- FutureValidation(inner map { validation => validation map fn })
-
- def flatMap[T](fn: (S) => FutureValidation[F, T])(implicit ec: ExecutionContext): FutureValidation[F, T] =
- FutureValidation(
- inner flatMap { validation =>
- validation fold (
- f => Future.successful(Failure[F, T](f)),
- s => fn(s).inner
- )
- })
-
- def fold[T](failure: (F) => T = identity[F] _, success: (S) => T = identity[S] _)(implicit ec: ExecutionContext): Future[T] =
- inner map { validation => validation fold (failure, success) }
-
- def mapFailure[G](f: F => G)(implicit ec: ExecutionContext): FutureValidation[G, S] =
- FutureValidation(
- this.fold(
- x => Failure(f(x)),
- Success.apply
- )
- )
-
- def foreach[T](f: (S) => T)(implicit ec: ExecutionContext): Unit = {
- this.map(f)
- ()
- }
-
- def orElse[G](f: F => FutureValidation[G, S])(implicit ec: ExecutionContext) =
- inner.flatMap {
- (v: Validation[F, S]) =>
- v.fold(
- x => f(x).inner,
- s => Future.successful(s.success[G])
- )
- }.fv
-
- /** And the success shall be failures and the failures shall be successes. This is how you do logical negation */
- def invert(implicit ec: ExecutionContext): FutureValidation[S, F] =
- FutureValidation(
- inner map (v => v.fold(Success.apply, Failure.apply))
- )
-
- def fv: FutureValidation[F, S] =
- this
-
- def failMap[G](func: F => G)(implicit ec: ExecutionContext): FutureValidation[G, S] =
- FutureValidation(inner map { validation => validation.fold(f => Failure(func(f)), s => Success(s)) })
-
- def await(duration: Duration = defaultDuration)(implicit ev: F <:< BananaException, ec: ExecutionContext): BananaValidation[S] =
- try {
- val bf = this.failMap(ev)
- Await.result(bf.inner, duration)
- } catch {
- case te: TimeoutException => Failure(BananaTimeout(te))
- }
-
- def getOrFail(duration: Duration = defaultDuration)(implicit ev: F <:< BananaException, ec: ExecutionContext): S = {
- val r = await(duration)
- r.fold(t => throw t, s => s)
- }
-
-}
-
-object FutureValidation {
-
- val defaultDuration = Duration("3s")
-
- // TODO: add a Traverse[Traversable] to scalaz-seven
- def sequence[A](in: Iterable[BananaFuture[A]])(implicit executor: ExecutionContext): BananaFuture[List[A]] = {
- val fvs: Iterable[Future[BananaValidation[A]]] = in.view.map(_.inner)
- val futureValidations: Future[Iterable[BananaValidation[A]]] = Future.sequence(fvs)
- FutureValidation {
- futureValidations.map { validations =>
- val v: BananaValidation[List[A]] = validations.toList.sequence[BananaValidation, A]
- v
- }
- }
- }
-
- // implicit def FutureValidationBind[E]: Bind[({ type l[x] = FutureValidation[E, x] })#l] = new Bind[({ type l[x] = FutureValidation[E, x] })#l] {
- // override def map[A, B](x: FutureValidation[E, A])(f: A => B): FutureValidation[E, B] = x map f
- // def bind[A, B](x: FutureValidation[E, A])(f: A => FutureValidation[E, B]): FutureValidation[E, B] = x flatMap f
- // }
-
- implicit def BananaFutureUnsafeExtractor[E]: UnsafeExtractor[({ type l[x] = FutureValidation[E, x] })#l] = new UnsafeExtractor[({ type l[x] = FutureValidation[E, x] })#l] {
- def unsafeExtract[T](fv: => FutureValidation[E, T]): Validation[Exception, T] = {
- try {
- Await.result(fv.inner, defaultDuration).fold(e => Failure(new Exception(e.toString)), Success.apply)
- } catch {
- case e: Exception => Failure(e)
- }
- }
- }
-
-}
9 rdf/src/main/scala/util/UnsafeExtractor.scala
View
@@ -1,9 +0,0 @@
-package org.w3.banana.util
-
-import scalaz.Validation
-
-trait UnsafeExtractor[M[_]] {
-
- def unsafeExtract[T](m: => M[T]): Validation[Exception, T]
-
-}
22 rdf/src/main/scala/util/ValidationSyntax.scala
View
@@ -1,22 +0,0 @@
-package org.w3.banana.util
-
-import org.w3.banana._
-
-import scala.concurrent._
-import scalaz.Validation
-
-class ValidationW[F, S](v: Validation[F, S]) {
- def fv(implicit ec: ExecutionContext): FutureValidation[F, S] = FutureValidation(Future.successful(v))
-}
-
-class BananaValidationW[S](v: BananaValidation[S]) extends ValidationW[BananaException, S](v) {
- def bf(implicit ec: ExecutionContext): BananaFuture[S] = fv
- def getOrFail: S = v.fold(be => throw be, s => s)
-}
-
-trait ValidationSyntax {
- implicit def validationToValidationSyntax[F, S](v: Validation[F, S]): ValidationW[F, S] = new ValidationW(v)
- implicit def bananaValidationToBananaValidationSyntax[S](v: BananaValidation[S]): BananaValidationW[S] = new BananaValidationW(v)
-}
-
-object ValidationSyntax extends ValidationSyntax
20 rdf/src/main/scala/util/package.scala
View
@@ -1,20 +0,0 @@
-package org.w3.banana
-
-import scalaz._
-import Id._
-
-package object util
- extends FutureSyntax
- with ValidationSyntax
- with AnySyntax {
-
- implicit val IdUnsafeExtractor: UnsafeExtractor[Id] = new UnsafeExtractor[Id] {
- def unsafeExtract[T](id: => Id[T]): Validation[Exception, T] =
- try {
- Success(id)
- } catch {
- case e: Exception => Failure(e)
- }
- }
-
-}
Please sign in to comment.
Something went wrong with that request. Please try again.