Skip to content

Latest commit

 

History

History
51 lines (34 loc) · 1.66 KB

README.md

File metadata and controls

51 lines (34 loc) · 1.66 KB

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.