Skip to content

Commit

Permalink
#326 removed slice dependency on effect project.
Browse files Browse the repository at this point in the history
  • Loading branch information
simerplaha committed Nov 19, 2021
1 parent efad44d commit 5fc1ed6
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 36 deletions.
8 changes: 3 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ lazy val effect =
.settings(commonSettings)
.settings(publishSettings)
.settings(libraryDependencies ++= commonDependencies(scalaVersion.value))
.dependsOn(utils, testkit % Test)
.dependsOn(slice, utils, testkit % Test)

lazy val core =
project
Expand Down Expand Up @@ -239,6 +239,7 @@ lazy val `core-series` =
.settings(publishSettings)
.settings(libraryDependencies ++= commonDependencies(scalaVersion.value))
.dependsOn(
effect % Test,
testkit % Test,
serializers % Test
)
Expand All @@ -255,10 +256,7 @@ lazy val slice =
.settings(commonSettings)
.settings(publishSettings)
.settings(libraryDependencies ++= commonDependencies(scalaVersion.value))
.dependsOn(
effect,
testkit % Test,
)
.dependsOn(utils, testkit % Test)

lazy val actor =
project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import swaydb.core.segment.Segment
import swaydb.core.segment.cache.sweeper.MemorySweeper
import swaydb.effect.Effect
import swaydb.slice.Slice
import swaydb.slice.SliceIOImplicits._
import swaydb.SliceIOImplicits._
import swaydb.slice.order.KeyOrder
import swaydb.utils.Extension
import swaydb.utils.StorageUnits._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import swaydb.core.segment.block.segment.transient.TransientSegment
import swaydb.core.segment.{Segment, SegmentOption}
import swaydb.core.util.DefIO
import swaydb.slice.Slice
import swaydb.slice.SliceIOImplicits._
import swaydb.SliceIOImplicits._
import swaydb.{Error, IO}

protected case object BehaviourCommit extends LazyLogging {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/swaydb/core/level/Level.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import swaydb.core.util.Exceptions._
import swaydb.core.util._
import swaydb.effect.Effect._
import swaydb.effect.{Dir, Effect, FileLocker}
import swaydb.slice.SliceIOImplicits._
import swaydb.SliceIOImplicits._
import swaydb.slice.order.{KeyOrder, TimeOrder}
import swaydb.slice.{Slice, SliceOption}
import swaydb.utils.{Aggregator, Extension, Futures, IDGenerator}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/swaydb/core/log/Logs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import swaydb.core.log.timer.Timer
import swaydb.core.queue.VolatileQueue
import swaydb.effect.Effect
import swaydb.effect.Effect._
import swaydb.slice.SliceIOImplicits._
import swaydb.SliceIOImplicits._
import swaydb.slice.order.KeyOrder
import swaydb.utils.DropIterator
import swaydb.{Error, IO}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/swaydb/core/log/PersistentLog.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import swaydb.core.log.serialiser.{LogEntryReader, LogEntrySerialiser, LogEntryW
import swaydb.effect.Effect._
import swaydb.effect.{Effect, IOStrategy}
import swaydb.slice.Slice
import swaydb.slice.SliceIOImplicits._
import swaydb.SliceIOImplicits._
import swaydb.slice.order.KeyOrder
import swaydb.utils.Extension

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package swaydb.core.log.serialiser
import com.typesafe.scalalogging.LazyLogging
import swaydb.Error.Log.ExceptionHandler
import swaydb.IO
import swaydb.ReaderBaseIOImplicits._
import swaydb.core.file.reader.Reader
import swaydb.core.log.{LogEntry, RecoveryResult}
import swaydb.core.util.CRC32
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/swaydb/core/segment/Segment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import swaydb.core.segment.ref.search.ThreadReadState
import swaydb.core.skiplist.{SkipList, SkipListTreeMap}
import swaydb.core.util._
import swaydb.effect.Effect
import swaydb.slice.SliceIOImplicits._
import swaydb.SliceIOImplicits._
import swaydb.slice.order.{KeyOrder, TimeOrder}
import swaydb.slice.{MaxKey, Slice, SliceOption}
import swaydb.utils.Collections._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import swaydb.core.segment.block.segment.transient.TransientSegment
import swaydb.core.segment.cache.sweeper.MemorySweeper
import swaydb.core.util.DefIO
import swaydb.slice.Slice
import swaydb.slice.SliceIOImplicits._
import swaydb.SliceIOImplicits._
import swaydb.slice.order.{KeyOrder, TimeOrder}
import swaydb.utils.IDGenerator
import swaydb.{Error, IO}
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala/swaydb/core/CommonAssertions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import swaydb.core.skiplist.SkipListConcurrent
import swaydb.effect.{Effect, IOStrategy}
import swaydb.serializers.Default._
import swaydb.serializers._
import swaydb.slice.SliceIOImplicits._
import swaydb.SliceIOImplicits._
import swaydb.slice.order.{KeyOrder, TimeOrder}
import swaydb.slice.{Reader, Slice, SliceOption, SliceReader}
import swaydb.testkit.RunThis._
Expand Down
30 changes: 30 additions & 0 deletions effect/src/main/scala/swaydb/ReaderBaseIOImplicits.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package swaydb

import swaydb.slice.ReaderBase

import scala.annotation.tailrec

object ReaderBaseIOImplicits {

implicit class ReaderIOImplicits[B](reader: ReaderBase[B]) {

@tailrec
@inline final def foldLeftIO[E: IO.ExceptionHandler, R](result: R)(f: (R, ReaderBase[B]) => IO[E, R]): IO[E, R] =
IO(reader.hasMore) match {
case IO.Left(error) =>
IO.Left(error)

case IO.Right(yes) if yes =>
f(result, reader) match {
case IO.Right(newResult) =>
foldLeftIO(newResult)(f)

case IO.Left(error) =>
IO.Left(error)
}

case _ =>
IO.Right(result)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

package swaydb.slice
package swaydb

import swaydb.IO
import swaydb.slice.Slice

import scala.collection.Iterable
import scala.collection.mutable.ListBuffer
Expand Down Expand Up @@ -243,5 +243,4 @@ object SliceIOImplicits {
}
}
}

}
20 changes: 0 additions & 20 deletions slice/src/main/scala/swaydb/slice/ReaderBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package swaydb.slice

import swaydb.IO
import swaydb.slice.utils.ByteOps
import swaydb.utils.Maybe.Maybe

Expand Down Expand Up @@ -118,25 +117,6 @@ trait ReaderBase[B] { self =>
@inline def reset(): ReaderBase[B] =
this moveTo 0

@tailrec
final def foldLeftIO[E: IO.ExceptionHandler, R](result: R)(f: (R, ReaderBase[B]) => IO[E, R]): IO[E, R] =
IO(hasMore) match {
case IO.Left(error) =>
IO.Left(error)

case IO.Right(yes) if yes =>
f(result, self) match {
case IO.Right(newResult) =>
foldLeftIO(newResult)(f)

case IO.Left(error) =>
IO.Left(error)
}

case _ =>
IO.Right(result)
}

@tailrec
final def foldLeft[R](result: R)(f: (R, ReaderBase[B]) => R): R =
if (hasMore)
Expand Down

0 comments on commit 5fc1ed6

Please sign in to comment.