File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -1742,8 +1742,26 @@ export function not_every_QMARK_(pred, coll) {
17421742 return ! every_QMARK_ ( pred , coll ) ;
17431743}
17441744
1745+ function keep1 ( pred ) {
1746+ return ( rf ) => {
1747+ return ( ...args ) => {
1748+ const al = args . length ;
1749+ if ( al === 0 ) return rf ( ) ;
1750+ if ( al === 1 ) return rf ( args [ 0 ] ) ;
1751+ if ( al === 2 ) {
1752+ const result = args [ 0 ] ;
1753+ const input = args [ 1 ] ;
1754+ const v = pred ( input ) ;
1755+ if ( v == null ) return result ;
1756+ return rf ( result , v ) ;
1757+ }
1758+ } ;
1759+ } ;
1760+ }
1761+
17451762export function keep ( pred , coll ) {
17461763 pred = toFn ( pred ) ;
1764+ if ( arguments . length === 1 ) return keep1 ( pred ) ;
17471765 return lazy ( function * ( ) {
17481766 for ( const o of iterable ( coll ) ) {
17491767 const res = pred ( o ) ;
You can’t perform that action at this time.
0 commit comments