Skip to content

Commit

Permalink
Adds version of mkString_ with no prefix/suffix, matching the std lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthughes committed Jan 25, 2019
1 parent 653b56f commit 7a1c65c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion core/src/main/scala/cats/syntax/foldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ final class FoldableOps[F[_], A](private val fa: F[A]) extends AnyVal {
A.combine(prefix, A.combine(F.intercalate(fa, delim), suffix))

/**
* Make a string using `Show`, named as `mkString_` to avoid conflict
* Make a string using `Show`, prefix, delimiter, and suffix.
*
* Named as `mkString_` to avoid conflict.
*
* Example:
* {{{
Expand All @@ -102,6 +104,26 @@ final class FoldableOps[F[_], A](private val fa: F[A]) extends AnyVal {
b.toString.dropRight(delim.length)
} + suffix
}

/**
* Make a string using `Show` and delimiter.
*
* Named as `mkString_` to avoid conflict.
*
* Example:
* {{{
* scala> import cats.implicits._
*
* scala> val l: List[Int] = List(1, 2, 3)
* scala> l.mkString_(",")
* res0: String = 1,2,3
* scala> val el: List[Int] = List()
* scala> el.mkString_(",")
* res1: String =
* }}}
*/
def mkString_(delim: String)(implicit A: Show[A], F: Foldable[F]): String =
mkString_("", delim, "")

/**
* Monadic version of `collectFirstSome`.
Expand Down

0 comments on commit 7a1c65c

Please sign in to comment.