- 
                Notifications
    
You must be signed in to change notification settings  - Fork 338
 
          Add iterate and iterateIndexed methods for Collections in the stdlib
          #1113
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
8e3b761
              e3d5187
              d353b85
              a3ec194
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -2571,6 +2571,18 @@ abstract external class Collection<out Element> extends Any { | |
| /// The first parameter of [operator] is the zero-based index of the current element. | ||
| abstract function foldIndexed<Result>(initial: Result, operator: (Int, Result, Element) -> Result): Result | ||
| 
     | 
||
| /// Iterate over elements of this collection in order, accumulating a result. | ||
| /// The looping function returns a [Pair] where the first value is a [Boolean] indicating if the iteration | ||
| /// should keep going ([true]) or stop, and the second value is the accumulated result. | ||
| /// This function is similar to [fold], but it can short-circuit. | ||
| abstract function iterate<Result>(initial: Result, loopFunction: (Result, Element) -> Pair<Boolean, Result>): Result | ||
                
       | 
||
| 
     | 
||
| /// Iterate over the indexes and elements of this collection in order, accumulating a result. | ||
| /// The looping function returns a [Pair] where the first value is a [Boolean] indicating if the iteration | ||
| /// should keep going ([true]) or stop, and the second value is the accumulated result. | ||
| /// This function is similar to [foldIndexed], but it can short-circuit. | ||
| abstract function iterateIndexed<Result>(initial: Result, loopFunction: (Int, Result, Element) -> Pair<Boolean, Result>): Result | ||
| 
     | 
||
| /// Folds this collection in iteration order using [operator], starting with the first element. | ||
| /// | ||
| /// Throws if this collection is empty. | ||
| 
          
            
          
           | 
    @@ -3050,6 +3062,9 @@ external class List<out Element> extends Collection<Element> { | |
| external function foldBack<Result>(initial: Result, operator: (Element, Result) -> Result): Result | ||
| external function foldIndexed<Result>(initial: Result, operator: (Int, Result, Element) -> Result): Result | ||
| 
     | 
||
| external function iterate<Result>(initial: Result, loopFunction: (Element, Result) -> Pair<Boolean, Result>): Result | ||
| external function iterateIndexed<Result>(initial: Result, loopFunction: (Int, Result, Element) -> Pair<Boolean, Result>): Result | ||
| 
     | 
||
| external function reduce<Result>(operator: (Element|Result, Element) -> Result): Result | ||
| external function reduceOrNull<Result>(operator: (Element|Result, Element) -> Result): Result? | ||
| 
     | 
||
| 
          
            
          
           | 
    @@ -3191,6 +3206,9 @@ external class Set<out Element> extends Collection<Element> { | |
| external function foldBack<Result>(initial: Result, operator: (Element, Result) -> Result): Result | ||
| external function foldIndexed<Result>(initial: Result, operator: (Int, Result, Element) -> Result): Result | ||
| 
     | 
||
| external function iterate<Result>(initial: Result, loopFunction: (Element, Result) -> Pair<Boolean, Result>): Result | ||
| external function iterateIndexed<Result>(initial: Result, loopFunction: (Int, Result, Element) -> Pair<Boolean, Result>): Result | ||
| 
     | 
||
| external function reduce<Result>(operator: (Element|Result, Element) -> Result): Result | ||
| external function reduceOrNull<Result>(operator: (Element|Result, Element) -> Result): Result? | ||
| 
     | 
||
| 
          
            
          
           | 
    ||
Uh oh!
There was an error while loading. Please reload this page.