The root of the collection hierarchy.

Collections modelize finite groups of objects, called elements.

The specific behavior and representation of collections is determined by the subclasses of the hierarchy.

The main service of Collection is to provide a stable iterator method usable to retrieve all the elements of the collection.

Additional services are provided. For an implementation point of view, Collection provide a basic implementation of these services using the iterator method. Subclasses often provide a more efficient implementation.

Because of the iterator method, Collections instances can use the for control structure.

var x: Collection[U]
# ...
for u in x do
    # u is a U
    # ...
end

that is equivalent with the following:

var x: Collection[U]
# ...
var i = x.iterator
while i.is_ok do
    var u = i.item # u is a U
    # ...
    i.next
end

Introduced properties

type CONCURRENT: ConcurrentCollection[E]

core :: Collection :: CONCURRENT

Type of the concurrent variant of this collection
fun combinations(r: Int): Collection[SequenceRead[E]]

core :: Collection :: combinations

All r-length combinations on self (in same order) without repeated elements.
fun combinations_with_replacement(r: Int): Collection[SequenceRead[E]]

core :: Collection :: combinations_with_replacement

All r-length combination on self (in same order) with repeated elements.
fun count(item: nullable Object): Int

core :: Collection :: count

How many occurrences of item are in the collection?
fun first: E

core :: Collection :: first

Return the first item of the collection
fun has(item: nullable Object): Bool

core :: Collection :: has

Is item in the collection ?
fun has_all(other: Collection[nullable Object]): Bool

core :: Collection :: has_all

Does the collection contain at least each element of other?
fun has_any(other: Collection[nullable Object]): Bool

core :: Collection :: has_any

Does the collection contain at least one element of other?
fun has_exactly(other: Collection[nullable Object]): Bool

core :: Collection :: has_exactly

Does the collection contain exactly all the elements of other?
fun has_only(item: nullable Object): Bool

core :: Collection :: has_only

Is the collection contain only item?
fun is_empty: Bool

core :: Collection :: is_empty

Is there no item in the collection?
abstract fun iterator: Iterator[E]

core :: Collection :: iterator

Get a new iterator on the collection.
fun join(separator: nullable Text, last_separator: nullable Text): String

core :: Collection :: join

Concatenate and separate each elements with separator.
fun length: Int

core :: Collection :: length

Number of items in the collection.
fun not_empty: Bool

core :: Collection :: not_empty

Alias for not is_empty.
fun permutations(r: Int): Collection[SequenceRead[E]]

core :: Collection :: permutations

All r-length permutations on self (all possible ordering) without repeated elements.
fun plain_to_s: String

core :: Collection :: plain_to_s

Concatenate elements without separators
fun product(r: Int): Collection[SequenceRead[E]]

core :: Collection :: product

Cartesian product, over r times self.
fun rand: E

core :: Collection :: rand

Return a random element form the collection
fun sample(length: Int): Array[E]

core :: Collection :: sample

Return a new array made of (at most) length elements randomly chosen.
fun to_a: Array[E]

core :: Collection :: to_a

Build a new array from a collection
abstract fun to_concurrent: CONCURRENT

core :: Collection :: to_concurrent

Wraps self in a thread-safe collection
fun to_counter: Counter[E]

core :: Collection :: to_counter

