Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
js/src
jvm/src
shared/src
README.md

README.md

io

Build Status Coverage Status org.hammerlab:io_2.* on Maven Central

Miscellaneous IO-related abstractions:

show

cats.Show helpers:

import hammerlab.show._

Exposes:

  • Show instances for Strings, Ints, and Longs
  • .show syntax
  • Show-instance derivations for sealed traits and case classes
  • Show type and inline-definition syntax (also as Show; example)

print

import hammerlab.print._, hammerlab.path._, hammerlab.indent.implicits.tab

Printer

PrintStream-like class for printing Show-able elements to a file or stdout:

implicit val printer = Printer(Path("out.txt"))  // Passing None will write to stdout
print(
  "first line",
  "second line"
)
echo("third line")  // with one argument, need to avoid Predef.print name collision

printer.close
Path("out.txt").read
// first line
// second line
// third line

Print collections up to a maximum number of elements:

import hammerlab.show._  // will use the default Show[Int] instance
implicit val printer = Printer(Path("out.txt"))
implicit val limit = Limit(3)
print(
  1 to 10,
  "Numbers:",
  n  s"First $n numbers:"
)
// First 3 numbers:
// 	1
// 	2
// 	3
//

print(
  1 to 2,
  "Numbers:",
  n  s"First $n numbers:"
)
// Numbers:
// 	1
// 	2

ToLines

Control how classes are serialized to Lines with instances of the ToLines type-class:

case class A(n: Int, s: String)

object A {
  implicit val toLines: ToLines[A] =
    (a: A)  {
      val A(n, s) = a
      Lines(
        s"n: $n",
        indent { s"s: $s" }
      )
    }
}

A(111, "aaa").showLines
// n: 111
// 	s: aaa

timing

Stubs around printing progress messages at intervals:

import hammerlab.timing._

Time a block of code:

val (durationMS, num) = time { (1 to 1000000 toList) size }
// (21, 1000000)

Schedule a "hearbeat" during execution of a block

var n = 0
var m = 0
heartbeat(
  ()  n += 1
) {
  while (n < 2) {
	println(s"n == $n, m == $m, sleeping…")
	m += 1
	Thread.sleep(600)
  }
  (n, m)
}
// n == 0, m == 0, sleeping…
// n == 0, m == 1, sleeping…
// n == 1, m == 2, sleeping…
// n == 1, m == 3, sleeping…
// (2, 4)

exception

Lightly augmented toString/show for exception stack-traces:

import hammerlab.exception._
You can’t perform that action at this time.