Last active
August 29, 2016 01:04
-
-
Save jsuereth/f8674e291f1015e2134c212b970f9536 to your computer and use it in GitHub Desktop.
Staged Sinks (just a lame cofree).
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
trait CanSink[First, Now, Final, To] { | |
def result[E](in: StagedSink[First, E, Final], f: E => Now): To | |
def result2[E](in: StagedSink[First, E, Final], f: E => TraversableOnce[Now]): To | |
} | |
trait LowPrioritySinkImplicits { | |
implicit def sinkChain[First, E, Final]: CanSink[First, E, Final, StagedSink[First, E, Final]] = ??? | |
} | |
object CanSink extends LowPrioritySinkImplicits { | |
implicit def finalSink[First, E]: CanSink[First, E,E, Sink[First]] = ??? | |
} | |
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
object Example { | |
class User { | |
def livesIn(in: String): Boolean = true | |
def name: String = "Josh" | |
} | |
object stdout extends Sink[String] { | |
override def apply(in: String): Unit = System.out.println(in); | |
} | |
def userSink: Sink[User] = | |
for { | |
user <- stdout.stage[User] | |
if user livesIn "pittsburgh" | |
} yield user.name | |
def result = for { | |
user <- List(new User) | |
} userSink(user) | |
} |
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
trait Sink[To] { | |
def apply(t: To): Unit | |
def stage[E]: StagedSink[E, E, To] = ??? | |
} |
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
trait StagedSink[First, Current, Final] { | |
def map[B, To](f: Current => B)(implicit isDone: CanSink[First, B, Final, To]): To | |
def flatMap[B, To](f: Current => TraversableOnce[B])(implicit isDone: CanSink[First, B, Final, To]): To | |
def withFilter(f: Current => Boolean): StagedSink[First, Current,Final] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment