@joookiwi/collection v1.8.0
Collection (javascript version)
Table of content
The implementation originated from the @joooKiwi/enumeration and is now a standalone implementation.
The way to think about this is to have the functionalities of other languages
(like Java
, PHP
, C#
, Kotlin
and even Javascript
)
all in one standalone structure.
But, with a possible functional approach using the collections.
The structure is and will be in continuous change to implement almost everything that the other languages have (if it is possible).
Installation
npm install @joookiwi/collection
npm i @joookiwi/collection
npm install --save @joookiwi/collection
npm i -S @joookiwi/collection
npm install --save-dev @joookiwi/collection
npm i -D @joookiwi/collection
Usage
There are 2 different kinds of collections.
A lazy (LazyGenericCollectionHolder
) and an eager (GenericCollectionHolder
) one.
All of which are non-mutable.
So, no computation can be done "normally" in these instances.
But they can always be converted to the Array
, Set
, WeakSet
or even Map
depending on the usage.
It can be separated in different categories.
1. The value methods
2. The loop methods
3. The conversion methods
4. Some utility methods (not part of the CollectionHolder
)
1. The value methods are:
size
,length
&count
isEmpty
&isNotEmpty
hasNull
,includesNull
&containsNull
get
,at
&elementAt
getOrElse
,atOrElse
&elementAtOrElse
getOrNull
,atOrNull
&elementAtOrNull
indexOf
&lastIndexOf
indexOfFirst
&indexOfFirstIndexed
indexOfLast
&indexOfLastIndexed
first
&firstOrNull
last
&lastOrNull
2. The loop methods are:
all
,any
&none
hasOne
,has
,includesOne
,includes
,containsOne
&contains
hasAll
,includesAll
&containsAll
join
filter
&filterIndexed
filterNot
&filterIndexedNot
filterNotNull
&requireNotNull
find
&findIndexed
findLast
&findLastIndexed
slice
map
&mapIndexed
mapNotNull
&mapNotNullIndexed
forEach
&forEachIndexed
3. The conversion methods
objectValuesMap
(a utility method to retrieve the object association ofWeakSet
)toIterator
toArray
&toMutableArray
toSet
&toMutableSet
toWeakSet
&toMutableWeakSet
toMap
&toMutableMap
toReverse
,toReversed
,reversed
toString
,toLocaleString
,toLowerCaseString
,toLocaleLowerCaseString
,toUpperCaseString
&toLocaleUpperCaseString
4. The utility methods (not part of the CollectionHolder
)
asString
,asLocaleString
,asLowerCaseString
,asLocaleLowerCaseString
,asUpperCaseString
&asLocaleUpperCaseString
(These methods will be eventually moved in another project)isMinimalistCollectionHolder
isCollectionHolder
isCollectionIterator
Almost every method is present in the src/method
at the exception of
get(index)
, getOrNull(index)
and getOrElse(index, defaultValue)
that is handled differently based on the type of instance.
The non-implemented methods are size
(with its alias length
& count
)
and isEmpty
with its inverse isNotEmpty
.
The alias methods are not part of the extension function.
It includes includesNull
, containsNull
, atOrElse
,
elementAtOrElse
, atOrDefault
, elementAtOrDefault
,
has
,
includes
, includesOne
, includesAll
,
contains
, containsOne
, containsAll
,
toReversed
& reversed
.
Contribution
You can contribute to great simple packages. All with similar behaviour across different languages (like Java, Kotlin, C# and PHP). It can be done 2 different ways: