Skip to content

apex-lodash/lo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status

apex-lodash

This class provides some similar utility methods to that of lodash.

Installation

TODO: Add installation guide

Usage

Chunk

Takes a given list and breaks it into several list based on a given size

List<String> myList = new List<String>{ 'a', 'b', 'c', 'd' };
lo.chunk(myList, 2);
// [['a', 'b'], ['c', 'd']]
lo.chunk(myList, 3);
// [['a', 'b', 'c'], ['d']]
lo.chunk(myList, 10);
// [['a', 'b', 'c', 'd']]

Drop

Drops a given number of elements off the "left hand side" of a list

Single drop

List<String> myList = new List<String>{ 'a', 'b', 'c', 'd' };
lo.drop(myList);
// ['b', 'c', 'd']

Provided drop count

List<String> myList = new List<String>{ 'a', 'b', 'c', 'd' };
lo.drop(myList, 2);
// ['c', 'd']

DropRight

Drops a given number of elements off the "right hand side" of a list

Single drop

List<String> myList = new List<String>{ 'a', 'b', 'c', 'd' };
lo.dropRight(myList);
// ['a', 'b', 'c']

Provided drop count

List<String> myList = new List<String>{ 'a', 'b', 'c', 'd' };
lo.dropRight(myList, 2);
// ['a', 'b']

Fill

Fills a list with the given object a given number of times

lo.fill('foo', 3);
// ['foo', 'foo', 'foo']

Initial

Gets all but the last element of a list

List<String> myList = new List<String>{ 'a', 'b', 'c'};
lo.initial(myList);
// ['a','b']

Last

Gets the last item from a list

List<String> myList = new List<String>{ 'a', 'b', 'c', 'd' };
lo.last(myList);
// 'd'

Pluck

Used to pluck a list of fields out of a list of objects

Single object

Account account = ...;
Object lo.pluck(account, 'name');

Single depth

List<Account> accountList = ...;
List<Object> lo.pluck(accountList, 'name');

Multiple depths

List<Case> caseList = ...;
List<Object> lo.pluck(caseList, 'contact.account.name');

Rest

Gets all but the first element of a list

List<String> myList = new List<String>{ 'a', 'b', 'c', 'd' };
lo.rest(myList);
// ['b', 'c', 'd']

Slice

Gets part of a list

From given point to end

List<String> myList = new List<String>{ 'a', 'b', 'c', 'd', 'e' };
lo.slice(myList, 2);
// ['c', 'd', 'e']

From given point to given point

List<String> myList = new List<String>{ 'a', 'b', 'c', 'd', 'e' };
lo.slice(myList, 2, 4);
// ['c', 'd']

Take

Takes a given number of entries off the "left hand side" of a list

List<String> myList = new List<String>{ 'a', 'b', 'c', 'd', 'e' };
lo.take(myList, 2);
// ['a', 'b']

TakeRight

Takes a given number of entries off the "right hand side" of a list

List<String> myList = new List<String>{ 'a', 'b', 'c', 'd', 'e' };
lo.takeRight(myList, 2);
// ['d', 'e']

ToString

Takes a list of Objects and typecasts them to strings

List<Account> accountList = ...;
List<String> lo.toString(lo.pluck(accountList, 'name'));

Union

Combines a list of lists of objects and combines them into a single list

List<List<String>> myList = new List<List<String>>{
	List<String>{'a', 'b'},
	List<String>{'c', 'd'},
	List<String>(),
	List<String>{'e'}
};
lo.union(myList);
// ['a', 'b', 'c', 'd', 'e']

Releases

No releases published

Packages

No packages published