Skip to content

Instantly share code, notes, and snippets.

@camjo
Created June 28, 2018 10:00
Show Gist options
  • Save camjo/c488596ef1135e8cda3900f3be173057 to your computer and use it in GitHub Desktop.
Save camjo/c488596ef1135e8cda3900f3be173057 to your computer and use it in GitHub Desktop.
Data structure independent plotting
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