a scala implementation of the left-pad javascript library
Scala Shell
Latest commit 83590c8 Apr 2, 2016 @stew Merge pull request #14 from ms-tg/patch-2
More whitespace consistency
Permalink
Failed to load latest commit information.
core Merge pull request #14 from ms-tg/patch-2 Apr 2, 2016
project Add doctest Apr 1, 2016
scripts perms Apr 1, 2016
.gitignore initial commit Mar 27, 2016
.travis.yml build on travis Apr 1, 2016
README.md Whitespace consistency Apr 1, 2016
build.sbt build on travis Apr 1, 2016
version.sbt Setting version to 0.1.0 Mar 31, 2016

README.md

left cats

Join the chat at https://gitter.im/stew/left-cats Build Status codecov.io

A scala implementation of the left-pad javascript library

I was inspired by this article to port this to Scala.

Example usage to left-pad a String with spaces:

scala> import left.cats._

scala> LeftPad[String, Char].leftPad("asdf")(10, '-')
res0: String = ------asdf

with syntax:

scala> import LeftPad.ops._

scala> "asdf".leftPad(10, '-')
res1: String = ------asdf

Additionally, this implementation will let you pad arbitrary F[A] structures with As as long as you have implicit cats.Foldable and cats.Alternative instances.

Example usage to left-pad a List[Int] with 0's:

scala> import cats._, cats.implicits._, left.cats._, LeftPad._

scala> LeftPad[List[Int], Int].leftPad(List(1, 2, 3, 4))(8, 0) 
res2: List[Int] = List(0, 0, 0, 0, 1, 2, 3, 4)

with syntax:

scala> import cats._, cats.implicits._, left.cats._, LeftPad._, LeftPad.ops._

scala> List(1, 2, 3, 4).leftPad(8, 0)
res3: List[Int] = List(0, 0, 0, 0, 1, 2, 3, 4)

Of course, it builds in scalaJS as well.