Skip to content

Commit

Permalink
Rename snoc and cons to append and prepend for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Jacobowitz committed Aug 14, 2018
1 parent 598c057 commit 76174a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 16 additions & 16 deletions core/src/main/scala/cats/data/Chain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ sealed abstract class Chain[+A] {
/**
* Returns true if there are no elements in this collection.
*/
final def isEmpty: Boolean
def isEmpty: Boolean

/**
* Returns false if there are no elements in this collection.
Expand All @@ -61,37 +61,37 @@ sealed abstract class Chain[+A] {
* Concatenates this with `c` in O(1) runtime.
*/
final def concat[A2 >: A](c: Chain[A2]): Chain[A2] =
append(this, c)
Chain.concat(this, c)

/**
* Alias for concat
*/
final def ++[A2 >: A](c: Chain[A2]): Chain[A2] =
concat(this, c)
concat(c)

/**
* Returns a new Chain consisting of `a` followed by this. O(1) runtime.
*/
final def cons[A2 >: A](a: A2): Chain[A2] =
append(one(a), this)
final def prepend[A2 >: A](a: A2): Chain[A2] =
Chain.concat(one(a), this)

/**
* Alias for [[cons]].
* Alias for [[prepend]].
*/
final def +:[A2 >: A](a: A2): Chain[A2] =
cons(a)
prepend(a)

/**
* Returns a new Chain consisting of this followed by `a`. O(1) runtime.
*/
final def snoc[A2 >: A](a: A2): Chain[A2] =
append(this, one(a))
final def append[A2 >: A](a: A2): Chain[A2] =
Chain.concat(this, one(a))

/**
* Alias for [[snoc]].
* Alias for [[append]].
*/
final def :+[A2 >: A](a: A2): Chain[A2] =
snoc(a)
append(a)

/**
* Applies the supplied function to each element and returns a new Chain.
Expand Down Expand Up @@ -374,7 +374,7 @@ object Chain extends ChainInstances {
private[data] final case class Append[A](left: Chain[A], right: Chain[A])
extends Chain[A] {
def isEmpty: Boolean =
false // b/c `append` constructor doesn't allow either branch to be empty
false // b/c `concat` constructor doesn't allow either branch to be empty
}
private[data] final case class Wrap[A](seq: Seq[A]) extends Chain[A] {
override def isEmpty: Boolean =
Expand All @@ -389,8 +389,8 @@ object Chain extends ChainInstances {
/** Creates a Chain of 1 element. */
def one[A](a: A): Chain[A] = Singleton(a)

/** Appends two Chains. */
def append[A](c: Chain[A], c2: Chain[A]): Chain[A] =
/** Concatenates two Chains. */
def concat[A](c: Chain[A], c2: Chain[A]): Chain[A] =
if (c.isEmpty) c2
else if (c2.isEmpty) c
else Append(c, c2)
Expand Down Expand Up @@ -511,7 +511,7 @@ object Chain extends ChainInstances {
private[data] sealed abstract class ChainInstances {
implicit def catsDataMonoidForChain[A]: Monoid[Chain[A]] = new Monoid[Chain[A]] {
def empty: Chain[A] = Chain.nil
def combine(c: Chain[A], c2: Chain[A]): Chain[A] = Chain.append(c, c2)
def combine(c: Chain[A], c2: Chain[A]): Chain[A] = Chain.concat(c, c2)
}

implicit val catsDataInstancesForChain: Traverse[Chain] with Alternative[Chain] with Monad[Chain] =
Expand All @@ -535,7 +535,7 @@ private[data] sealed abstract class ChainInstances {
G.map2(f(a), gcatb)(_ +: _)
}
def empty[A]: Chain[A] = Chain.nil
def combineK[A](c: Chain[A], c2: Chain[A]): Chain[A] = Chain.append(c, c2)
def combineK[A](c: Chain[A], c2: Chain[A]): Chain[A] = Chain.concat(c, c2)
def pure[A](a: A): Chain[A] = Chain.one(a)
def flatMap[A, B](fa: Chain[A])(f: A => Chain[B]): Chain[B] =
fa.flatMap(f)
Expand Down
2 changes: 1 addition & 1 deletion laws/src/main/scala/cats/laws/discipline/Arbitrary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ object arbitrary extends ArbitraryInstances0 {
case 0 => Gen.const(Chain.nil)
case 1 => A.arbitrary.map(Chain.one)
case 2 => A.arbitrary.flatMap(a1 => A.arbitrary.flatMap(a2 =>
Chain.append(Chain.one(a1), Chain.one(a2))))
Chain.concat(Chain.one(a1), Chain.one(a2))))
case n => Chain.fromSeq(Range.apply(0, n)).foldLeft(Gen.const(Chain.empty[A])) { (gen, _) =>
gen.flatMap(cat => A.arbitrary.map(a => cat :+ a))
}
Expand Down

0 comments on commit 76174a7

Please sign in to comment.