All Downloads are FREE. Search and download functionalities are using the official Maven repository.

algebra.std.string.scala Maven / Gradle / Ivy

The newest version!
package algebra
package std

package object string extends StringInstances

trait StringInstances {
  implicit val stringOrder: Order[String] = new StringOrder
  implicit val stringMonoid = new StringMonoid
}

class StringOrder extends Order[String] {
  def compare(x: String, y: String): Int = x compare y
}

class StringMonoid extends Monoid[String] {
  def empty: String = ""
  def combine(x: String, y: String): String = x + y

  override def combineAll(xs: TraversableOnce[String]): String = {
    val sb = new StringBuilder
    xs.foreach(sb.append)
    sb.toString
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy