Scalax
|
|
scalax/data/collection.scala
]
object
collection
extends
AnyRefMethod Summary | |
implicit def
|
Iterable2FilterMap [T](s : scala.Iterable[T]) : FilterMap[T] |
implicit def
|
Iterable2Iterator [T](s : scala.Iterable[T]) : scala.Iterator[T] |
implicit def
|
Iterator2FilterMap [T](s : scala.Iterator[T]) : FilterMap[T] |
implicit def
|
Iterator2XIterator [T](s : scala.Iterator[T]) : XIterator[T] |
implicit def
|
MapToRichMap [k, v](m : scala.collection.immutable.Map[k, v]) : RichMap[k, v] |
implicit def
|
RichMapToMap [k, v](m : RichMap[k, v]) : scala.collection.immutable.Map[k, v] |
implicit def
|
RichStreamToStream [a](s : RichStream[a]) : scala.Stream[a] |
implicit def
|
StreamToRichStream [a](s : scala.Stream[a]) : RichStream[a] |
def
|
all
(xs : scala.Seq[Boolean]) : Boolean
Same as
xs forall (x => x) |
def
|
argmax (xs : scala.Seq[Int]) : (Int, Int) |
def
|
argmin [a, b <: scala.Ordered[b]](xs : scala.Iterator[a])(f : (a) => b) : (a, b, Int) |
def
|
argmin (xs : scala.Seq[Int]) : (Int, Int) |
def
|
argminId
[a <: scala.Ordered[a]](xs : scala.Iterator[a]) : (a, a, Int)
A specialization of argmin that uses the identity function as the
comparison key.
|
def
|
camelToHyphen (s : java.lang.String) : java.lang.String |
def
|
camelToLower
(s : java.lang.String, sep : java.lang.String) : java.lang.String
Convert camel case to lower case with the given inter-word glue string.
|
def
|
camelToSpaced (s : java.lang.String) : java.lang.String |
def
|
camelToUnder (s : java.lang.String) : java.lang.String |
def
|
chunks
[a](n : Int)(xs : scala.Seq[a]) : scala.Stream[scala.Seq[a]]
Return all length-n "chunks" of xs as a stream.
|
def
|
concat
[a](iters : scala.Seq[scala.Iterator[a]]) : scala.Iterator[a]
Concatenate iterators.
|
def
|
coord
[a](i : Int, xss : scala.Iterable[scala.Seq[a]]) : (Int, Int)
Get the i-th element of a flatten list of lists.
|
def
|
dropWhile
[a](iter : scala.Iterator[a])(p : (a) => Boolean) : scala.Iterator[a]
The standard library Iterator.dropWhile is inefficient and non-scalable,
as it is recursive. This is an efficient (tail-recursive) implementation.
|
def
|
groupBy
[a](xs : scala.Seq[a])(pred : (a) => Boolean) : scala.Stream[scala.Seq[a]]
Same as splitBy, but uses the negation of the pred. Note that this is
quite different from Haskell's groupBy.
|
def
|
groupByHeaders
[a](xs : scala.Seq[a])(p : (a) => Boolean) : scala.collection.mutable.ArrayBuffer[scala.collection.mutable.ArrayBuffer[a]]
For each x in xs, if p(x), then x is a header, and it owns all the xs
after it until the next x for which p(x) holds. The return value is the
header and its body.
|
def
|
groupPairwiseBy
[a](xs : scala.Seq[a])(pred : (a, a) => Boolean) : scala.List[scala.List[a]]
Same as Haskell's groupBy. Groups together equal elements, letting the
user supply a custom equality test. Note this is quite different from
groupBy/splitBy.
|
def
|
hist
[a](xs : scala.Iterator[a]) : scala.collection.mutable.HashMap[a, Int]
Given an iterator, return a HashMap from each distinct element to its
count.
|
def
|
indexGroups
[a, b](xs : scala.Seq[a])(f : (a) => b) : scala.Stream[scala.Stream[Int]]
Indexes the result of groupBy.
|
def
|
iterator2array
[a](xs : scala.Iterator[a]) : scala.Array[a]
Convert an iterator to array.
|
def
|
lastIndexWhere
[a](seq : scala.Seq[a])(pred : (a) => Boolean) : Int
Find the index of the last element in the sequence that satisfies the
given predicate.
|
def
|
mean (xs : scala.Seq[Int]) : Int |
def
|
mean (xs : scala.Seq[Double]) : Double |
def
|
meanAndVariance
(xs : scala.Seq[Double]) : (Double, Double)
Return a tuple of the mean and variance of the given sequence.
|
def
|
median (xs : scala.Seq[Long]) : Long |
def
|
merge
[a, b <: scala.Ordered[b]](streams : scala.Seq[scala.BufferedIterator[a]])(f : (a) => b) : scala.Stream[a]
Sort-merge streams. Assumes that the stream are each sorted already.
|
def
|
mins
(xs : scala.Iterable[Long]) : (Long, Long)
Return the two smallest elements.
|
def
|
mod
(n : Int, m : Int) : Int
Return the positive (unsigned int) modulo.
|
def
|
mostPopular
[a](xs : scala.Iterator[a]) : a
Return a list of the most popular element. An arbitrary element may be
returned in case of ties.
|
def
|
multimap
[a, b](xs : scala.Iterable[(a, b)]) : scala.collection.mutable.HashMap[a, scala.collection.mutable.Set[b]] with scala.collection.mutable.MultiMap[a, b]
Construct a multimap out of the given key-value pairs; the result maps
keys to sets of values.
|
def
|
newArrayBuffer
[a](xs : scala.Iterator[a]) : scala.collection.mutable.ArrayBuffer[a]
Convenience constructor for converting an Iterator into an ArrayBuffer.
|
def
|
not
[a](pred : (a) => Boolean)(x : a) : Boolean
Negat a predicate function.
|
def
|
orderedMultimap
[a, b](xs : scala.List[(a, b)]) : scala.collection.mutable.HashMap[a, scala.collection.mutable.ArrayBuffer[b]]
Construct a multimap out of xs, preserving the order of values as they
were input.
|
def
|
pad
[a](n : Int, e : => a, s : scala.Iterator[a]) : scala.Stream[a]
Return a stream of length at least n whose first elements are from the
given iterator, but if the iterator has fewer than n elements, then the
remaining elements are repeat(gen).
|
implicit def
|
pair2xpair (p : (Int, Int)) : XPair |
def
|
pairs
[a](xs : scala.Seq[a]) : scala.Stream[(a, a)]
Return pairs of elements.
|
def
|
pairwise
[a](xs : scala.Iterable[a]) : scala.Iterator[(a, a)]
Same as
slices(_,2) but yields tuples. |
def
|
repeat
[a](gen : => a) : scala.Stream[a]
Return an infinite stream, where each element is an evaluation of gen.
|
def
|
replicate
[a](n : Int, gen : => a) : scala.Stream[a]
Return a stream of n elements, where each element is an evaluation of gen.
|
def
|
rot
(n : Int, s : java.lang.String) : java.lang.String
Rot-n-encode a string, but where all characters are rotated, not just
alphabetical characters.
|
def
|
separateHeads
[a](xss : scala.Seq[scala.Seq[a]]) : scala.Seq[(a, scala.Seq[a])]
Given a list of sublists, return pairs of the first element of each
sublist along with the remaining elements. Empty sublists are ignored.
|
def
|
serializeInt
(i : Int) : java.lang.String
Serialize an Int to a String of four bytes (little-endian).
|
def
|
slices
[a](xs : scala.Seq[a], n : Int) : scala.RandomAccessSeq.Projection[scala.Seq[a]]
Return all length-n slices of xs.
|
def
|
sortCounts
[a](xs : scala.Array[(a, Int)]) : scala.Array[(a, Int)]
Destructively sort the array by the tuples' second elements, and return
the array.
|
def
|
sortCounts
[a](h : scala.collection.mutable.Map[a, Int]) : scala.Seq[(a, Int)]
Return an array of the mappings in the Map, sorted by their entry-values.
|
def
|
sortStats
(xs : scala.Array[Double]) : (Double, Double, Double, Double, Double, Double)
Destructively sort the array, and returns a tuple of the (mean, median,
standard deviation, variance, minimum, and maximum) of a list.
|
def
|
spacedToHyphen
(s : java.lang.String) : java.lang.String
Convert a spaced word to a hyphenated word.
|
def
|
span
[a](n : Int)(xs : scala.Seq[a]) : (scala.Seq[a], scala.Seq[a])
A combination of take and drop.
|
def
|
spanBy
[a](xs : scala.Seq[a])(pred : (a) => Boolean) : (scala.Seq[a], scala.Seq[a])
A combination of takeWhile and dropWhile.
|
def
|
spanstr
[a](n : Int)(xs : java.lang.String) : (java.lang.String, java.lang.String)
Same as span but for Strings, which are treated as an array of chars.
|
def
|
splitBy
[a](xs : scala.Seq[a])(pred : (a) => Boolean) : scala.Stream[scala.Seq[a]]
Split up the sequence by the given predicate. Similar to String.split, but
matching is per-element.
|
def
|
str (xs : scala.Iterable[Char]) : java.lang.String |
def
|
sum (xs : scala.Iterator[Double]) : Double |
def
|
sum (xs : scala.Iterator[Int]) : Int |
def
|
sum (xs : scala.Seq[Double]) : Double |
def
|
swap
[a, b](p : (a, b)) : (b, a)
Swap the elements of a tuple.
|
def
|
take
[a](src : scala.Seq[a], n : Int) : scala.Array[a]
Take an elements from a list.
|
def
|
topHist
[a](xs : scala.Iterator[a], n : Int) : (scala.collection.mutable.HashMap[a, Int], scala.Seq[(a, Int)])
Return a list of the most popular elements along with their histogram
counts.
|
def
|
truncateWhile
[a](seq : scala.Seq[a])(pred : (a) => Boolean) : scala.Seq[a]
Truncate elements off the end of the sequence that satisfy the given
predicate. A reverse dropWhile.
|
def
|
uniq
[a](xs : scala.Seq[a]) : scala.List[a]
Eliminate consecutive duplicates.
|
def
|
untilNull
[a](f : => a) : scala.Iterator[a]
Return an iterator that yields invocations of f until it returns null.
Useful for, e.g., Java's IO stream abstractions.
|
def
|
unzip
[a, b](pairs : scala.Stream[(a, b)]) : (scala.Stream[a], scala.Stream[b])
Given a Stream of pairs, return two Streams over the first and second
elements of the pairs.
|
def
|
unzip
[a, b](pairs : scala.Iterator[(a, b)]) : (scala.Iterator[a], scala.Iterator[b])
Given an Iterator of pairs, return two Iterators over the first and second
elements of the pairs. Note that this operates by duplicating the
iterator and traversing each copy.
|
def
|
words
(x : java.lang.String) : scala.Array[java.lang.String]
Split a String into words. Use this when possible, since its
implementation may become more efficient than the regex-based
String.split() in the future.
|
implicit def
|
xpair2pair (p : XPair) : (Int, Int) |
def
|
zipx
[a](xss : scala.Seq[scala.Iterable[a]]) : scala.Stream[scala.Seq[a]]
Zip or unzip some lists (the zip width is dynamic, so no tuples). The
length of the resulting list is the length of the shortest input list.
|
def
|
zipx
[a](xss : scala.Iterable[scala.Seq[a]]) : scala.List[scala.Iterator[a]]
Zip or unzip some lists (the zip width is dynamic, so no tuples). The
length of the resulting list is the length of the shortest input list.
|
Methods inherited from AnyRef | |
getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized |
Methods inherited from Any | |
==, !=, isInstanceOf, asInstanceOf |
Class Summary | |
case class
|
And
[a](val ts : scala.Seq[BoolTree[a]]) extends BoolTree[a] with scala.Product
|
abstract class
|
BoolTree
[a] extends AnyRef
A boolean expression tree contains nodes corresponding to And, Or, Not,
and Leaf. And, Or contain any number of children.
|
class
|
FilterMap
[T](s : scala.Iterator[T]) extends AnyRef
|
class
|
IdMapper
[a] extends scala.collection.mutable.HashMap[a, Int]
Return a map that assigns unique IDs to distinct objects.
|
case class
|
Leaf
[a](val x : a) extends BoolTree[a] with scala.Product
|
case class
|
Not
[a](val t : BoolTree[a]) extends BoolTree[a] with scala.Product
|
case class
|
Or
[a](val ts : scala.Seq[BoolTree[a]]) extends BoolTree[a] with scala.Product
|
class
|
RichMap
[k, v](val m : scala.collection.immutable.Map[k, v]) extends AnyRef
|
class
|
RichStream
[a](val s : scala.Stream[a]) extends AnyRef
|
case class
|
TreeNode
[a](val value : a, val children : scala.Seq[TreeNode[a]]) extends scala.Product
|
class
|
XIterator
[a](i : scala.Iterator[a]) extends AnyRef
|
case class
|
XPair
(val x : Int, val y : Int) extends scala.Product
|
Object Summary | |
object
|
Tree
extends AnyRef
A simple tree class where each node (Tree) is a Leaf or a Branch, and each
Branch contains a list of other Trees.
|
Method Details |
def
words(x : java.lang.String) : scala.Array[java.lang.String]
def
camelToLower(s : java.lang.String, sep : java.lang.String) : java.lang.String
camelToLower("helloWorld", "_") == "hello_world"
camelToLower("HelloWorld", "_") == "_hello_world"
def
camelToUnder(s : java.lang.String) : java.lang.String
def
camelToHyphen(s : java.lang.String) : java.lang.String
def
camelToSpaced(s : java.lang.String) : java.lang.String
def
spacedToHyphen(s : java.lang.String) : java.lang.String
def
rot(n : Int, s : java.lang.String) : java.lang.String
implicit
def
Iterable2FilterMap[T](s : scala.Iterable[T]) : FilterMap[T]
implicit
def
Iterable2Iterator[T](s : scala.Iterable[T]) : scala.Iterator[T]
implicit
def
Iterator2FilterMap[T](s : scala.Iterator[T]) : FilterMap[T]
implicit
def
Iterator2XIterator[T](s : scala.Iterator[T]) : XIterator[T]
implicit
def
StreamToRichStream[a](s : scala.Stream[a]) : RichStream[a]
implicit
def
RichStreamToStream[a](s : RichStream[a]) : scala.Stream[a]
def
sum(xs : scala.Iterator[Int]) : Int
def
sum(xs : scala.Iterator[Double]) : Double
def
mins(xs : scala.Iterable[Long]) : (Long, Long)
def
sortCounts[a](xs : scala.Array[(a, Int)]) : scala.Array[(a, Int)]
def
hist[a](xs : scala.Iterator[a]) : scala.collection.mutable.HashMap[a, Int]
def
topHist[a](xs : scala.Iterator[a], n : Int) : (scala.collection.mutable.HashMap[a, Int], scala.Seq[(a, Int)])
def
mostPopular[a](xs : scala.Iterator[a]) : a
xs forall (x => x)
def
pairs[a](xs : scala.Seq[a]) : scala.Stream[(a, a)]
pairs([a,b,c,d,e]) == [(a,b),(c,d)]
pairs([a,b,c,d]) == [(a,b),(c,d)]
def
untilNull[a](f : => a) : scala.Iterator[a]
def
groupByHeaders[a](xs : scala.Seq[a])(p : (a) => Boolean) : scala.collection.mutable.ArrayBuffer[scala.collection.mutable.ArrayBuffer[a]]
groupByHeaders([1,2,3,4,5,6,7,8,9])(_%3==0) == [[3,4,5],[6,7,8],[9]]
separateHeads([[a,b,c],[d,e,f,g],[],[h]])
== [(a,[b,c]),(d,[e,f,g]),(h,[])]
def
multimap[a, b](xs : scala.Iterable[(a, b)]) : scala.collection.mutable.HashMap[a, scala.collection.mutable.Set[b]] with
scala.collection.mutable.MultiMap[a, b]
def
orderedMultimap[a, b](xs : scala.List[(a, b)]) : scala.collection.mutable.HashMap[a, scala.collection.mutable.ArrayBuffer[b]]
def
iterator2array[a](xs : scala.Iterator[a]) : scala.Array[a]
span(3)([a,b,c,d,e]) == ([a,b,c],[d,e])
def
spanstr[a](n : Int)(xs : java.lang.String) : (java.lang.String, java.lang.String)
spanstr(3)("abcde") == ("abc","de")
spanBy([1,2,3,4,5])((_ != 3)) == ([1,2],[3,4,5])
[1,3,5,6,7,8] odd == ([1,3,5],[6,7,8])
[] _ == ([],[])
splitBy([1..10], (_ % 4 < 2)) == [[2,3],[6,7],[8,9]]
groupBy([1,2,3,4,5], (_ % 4 < 2)) == [[1],[4,5],[8,9]]
chunks(3)([a..h]) == [[a,b,c],[d,e,f],[g,h]]
slice([a,b,c,d,e], 3) == [[a,b,c],[b,c,d],[c,d,e]]
def
pairwise[a](xs : scala.Iterable[a]) : scala.Iterator[(a, a)]
slices(_,2)
but yields tuples.
pairwise([a]) == []
pairwise([]) == []
pairwise([a,b,c]) == [(a,b),(c,d)]
def
groupPairwiseBy[a](xs : scala.Seq[a])(pred : (a, a) => Boolean) : scala.List[scala.List[a]]
groupPairwiseBy([1..9], (_/3 == _/3)) == [[1,2],[3,4,5],[6,7,8],[9]]]
def
str(xs : scala.Iterable[Char]) : java.lang.String
Iterable mkString ""
def
repeat[a](gen : => a) : scala.Stream[a]
def
replicate[a](n : Int, gen : => a) : scala.Stream[a]
Note that gen may be evaluated more than n times. See "How to add laziness to a strict language, without even being odd"
def
pad[a](n : Int, e : => a, s : scala.Iterator[a]) : scala.Stream[a]
truncateWhile([1,2,3,4,5], (_ != 3)) == [1,2,3]
def
unzip[a, b](pairs : scala.Iterator[(a, b)]) : (scala.Iterator[a], scala.Iterator[b])
def
unzip[a, b](pairs : scala.Stream[(a, b)]) : (scala.Stream[a], scala.Stream[b])
def
indexGroups[a, b](xs : scala.Seq[a])(f : (a) => b) : scala.Stream[scala.Stream[Int]]
[0 1 2 3 4 5 6 7 8 9]
[] == []
[a,b,c,c,c,d,d,e,f,f] == [[0],[1],[2,3,4],[5,6],[7],[8,9]]
def
zipx[a](xss : scala.Seq[scala.Iterable[a]]) : scala.Stream[scala.Seq[a]]
unzipx([[a,f,k],[b,g,l],[c,h,m],[d,i,n]])
== [[a,b,c,d],[f,g,h,i],[k,l,m,n]]
zipx([[a,b,c,d,e],[f,g,h,i,j],[k,l,m,n]])
== [[a,f,k],[b,g,l],[c,h,m],[d,i,n]]
def
zipx[a](xss : scala.Iterable[scala.Seq[a]]) : scala.List[scala.Iterator[a]]
def
concat[a](iters : scala.Seq[scala.Iterator[a]]) : scala.Iterator[a]
def
uniq[a](xs : scala.Seq[a]) : scala.List[a]
def
argminId[a <: scala.Ordered[a]](xs : scala.Iterator[a]) : (a, a, Int)
argminId([]) == error
argminId([b,a,c]) == (a,1)
def
argmin[a, b <: scala.Ordered[b]](xs : scala.Iterator[a])(f : (a) => b) : (a, b, Int)
def
merge[a, b <: scala.Ordered[b]](streams : scala.Seq[scala.BufferedIterator[a]])(f : (a) => b) : scala.Stream[a]
coord(7, [[a,b],[],[c,d,e],[f],[g,h,i],[j,k]]) == h
xss.flatMap(x=>x)(0)
.
def
newArrayBuffer[a](xs : scala.Iterator[a]) : scala.collection.mutable.ArrayBuffer[a]
xs.toElements
.
def
dropWhile[a](iter : scala.Iterator[a])(p : (a) => Boolean) : scala.Iterator[a]
def
take[a](src : scala.Seq[a], n : Int) : scala.Array[a]
def
serializeInt(i : Int) : java.lang.String
Scalax
|
|