Skip to content

Claudye/dart-tk-collection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Utils collection toolkit

all

Get all the items in the collection, after some modification/operation

collection.push(1).push(2);
collection.all()

pluck

Extracts a list of values corresponding to a specified key from each item in the collection.

  • Usage: Use pluck to retrieve values of a specific attribute/key from each item in the collection.
  • How to Use: Call pluck on the collection and provide the attribute/key name as a string.
  • Example:
    Collection collection = Collection([
      {'name': 'Alice', 'age': 20},
      {'name': 'Bob', 'age': 23,'notes':[{'english':20,'french':4},{'french':20,'english':7}]}
    ]);
    
    // Extract 'age' attribute from each item
    var ages = collection.pluck<int>('age');
    
     // Extract 'age' attribute from each item
    var ages = collection.pluck<int>('notes.1.english'); // 7
  • Returns: Returns a new collection containing the extracted values of the specified attribute/key from each item.

This method is useful for extracting specific data attributes from a collection for further processing or analysis.

sort

Sorts the collection's items based on the provided criteria.

  • Usage: Use sort to arrange items either by a specific attribute/key or by a custom sorting function.
  • How to Use: Call sort on the collection and provide either a string representing the attribute to sort by or a custom sorting function.
  • Example:
      // for nested object/map in the collection
      collection.sort('notes.courses.dart'); 
      // Sort by the first element of list notes
      collection.sort('notes.0');
      // sort by custum callback
      collection.sort<int>((a, b) => a['age'] - b['age']);
  • Returns: Returns the sorted collection.

This method is useful for organizing data in ascending order based on a specific attribute or applying custom sorting logic to the collection.

where

sum

avg

min

max

count

push

add

remove

filter

every

some

sortByDesc

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages