Created
June 28, 2018 10:00
-
-
Save camjo/c488596ef1135e8cda3900f3be173057 to your computer and use it in GitHub Desktop.
Data structure independent plotting
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
import scalaz.effect.IO | |
trait Source[F[_], A] { | |
def iterator(s: F[A]): Iterator[A] | |
} | |
object Source { | |
implicit def listSource[A]: Source[List, A] = (s: List[A]) => s.toIterator | |
implicit def streamSource[A]: Source[Stream, A] = (s: Stream[A]) => s.toIterator | |
} | |
def plot[F[_], A](input: F[A]) | |
(implicit ev: Source[F, A]): IO[Unit] = IO[Unit] { | |
// do the actual plotting here | |
ev.iterator(input).foreach(println) | |
} | |
plot(List(1,2,3)).unsafePerformIO() | |
plot(Stream(4, 5, 6, 7)).unsafePerformIO() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment