-
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.
Add mr Hyde using thirdparty library
- Loading branch information
1 parent
1a2d750
commit b6af98f
Showing
14 changed files
with
278 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
hyde/jvm/src/main/scala/pl/writeonly/scala/hyde/common/states/api/DisjunctionAPIState.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,30 @@ | ||
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.thirdparty._ | ||
|
||
abstract class DisjunctionAPIState(data: UrlsWithThrowableList)(implicit d: Domain) extends AbstractAPIState(data) { | ||
override type HP = SourcePageDisjunction | ||
|
||
def nextData(set: SourcePageDisjunctionSet): UrlsWithThrowableList = { | ||
|
||
val partitioned = set.partition(_.isRight) | ||
|
||
val newWrappedUrls: WrappedUrlSet = partitioned._1 | ||
.flatMap(DisjunctionAPIState.sourcePageDisjunctionToWrappedUrlSet) | ||
|
||
val newThrowableList: ThrowableList = partitioned._2.toList | ||
.flatMap(_.swap.toOption.toList) | ||
|
||
val newUrls = NewUrls(newWrappedUrls) | ||
|
||
data.next(newUrls, newThrowableList) | ||
} | ||
|
||
} | ||
|
||
object DisjunctionAPIState { | ||
val sourcePageDisjunctionToWrappedUrlSet: SourcePageDisjunction => WrappedUrlSet = | ||
_.map(_.getWrappedUrlSet).toOption.toSet.flatten | ||
} |
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
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
13 changes: 13 additions & 0 deletions
13
.../src/main/scala/pl/writeonly/scala/hyde/impl/thirdparty/thirdparty1/DisjunctionHyde.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,13 @@ | ||
package pl.writeonly.scala.hyde.impl.thirdparty.thirdparty1 | ||
|
||
import pl.writeonly.scala.hyde.common.states.notexception.AbstractNextState | ||
|
||
object DisjunctionHyde { | ||
|
||
private val domain = "https://www.writeonly.pl" | ||
|
||
def main(args: Array[String]): Unit = | ||
apply().showResult() | ||
|
||
def apply(): AbstractNextState = DisjunctionState(domain) | ||
} |
19 changes: 19 additions & 0 deletions
19
...src/main/scala/pl/writeonly/scala/hyde/impl/thirdparty/thirdparty1/DisjunctionState.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.thirdparty.thirdparty1 | ||
|
||
import pl.writeonly.scala.hyde.common.states.api.DisjunctionAPIState | ||
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.thirdparty.SourcePageDisjunctionFromInternalUrl | ||
|
||
class DisjunctionState(data: UrlsWithThrowableList)(implicit d: Domain) extends DisjunctionAPIState(data) with AbstractFunctionState { | ||
|
||
override def impureFunction: HPFromInternalUrl = SourcePageDisjunctionFromInternalUrl | ||
|
||
override def nextState(data: UrlsWithThrowableList): AbstractNextState = new DisjunctionState(data) | ||
} | ||
|
||
object DisjunctionState extends AbstractNextStateObject { | ||
|
||
override def fromDomain(implicit d: Domain): AbstractNextState = new DisjunctionState(UrlsWithThrowableList.fromDomain) | ||
} |
13 changes: 13 additions & 0 deletions
13
...main/scala/pl/writeonly/scala/hyde/impl/thirdparty/thirdparty2/DisjunctionBeginHyde.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,13 @@ | ||
package pl.writeonly.scala.hyde.impl.thirdparty.thirdparty2 | ||
|
||
import pl.writeonly.scala.hyde.common.states.notexception.AbstractNextState | ||
|
||
object DisjunctionBeginHyde { | ||
|
||
private val domain = "https://www.writeonly.pl" | ||
|
||
def main(args: Array[String]): Unit = apply().showResult() | ||
|
||
def apply(): AbstractNextState = DisjunctionBeginState(domain) | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...ain/scala/pl/writeonly/scala/hyde/impl/thirdparty/thirdparty2/DisjunctionBeginState.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,33 @@ | ||
package pl.writeonly.scala.hyde.impl.thirdparty.thirdparty2 | ||
|
||
import pl.writeonly.scala.hyde.common.states.api.DisjunctionAPIState | ||
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.thirdparty._ | ||
import scalaz.Scalaz._ | ||
import scalaz.concurrent.Task | ||
|
||
class DisjunctionBeginState(data: UrlsWithThrowableList)(implicit d: Domain) extends DisjunctionAPIState(data) with AbstractNewSetState { | ||
|
||
override def newSet: SourcePageDisjunctionSet = { | ||
|
||
val set: Set[Task[SourcePageDisjunction]] = nextUrls | ||
.map(SourcePageTaskFromInternalUrl.apply) | ||
|
||
val monad: Task[SourcePageDisjunctionSet] = Task.gatherUnordered(set.toSeq).map(_.toSet) | ||
|
||
monad.unsafePerformSync | ||
} | ||
|
||
override def nextState(data: UrlsWithThrowableList): AbstractNextState = new DisjunctionBeginState(data) | ||
} | ||
|
||
object DisjunctionBeginState { | ||
|
||
def apply(domain: String): AbstractNextState = fromDomain(new Domain(domain)) |> AbstractNextState.run | ||
|
||
def fromDomain(implicit d: Domain): AbstractNextState = | ||
new DisjunctionBeginState(UrlsWithThrowableList.fromDomain) | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...c/main/scala/pl/writeonly/scala/hyde/impl/thirdparty/thirdparty3/DisjunctionEndHyde.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,13 @@ | ||
package pl.writeonly.scala.hyde.impl.thirdparty.thirdparty3 | ||
|
||
import pl.writeonly.scala.hyde.common.states.notexception.AbstractNextState | ||
|
||
object DisjunctionEndHyde { | ||
|
||
private val domain = "https://www.writeonly.pl" | ||
|
||
def main(args: Array[String]): Unit = apply().showResult() | ||
|
||
def apply(): AbstractNextState = DisjunctionEndState(domain) | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
.../main/scala/pl/writeonly/scala/hyde/impl/thirdparty/thirdparty3/DisjunctionEndState.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,32 @@ | ||
package pl.writeonly.scala.hyde.impl.thirdparty.thirdparty3 | ||
|
||
import pl.writeonly.scala.hyde.common.states.api.DisjunctionAPIState | ||
import pl.writeonly.scala.hyde.common.states.notexception.AbstractNextState | ||
import pl.writeonly.scala.hyde.common.url.Domain | ||
import pl.writeonly.scala.hyde.common.url.urls.UrlsWithThrowableList | ||
import pl.writeonly.scala.hyde.sourcepage.thirdparty._ | ||
import scalaz.Scalaz._ | ||
import scalaz.concurrent.Task | ||
|
||
class DisjunctionEndState(data: UrlsWithThrowableList)(implicit d: Domain) extends DisjunctionAPIState(data) with AbstractNextState { | ||
|
||
override def next: AbstractNextState = { | ||
|
||
val set: Set[Task[SourcePageDisjunction]] = nextUrls | ||
.map(SourcePageTaskFromInternalUrl.apply) | ||
|
||
val monad: Task[SourcePageDisjunctionSet] = Task.gatherUnordered(set.toSeq).map(_.toSet) | ||
|
||
monad.map(newState).unsafePerformSync | ||
} | ||
|
||
override def nextState(data: UrlsWithThrowableList): AbstractNextState = new DisjunctionEndState(data) | ||
} | ||
|
||
object DisjunctionEndState { | ||
|
||
def apply(domain: String): AbstractNextState = fromDomain(new Domain(domain)) |> AbstractNextState.run | ||
|
||
def fromDomain(implicit d: Domain): AbstractNextState = | ||
new DisjunctionEndState(UrlsWithThrowableList.fromDomain) | ||
} |
15 changes: 15 additions & 0 deletions
15
hyde/jvm/src/main/scala/pl/writeonly/scala/hyde/impl/thirdparty/thirdparty4/TaskHyde.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.thirdparty.thirdparty4 | ||
|
||
import pl.writeonly.scala.hyde.common.states.api._ | ||
|
||
object TaskHyde { | ||
|
||
private val domain = "https://www.writeonly.pl" | ||
|
||
def main(args: Array[String]): Unit = apply().showResult() | ||
|
||
def apply(): DisjunctionAPIState = applyTask().unsafePerformSync | ||
|
||
def applyTask(): ParallelStateTask = TaskState(domain) | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
hyde/jvm/src/main/scala/pl/writeonly/scala/hyde/impl/thirdparty/thirdparty4/TaskState.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.thirdparty.thirdparty4 | ||
|
||
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.thirdparty._ | ||
import scalaz.Scalaz._ | ||
import scalaz.concurrent.Task | ||
|
||
class TaskState(refsWithThrowable: UrlsWithThrowableList)(implicit d: Domain) extends DisjunctionAPIState(refsWithThrowable) { | ||
|
||
override type NextState = TaskState | ||
|
||
override def nextState(data: UrlsWithThrowableList): TaskState = new TaskState(data) | ||
|
||
def nextMonad: Task[TaskState] = { | ||
|
||
val set: Set[Task[SourcePageDisjunction]] = refsWithThrowable.nextUrls | ||
.map(SourcePageTaskFromInternalUrl.apply) | ||
|
||
val monad: Task[SourcePageDisjunctionSet] = Task | ||
.gatherUnordered(set.toSeq) | ||
.map(_.toSet) | ||
|
||
monad.map(newState) | ||
} | ||
|
||
} | ||
|
||
object TaskState { | ||
|
||
def apply(domain: String): ParallelStateTask = fromDomain(new Domain(domain)) |> TaskState.run | ||
|
||
def fromDomain(implicit d: Domain): TaskState = new TaskState(UrlsWithThrowableList.fromDomain) | ||
|
||
def run(state: TaskState): Task[DisjunctionAPIState] = | ||
if (state.isEmptyNextInternalUrls) Task.now(state) else state.nextMonad.flatMap(run) | ||
} |
13 changes: 13 additions & 0 deletions
13
.../pl/writeonly/scala/hyde/sourcepage/thirdparty/SourcePageDisjunctionFromInternalUrl.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,13 @@ | ||
package pl.writeonly.scala.hyde.sourcepage.thirdparty | ||
|
||
import pl.writeonly.scala.hyde.common.url.typed.InternalUrl | ||
import pl.writeonly.scala.hyde.sourcepage.oo.SourcePageFromInternalUrl | ||
import scalaz.Disjunction | ||
import scalaz.Scalaz._ | ||
|
||
object SourcePageDisjunctionFromInternalUrl extends (InternalUrl => SourcePageDisjunction) { | ||
|
||
override def apply(internalUrl: InternalUrl): SourcePageDisjunction = | ||
Disjunction.attempt(internalUrl |> SourcePageFromInternalUrl.apply)(internalUrl.toException) | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...n/scala/pl/writeonly/scala/hyde/sourcepage/thirdparty/SourcePageTaskFromInternalUrl.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,11 @@ | ||
package pl.writeonly.scala.hyde.sourcepage.thirdparty | ||
|
||
import pl.writeonly.scala.hyde.common.url.typed.InternalUrl | ||
import scalaz.Scalaz._ | ||
import scalaz.concurrent.Task | ||
|
||
object SourcePageTaskFromInternalUrl { | ||
|
||
def apply(internalUrl: InternalUrl): SourcePageTask = | ||
Task(internalUrl |> SourcePageDisjunctionFromInternalUrl.apply) | ||
} |
14 changes: 14 additions & 0 deletions
14
hyde/jvm/src/main/scala/pl/writeonly/scala/hyde/sourcepage/thirdparty/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 pl.writeonly.scala.hyde.common.url.exception.UrlException | ||
import scalaz.Disjunction | ||
import scalaz.concurrent.Task | ||
|
||
package object thirdparty { | ||
type SourcePageDisjunction = Disjunction[UrlException, SourcePage] | ||
|
||
type SourcePageDisjunctionSet = Set[SourcePageDisjunction] | ||
|
||
type SourcePageTask = Task[SourcePageDisjunction] | ||
|
||
} |