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
public static void streamLog(LogReaderStreamer logReaderStreamer){ | |
logReaderStreamer.read().forEach(logReaderStreamer::stream); | |
} |
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
interface LogReaderStreamer extends LogReader, LogStreamer { | |
} |
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
interface LogReader { | |
List<String> read(); | |
} | |
interface LogStreamer { | |
void stream(String message); | |
} |
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
echoConcat[Id]("Hello", "World!") |
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
echoConcat("Hello": Id[String], "World!": Id[String]) |
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 Monad[F[_]] { | |
def pure[A](value: A): F[A] | |
def flatMap[A, B](value: F[A])(func: A => F[B]): F[B] | |
} |
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
type Id[A] = A |
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
def echoConcat[F[_]: Monad](s1: F[String], s2: F[String]): F[String] = for { | |
x <- s1 | |
y <- s2 | |
} yield s"echo $x $y" | |
echoConcat(Option("Hello"), Option("World!")) |
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
public synchronized void printText(String text) throws PrintingException { | |
final PrintTask printTask = new PrintTask(); | |
PrintingListener printingListener = new PrintingListener() { | |
@Override | |
public void onSuccess(SuccessResult successResult) { | |
printTask.setResult(PrintTask.RESULT_SUCCESS); | |
} | |
@Override |
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
public synchronized void printText(String text) throws PrintingException { | |
final CompletableFuture<SuccessResult> result = new CompletableFuture(); | |
PrintingListener printingListener = new PrintingListener() { | |
@Override | |
public void onSuccess(SuccessResult successResult) { | |
result.complete(successResult); | |
} | |
@Override |