不适合
scala.collection.immutable.Set
,但是
SortedSet
:
scala> import cats.syntax.set._
import cats.syntax.set._
scala> import scala.collection.immutable.SortedSet
import scala.collection.immutable.SortedSet
scala> SortedSet(1, 2, 3).toNes
res0: Option[cats.data.NonEmptySet[Int]] = Some(TreeSet(1, 2, 3))
Set
:
scala> Set(1, 2, 3).to[SortedSet].toNes
res1: Option[cats.data.NonEmptySet[Int]] = Some(TreeSet(1, 2, 3))
猫的
NonEmptySet
(而且Cats不提供
)因为
设置
分类集
scala.math.Ordering
实例,使其更符合Cats中遵循的设计原则(参见。
this issue
更多讨论)。