Created
          September 6, 2018 03:28 
        
      - 
      
- 
        Save ailabs-software/8bcf9daf62488198e9bd0a6df0cfba6a to your computer and use it in GitHub Desktop. 
    First of each distinct value
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class LordeSandwich | |
| { | |
| static List<E> firstOfEach<E, L>(Iterable<E> sourceIterable, ConsumerSupplierFunction<E, L> strategy) | |
| { | |
| Set<L> seenPrimaryKeys = new Set<L>(); | |
| List<E> list = new List<E>(); | |
| for (E element in sourceIterable) | |
| { | |
| L primaryKey = strategy(element); | |
| if ( !seenPrimaryKeys.contains(primaryKey) ) { | |
| seenPrimaryKeys.add(primaryKey); | |
| list.add(element); | |
| } | |
| } | |
| return list; | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment