Poly-collection is a Scala collection framework that aims to provide an alternative to the standard Scala collection framework. It provides a large range of collection classes, and differs from the standard collection framework in several ways:
-
Full support for graphs, trees, multisets, multimaps and others with various functional operators defined on them.
-
Based on algebraic typeclasses through the Typelevel Scala family projects Cats, Algebra and Spire (
Eq
/Order
/...). This means the equivalence relation / hashing function for sets / maps can be customized via arbitrary typeclass instances. -
Lazy by default: Higher-order transformational functions are nearly always executed in a non-strict manner: functions like
map
,filter
,flatMap
are nearly always evaluated lazily (like Spark). This allows chain application likexs map f filter g reduce h
to be much faster than the standard library. -
Returning-same-trait principle: Instead of the uniform-return-type principle of the Scala standard collection library, Poly-collection returns the most fined-grained trait possible without much performance loss. For example, a
map
applied on anArraySeq
would return a read-only view, or a lazyIndexedSeq
instead of a strictArraySeq
. -
Map
s andSet
s are notIterable
s, instead,map.pairs
orset.keys
are. The nonsensical behavior ofzip
/tail
etc. for Sets/Maps in Scala is removed.map.zip
now means zip-by-keys. -
Various algorithms / data structures provided out of the box: binary search, disjoint sets, Fenwick trees, etc.
-
A fully-fledged
search
subpackage that enables the execution of common search algorithms (BFS, DFS, A*, etc.) on very generic state spaces (of course lazily!). -
Caching utilities:
LRUCache
,Memo
.
-
Implicit conversions from/to Scala & from Java collections to Poly-collections are provided by importing the
objects poly.collection.conversion.{FromJava, FromScala, ToScala}
.
Poly-collection is currently in alpha stage and is progressing into the 0.1 release.
libraryDependencies += "me.tongfei" %% "poly-collection" % "0.1.0"
- SI-2509: Contravariant implicits influences the use of contravariant typeclasses
Eq
/Order
/Hashing
. - SI-2712: Higher-order unification influences the
to
method onTraversable
s when piping to aBitSet
/DenseIntKeyedMap
.
- Remove Spire from the dependencies.