-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e491e7c
commit 1a2d750
Showing
14 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
hyde/jvm/src/main/scala/pl/writeonly/scala/hyde/common/states/api/EitherAPIState.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package pl.writeonly.scala.hyde.common.states.api | ||
|
||
import pl.writeonly.scala.hyde.common.url._ | ||
import pl.writeonly.scala.hyde.common.url.urls._ | ||
import pl.writeonly.scala.hyde.sourcepage.std._ | ||
|
||
abstract class EitherAPIState(data: UrlsWithThrowableList)(implicit d: Domain) extends AbstractAPIState(data) { | ||
override protected type HP = SourcePageEither | ||
|
||
protected def nextData(set: SourcePageEitherSet): UrlsWithThrowableList = { | ||
|
||
val partitioned = set.partition(_.isRight) | ||
|
||
val newWrappedUrls: WrappedUrlSet = partitioned._1 | ||
.flatMap(EitherAPIState.sourcePageEitherToWrappedUrlSet) | ||
|
||
val newThrowableList: ThrowableList = partitioned._2.toList | ||
.flatMap(_.left.toOption.toList) | ||
|
||
val newUrls = NewUrls(newWrappedUrls) | ||
|
||
data.next(newUrls, newThrowableList) | ||
} | ||
} | ||
|
||
object EitherAPIState { | ||
val sourcePageEitherToWrappedUrlSet: SourcePageEither => WrappedUrlSet = | ||
_.right.map(_.getWrappedUrlSet).right.toOption.toSet.flatten | ||
} |
7 changes: 7 additions & 0 deletions
7
hyde/jvm/src/main/scala/pl/writeonly/scala/hyde/common/states/api/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package pl.writeonly.scala.hyde.common.states | ||
|
||
import scala.concurrent.Future | ||
|
||
package object api { | ||
type ParallelStateFuture = Future[EitherAPIState] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
hyde/jvm/src/main/scala/pl/writeonly/scala/hyde/impl/std/std1/EitherHyde.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package pl.writeonly.scala.hyde.impl.std.std1 | ||
|
||
import pl.writeonly.scala.hyde.common.states.notexception.AbstractNextState | ||
|
||
object EitherHyde { | ||
|
||
private val domain = "https://www.writeonly.pl" | ||
|
||
def main(args: Array[String]): Unit = apply().showResult() | ||
|
||
def apply(): AbstractNextState = EitherState(domain) | ||
} |
19 changes: 19 additions & 0 deletions
19
hyde/jvm/src/main/scala/pl/writeonly/scala/hyde/impl/std/std1/EitherState.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package pl.writeonly.scala.hyde.impl.std.std1 | ||
|
||
import pl.writeonly.scala.hyde.common.states.api.EitherAPIState | ||
import pl.writeonly.scala.hyde.common.states.notexception._ | ||
import pl.writeonly.scala.hyde.common.url.Domain | ||
import pl.writeonly.scala.hyde.common.url.urls.UrlsWithThrowableList | ||
import pl.writeonly.scala.hyde.sourcepage.std.SourcePageEitherFromInternalUrl | ||
|
||
class EitherState(data: UrlsWithThrowableList)(implicit d: Domain) extends EitherAPIState(data) with AbstractFunctionState { | ||
|
||
override protected def nextState(data: UrlsWithThrowableList): AbstractNextState = new EitherState(data) | ||
|
||
override protected def impureFunction: HPFromInternalUrl = SourcePageEitherFromInternalUrl.apply | ||
} | ||
|
||
object EitherState extends AbstractNextStateObject { | ||
|
||
override protected def fromDomain(implicit d: Domain): AbstractNextState = new EitherState(UrlsWithThrowableList.fromDomain) | ||
} |
15 changes: 15 additions & 0 deletions
15
hyde/jvm/src/main/scala/pl/writeonly/scala/hyde/impl/std/std2/EitherBeginHyde.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package pl.writeonly.scala.hyde.impl.std.std2 | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
import pl.writeonly.scala.hyde.common.states.notexception.AbstractNextState | ||
|
||
object EitherBeginHyde { | ||
|
||
private val domain = "https://www.writeonly.pl" | ||
|
||
def main(args: Array[String]): Unit = apply().showResult() | ||
|
||
def apply(): AbstractNextState = EitherBeginState(domain) | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
hyde/jvm/src/main/scala/pl/writeonly/scala/hyde/impl/std/std2/EitherBeginState.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package pl.writeonly.scala.hyde.impl.std.std2 | ||
|
||
import scala.concurrent._ | ||
import scala.concurrent.duration._ | ||
|
||
import pl.writeonly.scala.hyde.common.states.api.EitherAPIState | ||
import pl.writeonly.scala.hyde.common.states.notexception._ | ||
import pl.writeonly.scala.hyde.common.url.Domain | ||
import pl.writeonly.scala.hyde.common.url.urls.UrlsWithThrowableList | ||
import pl.writeonly.scala.hyde.sourcepage.std._ | ||
import scalaz.Scalaz._ | ||
|
||
class EitherBeginState(data: UrlsWithThrowableList)(implicit d: Domain, ec: ExecutionContext) extends EitherAPIState(data) with AbstractNewSetState { | ||
|
||
override protected def nextState(data: UrlsWithThrowableList): AbstractNextState = new EitherBeginState(data) | ||
|
||
override protected def newSet: SourcePageEitherSet = { | ||
|
||
val set: Set[Future[SourcePageEither]] = nextUrls | ||
.map(SourcePageFutureFromInternalUrl.apply) | ||
|
||
val future: Future[SourcePageEitherSet] = Future.sequence(set) | ||
|
||
Await.result(future, 1.minute) | ||
} | ||
} | ||
|
||
object EitherBeginState { | ||
|
||
def apply(domain: String)(implicit ec: ExecutionContext): AbstractNextState = fromDomain(new Domain(domain)) |> AbstractNextState.run | ||
|
||
private def fromDomain(domain: Domain)(implicit ec: ExecutionContext): AbstractNextState = fromDomainAllImplicit(domain, ec) | ||
|
||
private def fromDomainAllImplicit(implicit d: Domain, ec: ExecutionContext): AbstractNextState = | ||
new EitherBeginState(UrlsWithThrowableList.fromDomain) | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
hyde/jvm/src/main/scala/pl/writeonly/scala/hyde/impl/std/std3/EitherEndHyde.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package pl.writeonly.scala.hyde.impl.std.std3 | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
import pl.writeonly.scala.hyde.common.states.notexception.AbstractNextState | ||
|
||
object EitherEndHyde { | ||
|
||
private val domain = "https://www.writeonly.pl" | ||
|
||
def main(args: Array[String]): Unit = apply().showResult() | ||
|
||
def apply(): AbstractNextState = EitherEndState(domain) | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
hyde/jvm/src/main/scala/pl/writeonly/scala/hyde/impl/std/std3/EitherEndState.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package pl.writeonly.scala.hyde.impl.std.std3 | ||
|
||
import scala.concurrent._ | ||
import scala.concurrent.duration._ | ||
|
||
import pl.writeonly.scala.hyde.common.states.api.EitherAPIState | ||
import pl.writeonly.scala.hyde.common.states.notexception._ | ||
import pl.writeonly.scala.hyde.common.url.Domain | ||
import pl.writeonly.scala.hyde.common.url.urls.UrlsWithThrowableList | ||
import pl.writeonly.scala.hyde.sourcepage.std._ | ||
import scalaz.Scalaz._ | ||
|
||
class EitherEndState(data: UrlsWithThrowableList)(implicit d: Domain, ec: ExecutionContext) extends EitherAPIState(data) with AbstractNextState { | ||
|
||
override protected def nextState(data: UrlsWithThrowableList): AbstractNextState = new EitherEndState(data) | ||
|
||
override def next: AbstractNextState = { | ||
|
||
val set: Set[Future[SourcePageEither]] = nextUrls | ||
.map(SourcePageFutureFromInternalUrl.apply) | ||
|
||
val monad: Future[NextState] = Future | ||
.sequence(set) | ||
.map(newState) | ||
|
||
Await.result(monad, 1.minute) | ||
} | ||
} | ||
|
||
object EitherEndState { | ||
|
||
def apply(domain: String)(implicit ec: ExecutionContext): AbstractNextState = fromDomain(new Domain(domain)) |> AbstractNextState.run | ||
|
||
private def fromDomain(domain: Domain)(implicit ec: ExecutionContext): AbstractNextState = fromDomainAllImplicit(domain, ec) | ||
|
||
private def fromDomainAllImplicit(implicit d: Domain, ec: ExecutionContext): AbstractNextState = | ||
new EitherEndState(UrlsWithThrowableList.fromDomain) | ||
} |
19 changes: 19 additions & 0 deletions
19
hyde/jvm/src/main/scala/pl/writeonly/scala/hyde/impl/std/std4/FutureHyde.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package pl.writeonly.scala.hyde.impl.std.std4 | ||
|
||
import scala.concurrent.Await | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import scala.concurrent.duration._ | ||
|
||
import pl.writeonly.scala.hyde.common.states.api._ | ||
|
||
object FutureHyde { | ||
|
||
private val domain = "https://www.writeonly.pl" | ||
|
||
def main(args: Array[String]): Unit = apply().showResult() | ||
|
||
def apply(): EitherAPIState = Await.result(applyFuture(), 1.minute) | ||
|
||
def applyFuture(): ParallelStateFuture = FutureState(domain) | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
hyde/jvm/src/main/scala/pl/writeonly/scala/hyde/impl/std/std4/FutureState.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package pl.writeonly.scala.hyde.impl.std.std4 | ||
|
||
import scala.concurrent._ | ||
|
||
import pl.writeonly.scala.hyde.common.states.api._ | ||
import pl.writeonly.scala.hyde.common.url.Domain | ||
import pl.writeonly.scala.hyde.common.url.urls.UrlsWithThrowableList | ||
import pl.writeonly.scala.hyde.sourcepage.std._ | ||
import scalaz.Scalaz._ | ||
|
||
class FutureState(data: UrlsWithThrowableList)(implicit d: Domain, ec: ExecutionContext) extends EitherAPIState(data) { | ||
|
||
override protected def nextState(data: UrlsWithThrowableList): NextState = new FutureState(data) | ||
|
||
override type NextState = FutureState | ||
|
||
def nextMonad: Future[FutureState] = { | ||
|
||
val set: Set[Future[SourcePageEither]] = nextUrls | ||
.map(SourcePageFutureFromInternalUrl.apply) | ||
|
||
val monad: Future[SourcePageEitherSet] = Future | ||
.sequence(set) | ||
|
||
monad.map(newState) | ||
} | ||
} | ||
|
||
object FutureState { | ||
|
||
def apply(domain: String)(implicit ec: ExecutionContext): ParallelStateFuture = fromDomain(new Domain(domain)) |> run | ||
|
||
private def fromDomain(domain: Domain)(implicit ec: ExecutionContext): FutureState = fromDomainAllImplicit(domain, ec) | ||
|
||
private def fromDomainAllImplicit(implicit d: Domain, ec: ExecutionContext): FutureState = | ||
new FutureState(UrlsWithThrowableList.fromDomain) | ||
|
||
private def run(state: FutureState)(implicit executor: ExecutionContext): Future[EitherAPIState] = | ||
if (state.isEmptyNextInternalUrls) Future.successful(state) else state.nextMonad.flatMap(run) | ||
} |
15 changes: 15 additions & 0 deletions
15
...c/main/scala/pl/writeonly/scala/hyde/sourcepage/std/SourcePageEitherFromInternalUrl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package pl.writeonly.scala.hyde.sourcepage.std | ||
|
||
import scala.util.control.Exception.nonFatalCatch | ||
|
||
import pl.writeonly.scala.hyde.common.url.typed.InternalUrl | ||
import pl.writeonly.scala.hyde.sourcepage.InternalUrlTo | ||
import pl.writeonly.scala.hyde.sourcepage.oo.SourcePageFromInternalUrl | ||
import scalaz.Scalaz._ | ||
|
||
object SourcePageEitherFromInternalUrl extends InternalUrlTo[SourcePageEither] { | ||
|
||
override def apply(internalUrl: InternalUrl): SourcePageEither = applyWithThrowable(internalUrl).left.map(internalUrl.toException) | ||
|
||
private def applyWithThrowable(internalUrl: InternalUrl) = nonFatalCatch either { internalUrl |> SourcePageFromInternalUrl.apply } | ||
} |
12 changes: 12 additions & 0 deletions
12
...c/main/scala/pl/writeonly/scala/hyde/sourcepage/std/SourcePageFutureFromInternalUrl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package pl.writeonly.scala.hyde.sourcepage.std | ||
|
||
import scala.concurrent._ | ||
|
||
import pl.writeonly.scala.hyde.common.url.typed.InternalUrl | ||
import scalaz.Scalaz._ | ||
|
||
object SourcePageFutureFromInternalUrl { | ||
|
||
def apply(internalUrl: InternalUrl)(implicit ec: ExecutionContext): SourcePageFuture = | ||
Future { internalUrl |> SourcePageEitherFromInternalUrl.apply } | ||
} |
14 changes: 14 additions & 0 deletions
14
hyde/jvm/src/main/scala/pl/writeonly/scala/hyde/sourcepage/std/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package pl.writeonly.scala.hyde.sourcepage | ||
|
||
import scala.concurrent.Future | ||
|
||
import pl.writeonly.scala.hyde.common.url.exception.UrlException | ||
|
||
package object std { | ||
type SourcePageEither = Either[UrlException, SourcePage] | ||
|
||
type SourcePageEitherSet = Set[SourcePageEither] | ||
|
||
type SourcePageFuture = Future[SourcePageEither] | ||
|
||
} |