iterables-js

0.3.0 • Public • Published
//Define a class
class Example {
  constructor(
    public id: number,
    public name: string
  ){}
}
 
//Create a collection that identifies objects by its 'id'
let collection = new Collection<Example>('id');
 
//Adding a new element
let obj = new Example(1, 'Example1');
collection.add(obj);
 
//Adding elements array
let array = [new Example(2, 'Example2')];
collection.addElements(array);
 
//Get element by index
let obj = collection.get(0); //Return obj
 
//Get element by key
let obj = collection.getByKey('1') //Return obj
 
//Removing element
collection.remove(obj);
 
//Check if collection contains an element
collection.contains(obj);
 
//Get collection size
let size = collection.size();
 
//Iterate
for(element of collection.elements())
{
  //
}

Package Sidebar

Install

npm i iterables-js

Weekly Downloads

1

Version

0.3.0

License

ISC

Last publish

Collaborators

  • gricob