Create and fill up a counter with the elements of `self.
fun to_curlslist: CURLSList

core :: Collection :: to_curlslist

Convert Collection[String] to CURLSList
fun to_shuffle: Array[E]

core :: Collection :: to_shuffle

Return a new array made of elements in a random order.

Redefined properties

redef type SELF: Collection[E]

core $ Collection :: SELF

Type of this instance, automatically specialized in every class
redef fun to_s: String

core :: abstract_text $ Collection :: to_s

String representation of the content of the collection.

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type CONCURRENT: ConcurrentCollection[E]

core :: Collection :: CONCURRENT

Type of the concurrent variant of this collection
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun combinations(r: Int): Collection[SequenceRead[E]]

core :: Collection :: combinations

All r-length combinations on self (in same order) without repeated elements.
fun combinations_with_replacement(r: Int): Collection[SequenceRead[E]]

core :: Collection :: combinations_with_replacement

All r-length combination on self (in same order) with repeated elements.
fun count(item: nullable Object): Int

core :: Collection :: count

How many occurrences of item are in the collection?
fun first: E

core :: Collection :: first

Return the first item of the collection
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun has(item: nullable Object): Bool

core :: Collection :: has

Is item in the collection ?
fun has_all(other: Collection[nullable Object]): Bool

core :: Collection :: has_all

Does the collection contain at least each element of other?
fun has_any(other: Collection[nullable Object]): Bool

core :: Collection :: has_any

Does the collection contain at least one element of other?
fun has_exactly(other: Collection[nullable Object]): Bool

core :: Collection :: has_exactly

Does the collection contain exactly all the elements of other?
fun has_only(item: nullable Object): Bool

core :: Collection :: has_only

Is the collection contain only item?
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
fun is_empty: Bool

core :: Collection :: is_empty

Is there no item in the collection?
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
abstract fun iterator: Iterator[E]

core :: Collection :: iterator

Get a new iterator on the collection.
fun join(separator: nullable Text, last_separator: nullable Text): String

core :: Collection :: join

Concatenate and separate each elements with separator.
fun length: Int

core :: Collection :: length

Number of items in the collection.
fun not_empty: Bool

core :: Collection :: not_empty

Alias for not is_empty.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun permutations(r: Int): Collection[SequenceRead[E]]

core :: Collection :: permutations

All r-length permutations on self (all possible ordering) without repeated elements.
fun plain_to_s: String

core :: Collection :: plain_to_s

Concatenate elements without separators
fun product(r: Int): Collection[SequenceRead[E]]

core :: Collection :: product

Cartesian product, over r times self.
fun rand: E

core :: Collection :: rand

Return a random element form the collection
fun sample(length: Int): Array[E]

core :: Collection :: sample

Return a new array made of (at most) length elements randomly chosen.
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun to_a: Array[E]

core :: Collection :: to_a

Build a new array from a collection
abstract fun to_concurrent: CONCURRENT

core :: Collection :: to_concurrent

Wraps self in a thread-safe collection
fun to_counter: Counter[E]

core :: Collection :: to_counter

Create and fill up a counter with the elements of `self.
fun to_curlslist: CURLSList

core :: Collection :: to_curlslist

Convert Collection[String] to CURLSList
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun to_shuffle: Array[E]

core :: Collection :: to_shuffle

Return a new array made of elements in a random order.
package_diagram core::Collection Collection core::Object Object core::Collection->core::Object core::Ref Ref core::Ref->core::Collection core::RemovableCollection RemovableCollection core::RemovableCollection->core::Collection core::SequenceRead SequenceRead core::SequenceRead->core::Collection core::Range Range core::Range->core::Collection pthreads::ConcurrentCollection ConcurrentCollection pthreads::ConcurrentCollection->core::Collection poset::POSet POSet poset::POSet->core::Collection cartesian::Cartesian Cartesian cartesian::Cartesian->core::Collection combinations::CartesianCollection CartesianCollection combinations::CartesianCollection->core::Collection combinations::CombinationCollection CombinationCollection combinations::CombinationCollection->core::Collection ordered_tree::OrderedTree OrderedTree ordered_tree::OrderedTree->core::Collection core::SimpleCollection SimpleCollection core::SimpleCollection->core::RemovableCollection core::SimpleCollection... ... core::SimpleCollection...->core::SimpleCollection core::AbstractArrayRead AbstractArrayRead core::AbstractArrayRead->core::SequenceRead core::Sequence Sequence core::Sequence->core::SequenceRead pthreads::ConcurrentSequenceRead ConcurrentSequenceRead pthreads::ConcurrentSequenceRead->core::SequenceRead pthreads::ConcurrentSequenceRead->pthreads::ConcurrentCollection java::AbstractJavaArray AbstractJavaArray java::AbstractJavaArray->core::SequenceRead json::JsonSequenceRead JsonSequenceRead json::JsonSequenceRead->core::SequenceRead core::AbstractArrayRead... ... core::AbstractArrayRead...->core::AbstractArrayRead core::Sequence... ... core::Sequence...->core::Sequence pthreads::ConcurrentSequenceRead... ... pthreads::ConcurrentSequenceRead...->pthreads::ConcurrentSequenceRead java::AbstractJavaArray... ... java::AbstractJavaArray...->java::AbstractJavaArray json::JsonSequenceRead... ... json::JsonSequenceRead...->json::JsonSequenceRead fca::ConceptLattice ConceptLattice fca::ConceptLattice->poset::POSet fca::ConceptLattice... ... fca::ConceptLattice...->fca::ConceptLattice

Parents

interface Object

core :: Object

The root of the class hierarchy.

Children

class Cartesian[E: nullable Object, F: nullable Object]

cartesian :: Cartesian

A view of a Cartesian-product collection over two collections.
class CartesianCollection[E: nullable Object]

combinations :: CartesianCollection

A view of a Cartesian-product collection over homogeneous collections.
class CombinationCollection[E: nullable Object]

combinations :: CombinationCollection

A view of some combinations over a base collections.
abstract class ConcurrentCollection[E: nullable Object]

pthreads :: ConcurrentCollection

A concurrent variant to the standard Collection
class OrderedTree[E: Object]

ordered_tree :: OrderedTree

Generic structure to manage and display an ordered tree
class POSet[E: nullable Object]

poset :: POSet

Pre-order set graph.
class Range[E: Discrete]

core :: Range

Range of discrete objects.
class Ref[E: nullable Object]

core :: Ref

A collection that contains only one item.
interface RemovableCollection[E: nullable Object]

core :: RemovableCollection

Items can be removed from this collection
interface SequenceRead[E: nullable Object]

core :: SequenceRead

Sequences are indexed collections.

Descendants

abstract class AbstractArray[E: nullable Object]

core :: AbstractArray

Resizable one dimension array of objects.
abstract class AbstractArrayRead[E: nullable Object]

core :: AbstractArrayRead

One dimension array of objects.
extern class AbstractJavaArray[E: Object]

java :: AbstractJavaArray

Java primitive array
class Array[E: nullable Object]

core :: Array

Resizable one dimension array of objects.
class ArrayCmp[E: nullable Comparable]

core :: ArrayCmp

Comparable array for comparable elements.
class ArraySet[E: nullable Object]

core :: ArraySet

A set implemented with an Array.
class BlockingQueue[E: nullable Object]

pthreads :: BlockingQueue

A Blocking queue implemented from a ConcurrentList
class BoxedArray[E: Boxed[Numeric]]

geometry :: BoxedArray

BoxedCollection implemented by an array
interface BoxedCollection[E: Boxed[Numeric]]

geometry :: BoxedCollection

Base for all data structures containing multiple Boxed Objects
class Bytes

core :: Bytes

A buffer containing Byte-manipulation facilities
abstract class CArray[E: nullable Object]

c :: CArray

A thin wrapper around a NativeCArray adding length information
class CByteArray

c :: CByteArray

Wrapper around an array of unsigned char in C (unsigned char*) with length and destroy state
class CCStringArray

c :: CCStringArray

Wrapper around an array of CString in C (char**) with length and destroy state.
class CIntArray

c :: CIntArray

Wrapper around an array of int in C (int*) with length and destroy state
class CUInt16Array

c :: CUInt16Array

Wrapper of a C array of type uint16_t* with length and destroy state
class CircularArray[E: nullable Object]

core :: CircularArray

Efficient data structure to access both end of the sequence.
class ConceptLattice[O: Object, A: Object]

fca :: ConceptLattice

Concept Lattice
class ConcurrentArray[E: nullable Object]

pthreads :: ConcurrentArray

A concurrent variant to the standard Array
class ConcurrentList[E: nullable Object]

pthreads :: ConcurrentList

A concurrent variant to the standard List
abstract class ConcurrentSequence[E: nullable Object]

pthreads :: ConcurrentSequence

A concurrent variant to the standard Sequence
abstract class ConcurrentSequenceRead[E: nullable Object]

pthreads :: ConcurrentSequenceRead

A concurrent variant to the standard SequenceRead
class DQuadTree[E: Boxed[Numeric]]

geometry :: DQuadTree

A dynamic implementation of the quadtree data structure
class DisjointSet[E: nullable Object]

core :: DisjointSet

Data structure to keep track of elements partitioned into disjoint subsets
class DummyArray

dummy_array :: DummyArray

A Set that contains only integers.
class HashSet[E: nullable Object]

core :: HashSet

A Set implemented with a hash table.
class Interfaces

nitcorn :: Interfaces

A list of interfaces with dynamic port listeners
extern class JavaArray

java :: JavaArray

Java primitive array Object[]
extern class JavaBoolArray

java :: JavaBoolArray

Java primitive array boolean[]
extern class JavaByteArray

java :: JavaByteArray

Java primitive array byte[]
extern class JavaCharArray

java :: JavaCharArray

Java primitive array char[]
extern class JavaDoubleArray

java :: JavaDoubleArray

Java primitive array double[]
extern class JavaFloatArray

java :: JavaFloatArray

Java primitive array float[]
extern class JavaIntArray

java :: JavaIntArray

Java primitive array int[]
extern class JavaLongArray

java :: JavaLongArray

Java primitive array long[]
extern class JavaShortArray

java :: JavaShortArray

Java primitive array short[]
class JsonArray

json :: JsonArray

A JSON array.
class JsonSequenceRead[E: nullable Serializable]

json :: JsonSequenceRead

A sequence that can be translated into a JSON array.
class List[E: nullable Object]

core :: List

Double linked lists.
class LiveGroup[E: LiveObject]

scene2d :: LiveGroup

Organizational class to manage groups of sprites and other live objects.
class Mailbox[E: nullable Object]

actors :: Mailbox

A Blocking queue implemented from a ConcurrentList
class MinHeap[E: Object]

core :: MinHeap

A min-heap implemented over an array
class MongoPipeline

mongodb :: MongoPipeline

Mongo pipelines are arrays of aggregation stages
abstract class NeoNodeCollection

neo4j :: NeoNodeCollection

All the nodes in a NeoGraph.
abstract class QuadTree[E: Boxed[Numeric]]

geometry :: QuadTree

Abstract QuadTree implementing the basic functions and data
interface Queue[E: nullable Object]

core :: Queue

Queues are collection that controls how elements are retrieved.
class ReverseBlockingQueue[E: nullable Object]

pthreads :: ReverseBlockingQueue

A collection which is_empty method blocks until it's empty
class SQuadTree[E: Boxed[Numeric]]

geometry :: SQuadTree

Static implementation of the quadtree structure
interface Sequence[E: nullable Object]

core :: Sequence

Sequence are indexed collection.
class SequentialNodeCollection

neo4j :: SequentialNodeCollection

A Neo4j node collection using a sequential identification scheme.
interface Set[E: nullable Object]

core :: Set

Abstract sets.
interface SimpleCollection[E: nullable Object]

core :: SimpleCollection

Items can be added to these collections.
class SpriteSet

gamnit :: SpriteSet

Set of sprites sorting them into different SpriteContext
class TextureSet

gamnit :: TextureSet

Group of Texture
class UnrolledList[E: nullable Object]

more_collections :: UnrolledList

An unrolled linked list
class VirtualHosts

nitcorn :: VirtualHosts

A list of virtual hosts with dynamic port listeners

Class definitions

