Skip to content

Commit

Permalink
make everybody Serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
erikerlandson committed Mar 6, 2017
1 parent 08e836a commit e053dae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/main/scala/com/manyangled/breakable/Breakable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Breakable._
class Breakable[A] private [breakable] (
stream: () => Stream[Try[Any]],
label: Label,
p: A => Boolean) {
p: A => Boolean) extends Serializable {

private [breakable] def rawStream = stream()

Expand Down Expand Up @@ -110,9 +110,9 @@ class Breakable[A] private [breakable] (
}

object Breakable {
trait Label
trait Label extends Serializable

sealed trait Control extends Exception
sealed trait Control extends Exception with Serializable
case class Break(label: Label) extends Control
case class Continue(label: Label) extends Control

Expand Down
9 changes: 5 additions & 4 deletions src/main/scala/com/manyangled/breakable/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package object breakable {
def break(lab: Label): Unit = { throw Break(lab) }
def continue(lab: Label): Unit = { throw Continue(lab) }

implicit class ImplicitForBreakingFilter(b: => Boolean) {
implicit class ImplicitForBreakingFilter(b: => Boolean) extends Serializable {
def break(lab: Label): Boolean = {
if (b) throw Break(lab)
true
Expand All @@ -33,7 +33,7 @@ package object breakable {
}
}

implicit class ImplicitForSequenceResults[A](bkb: Breakable[A]) {
implicit class ImplicitForSequenceResults[A](bkb: Breakable[A]) extends Serializable {
def toStream: Stream[A] = bkb.rawStream.map(_.get).asInstanceOf[Stream[A]]
def toIterator: Iterator[A] = toStream.iterator
def toVector: Vector[A] = toStream.toVector
Expand All @@ -42,13 +42,14 @@ package object breakable {
}

// why you need ClassTag, toArray method?
implicit class ImplicitForArrayResults[A :scala.reflect.ClassTag](bkb: Breakable[A]) {
implicit class ImplicitForArrayResults[A :scala.reflect.ClassTag](bkb: Breakable[A])
extends Serializable {
def toArray: Array[A] = bkb.toStream.toArray
}

def breakable[A](s: => Seq[A]): Breakable[(A, Label)] = Breakable(s)

implicit class ImplicitForBreakableMethod[A](s: => Seq[A]) {
implicit class ImplicitForBreakableMethod[A](s: => Seq[A]) extends Serializable {
def breakable: Breakable[(A, Label)] = Breakable(s)
}
}

0 comments on commit e053dae

Please sign in to comment.