Skip to content
/ left-cats Public

a scala implementation of the left-pad javascript library

Notifications You must be signed in to change notification settings

stew/left-cats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

a scala implementation of the left-pad javascript library

Resources

Stars

Watchers

Forks

Packages

No packages published