core $ Collection
# The root of the collection hierarchy.
#
# Collections modelize finite groups of objects, called elements.
#
# The specific behavior and representation of collections is determined
# by the subclasses of the hierarchy.
#
# The main service of Collection is to provide a stable `iterator`
# method usable to retrieve all the elements of the collection.
#
# Additional services are provided.
# For an implementation point of view, Collection provide a basic
# implementation of these services using the `iterator` method.
# Subclasses often provide a more efficient implementation.
#
# Because of the `iterator` method, Collections instances can use
# the `for` control structure.
#
# ~~~nitish
# var x: Collection[U]
# # ...
# for u in x do
#	# u is a U
#	# ...
# end
# ~~~
#
# that is equivalent with the following:
#
# ~~~nitish
# var x: Collection[U]
# # ...
# var i = x.iterator
# while i.is_ok do
#     var u = i.item # u is a U
#     # ...
#     i.next
# end
# ~~~
interface Collection[E]
	# Get a new iterator on the collection.
	fun iterator: Iterator[E] is abstract

	# Is there no item in the collection?
	#
	#     assert [1,2,3].is_empty  == false
	#     assert [1..1[.is_empty   == true
	fun is_empty: Bool do return length == 0

	# Alias for `not is_empty`.
	#
	# Some people prefer to have conditions grammatically easier to read.
	#
	#     assert [1,2,3].not_empty  == true
	#     assert [1..1[.not_empty   == false
	fun not_empty: Bool do return not self.is_empty

	# Number of items in the collection.
	#
	#     assert [10,20,30].length == 3
	#     assert [20..30[.length   == 10
	fun length: Int
	do
		var nb = 0
		for i in self do nb += 1
		return nb
	end

	# Is `item` in the collection ?
	# Comparisons are done with ==
	#
	#     assert [1,2,3].has(2)    == true
	#     assert [1,2,3].has(9)    == false
	#     assert [1..5[.has(2)     == true
	#     assert [1..5[.has(9)     == false
	fun has(item: nullable Object): Bool
	do
		for i in self do if i == item then return true
		return false
	end

	# Is the collection contain only `item`?
	# Comparisons are done with ==
	# Return true if the collection is empty.
	#
	#     assert [1,1,1].has_only(1)         == true
	#     assert [1,2,3].has_only(1)         == false
	#     assert [1..1].has_only(1)          == true
	#     assert [1..3].has_only(1)          == false
	#     assert [3..3[.has_only(1)          == true # empty collection
	#
	# ENSURE `is_empty implies result == true`
	fun has_only(item: nullable Object): Bool
	do
		for i in self do if i != item then return false
		return true
	end

	# How many occurrences of `item` are in the collection?
	# Comparisons are done with ==
	#
	#     assert [10,20,10].count(10)         == 2
	fun count(item: nullable Object): Int
	do
		var nb = 0
		for i in self do if i == item then nb += 1
		return nb
	end

	# Return the first item of the collection
	#
	#     assert [1,2,3].first                == 1
	fun first: E
	do
		assert length > 0
		return iterator.item
	end

	# Does the collection contain at least each element of `other`?
	#
	#     assert [1,3,4,2].has_all([1..2])    == true
	#     assert [1,3,4,2].has_all([1..5])    == false
	#
	# Repeated elements in the collections are not considered.
	#
	#     assert [1,1,1].has_all([1])         == true
	#     assert [1..5].has_all([1,1,1])      == true
	#
	# Note that the default implementation is general and correct for any lawful Collections.
	# It is memory-efficient but relies on `has` so may be CPU-inefficient for some kind of collections.
	fun has_all(other: Collection[nullable Object]): Bool
	do
		if is_same_instance(other) then return true
		var ol = other.length
		var  l = length
		if ol == 0 then return true
		if l == 0 then return false
		if ol == 1 then return has(other.first)
		for x in other do if not has(x) then return false
		return true
	end

	# Does the collection contain exactly all the elements of `other`?
	#
	# The same elements must be present in both `self` and `other`,
	# but the order of the elements in the collections are not considered.
	#
	#     assert [1..3].has_exactly([3,1,2]) == true  # the same elements
	#     assert [1..3].has_exactly([3,1])   == false # 2 is not in the array
	#     assert [1..2].has_exactly([3,1,2]) == false # 3 is not in the range
	#
	# Repeated elements must be present in both collections in the same amount.
	# So basically it is a multi-set comparison.
	#
	#     assert [1,2,3,2].has_exactly([1,2,2,3]) == true  # the same elements
	#     assert [1,2,3,2].has_exactly([1,2,3])   == false # more 2 in the first array
	#     assert [1,2,3].has_exactly([1,2,2,3])   == false # more 2 in the second array
	#
	# Note that the default implementation is general and correct for any lawful Collections.
	# It is memory-efficient but relies on `count` so may be CPU-inefficient for some kind of collections.
	fun has_exactly(other: Collection[nullable Object]): Bool
	do
		if length != other.length then return false
		for e in self do if self.count(e) != other.count(e) then return false
		return true
	end

	# Does the collection contain at least one element of `other`?
	#
	#     assert [1,3,4,2].has_any([1..10])    == true
	#     assert [1,3,4,2].has_any([5..10])    == false
	#
	# Note that the default implementation is general and correct for any lawful Collections.
	# It is memory-efficient but relies on `has` so may be CPU-inefficient for some kind of collections.
	fun has_any(other: Collection[nullable Object]): Bool
	do
		for o in other do
			if has(o) then return true
		end
		return false
	end
end
lib/core/collection/abstract_collection.nit:20,1--201,3

core :: array $ Collection
redef class Collection[E]
	# Build a new array from a collection
	fun to_a: Array[E]
	do
		var res = new Array[E].with_capacity(length)
		res.add_all(self)
		return res
	end
end
lib/core/collection/array.nit:965,1--973,3

core :: math $ Collection
redef class Collection[ E ]
	# Return a random element form the collection
	# There must be at least one element in the collection
	#
	# ~~~
	# var x = [1,2,3].rand
	# assert x == 1 or x == 2 or x == 3
	# ~~~
	fun rand: E
	do
		if is_empty then abort
		var rand_index = length.rand

		for e in self do
			if rand_index == 0 then return e
			rand_index -= 1
		end
		abort
	end

	# Return a new array made of elements in a random order.
	#
	# ~~~
	# var a = [1,2,1].to_shuffle
	# assert a == [1,1,2] or a == [1,2,1] or a == [2,1,1]
	# ~~~
	fun to_shuffle: Array[E]
	do
		var res = self.to_a
		res.shuffle
		return res
	end

	# Return a new array made of (at most) `length` elements randomly chosen.
	#
	# ~~~
	# var a = [1,2,1].sample(2)
	# assert a == [1,1] or a == [1,2] or a == [2,1]
	# ~~~
	#
	# If there is not enough elements, then the result only contains them in a random order.
	# See `to_shuffle`.
	#
	# ENSURE `result.length == self.length.min(length)`
	#
	# Note: the default implementation uses the Reservoir Algorithm
	fun sample(length: Int): Array[E]
	do
		if length >= self.length then return to_shuffle

		var res = new Array[E].with_capacity(length)
		var it = iterator
		for i in [0..length[ do
			res[i] = it.item
			it.next
		end
		res.shuffle
		for i in [length+1..self.length] do
			var j = i.rand
			if j < length then
				res[j] = it.item
			end
			it.next
		end
		return res
	end
end
lib/core/math.nit:434,1--500,3

core :: abstract_text $ Collection
redef class Collection[E]
	# String representation of the content of the collection.
	#
	# The standard representation is the list of elements separated with commas.
	#
	# ~~~
	# assert [1,2,3].to_s == "[1,2,3]"
	# assert [1..3].to_s  == "[1,2,3]"
	# assert (new Array[Int]).to_s == "[]" # empty collection
	# ~~~
	#
	# Subclasses may return a more specific string representation.
	redef fun to_s
	do
		return "[" + join(",") + "]"
	end

	# Concatenate elements without separators
	#
	# ~~~
	# assert [1,2,3].plain_to_s == "123"
	# assert [11..13].plain_to_s  == "111213"
	# assert (new Array[Int]).plain_to_s == "" # empty collection
	# ~~~
	fun plain_to_s: String
	do
		var s = new Buffer
		for e in self do if e != null then s.append(e.to_s)
		return s.to_s
	end

	# Concatenate and separate each elements with `separator`.
	#
	# Only concatenate if `separator == null`.
	#
	# ~~~
	# assert [1, 2, 3].join(":")    == "1:2:3"
	# assert [1..3].join(":")       == "1:2:3"
	# assert [1..3].join            == "123"
	# ~~~
	#
	# if `last_separator` is given, then it is used to separate the last element.
	#
	# ~~~
	# assert [1, 2, 3, 4].join(", ", " and ")    == "1, 2, 3 and 4"
	# ~~~
	fun join(separator: nullable Text, last_separator: nullable Text): String
	do
		if is_empty then return ""

		var s = new Buffer # Result

		# Concat first item
		var i = iterator
		var e = i.item
		if e != null then s.append(e.to_s)

		if last_separator == null then last_separator = separator

		# Concat other items
		i.next
		while i.is_ok do
			e = i.item
			i.next
			if i.is_ok then
				if separator != null then s.append(separator)
			else
				if last_separator != null then s.append(last_separator)
			end
			if e != null then s.append(e.to_s)
		end
		return s.to_s
	end
end
lib/core/text/abstract_text.nit:2339,1--2412,3

combinations :: combinations $ Collection
redef class Collection[E]
	# Cartesian product, over `r` times `self`.
	#
	# See `CartesianCollection` for details.
	#
	# FIXME: Cannot be used if RTA is enabled. So `niti` or `--erasure` only.
	fun product(r: Int): Collection[SequenceRead[E]]
	do
		return new CartesianCollection[E]([self]*r)
	end

	# All `r`-length permutations on self (all possible ordering) without repeated elements.
	#
	# See `CartesianCollection` for details.
	#
	# FIXME: Cannot be used if RTA is enabled. So `niti` or `--erasure` only.
	fun permutations(r: Int): Collection[SequenceRead[E]]
	do
		var res = new CombinationCollection[E](self, r)
		res.are_sorted = false
		res.are_unique = true
		return res
	end

	# All `r`-length combinations on self (in same order) without repeated elements.
	#
	# See `CartesianCollection` for details.
	#
	# FIXME: Cannot be used if RTA is enabled. So `niti` or `--erasure` only.
	fun combinations(r: Int): Collection[SequenceRead[E]]
	do
		var res = new CombinationCollection[E](self, r)
		res.are_sorted = true
		res.are_unique = true
		return res
	end

	# All `r`-length combination on self (in same order) with repeated elements.
	#
	# See `CartesianCollection` for details.
	#
	# FIXME: Cannot be used if RTA is enabled. So `niti` or `--erasure` only.
	fun combinations_with_replacement(r: Int): Collection[SequenceRead[E]]
	do
		var res = new CombinationCollection[E](self, r)
		res.are_sorted = true
		res.are_unique = false
		return res
	end
end
lib/combinations/combinations.nit:25,1--74,3

curl :: native_curl $ Collection
redef class Collection[E]
	# Convert Collection[String] to CURLSList
	fun to_curlslist: CURLSList
	do
		assert collectionItemType: self isa Collection[String] else
			print "Collection item must be strings."
		end
		if is_empty then return new CURLSList
		var primList = new CURLSList.with_str(self.first)
		var is_first = true
		for s in self do
			if not is_first then primList.append(s)
			is_first = false
		end
		return primList
	end
end
lib/curl/native_curl.nit:337,1--353,3

pthreads :: concurrent_collections $ Collection
redef class Collection[E]
	# Type of the concurrent variant of this collection
	type CONCURRENT: ConcurrentCollection[E]

	# Wraps `self` in a thread-safe collection
	fun to_concurrent: CONCURRENT is abstract
end
lib/pthreads/concurrent_collections.nit:40,1--46,3

counter :: counter $ Collection
redef class Collection[E]
	# Create and fill up a counter with the elements of `self.
	#
	# ~~~
	# var cpt = "abaa".chars.to_counter
	# assert cpt['a'] == 3
	# assert cpt['b'] == 1
	# assert cpt.length == 2
	# assert cpt.sum == 4
	# ~~~
	fun to_counter: Counter[E]
	do
		var res = new Counter[E]
		res.inc_all(self)
		return res
	end
end
lib/counter/counter.nit:323,1--339,3

json :: serialization_write $ Collection
redef class Collection[E]
	# Utility to serialize a normal Json array
	private fun serialize_to_pure_json(v: JsonSerializer)
	do
		v.stream.write "["
		var is_first = true
		for e in self do
			if is_first then
				is_first = false
			else
				v.stream.write ","
				if v.pretty_json then v.stream.write " "
			end

			if not v.try_to_serialize(e) then
				assert e != null # null would have been serialized
				v.warn("element of type {e.class_name} is not serializable.")
				v.stream.write "null"
			end
		end
		v.stream.write "]"
	end
end
lib/json/serialization_write.nit:306,1--328,3

serialization :: inspect $ Collection
redef class Collection[E]
	private fun serialize_as_inspect(v: InspectSerializer)
	do
		v.stream.write "["
		var is_first = true
		for e in self do
			if is_first then
				is_first = false
			else
				v.stream.write ", "
			end

			if not v.try_to_serialize(e) then
				assert e != null
				v.stream.write e.inspect
			end
		end
		v.stream.write "]"
	end
end
lib/serialization/inspect.nit:239,1--258,3