Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.
/ apex-streams Public archive

Salesforce Apex support for functional-style operations on collections

License

Notifications You must be signed in to change notification settings

MuriloKakazu/apex-streams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apex Streams ☁️

This is an Apex library to support functional-style operations on collections, such as filtering, aggregating, transforming, etc.

This supports both SObjects and user-defined types.

Dependencies

Deploying

Deploy to Salesforce

How to use

Filtering

Filtering by field supports the following operations:

Operation Details
equals() If not primitives, will compare the objects's reference in memory
notEquals() If not primitives, will compare the objects's reference in memory
greaterThan()
lessThan()
greaterThanOrEquals()
lessThanOrEquals()
isIn() Works comparing with Set<Object> only
isNotIn() Works comparing with Set<Object> only
isNull()
hasValue()

Example:

List<Person> filteredPeople = (List<Person>)
    DynamicStream.of(people)
        .filter().field('age').greaterThan(21)
        .filter().field('gender').equals('Male')
        .collect().asListOf(Person.class)

You may also filter using predicates that implement the DynamicPredicate interface:

List<Account> filteredAccount = (List<Account>)
    DynamicStream.of(accounts)
        .filter().keeping(new HasFullBillingAddress())
        .filter().keeping(new HasOrdersAwaitingPayment())
        .collect().asListOf(Account.class)

Grouping/Aggregating

Map<Integer, List<Dynamic>> peopleGroupedByAge =
    DynamicStream.of(people)
        .group().byIntegers('age')

About

Salesforce Apex support for functional-style operations on collections

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages