File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -174,6 +174,21 @@ exports.filter = function (f) {
174
174
} ;
175
175
} ;
176
176
177
+ exports . partition = function ( f ) {
178
+ return function ( xs ) {
179
+ var yes = [ ] ;
180
+ var no = [ ] ;
181
+ for ( var i = 0 ; i < xs . length ; i ++ ) {
182
+ var x = xs [ i ] ;
183
+ if ( f ( x ) )
184
+ yes . push ( x ) ;
185
+ else
186
+ no . push ( x ) ;
187
+ }
188
+ return { yes : yes , no : no } ;
189
+ } ;
190
+ } ;
191
+
177
192
//------------------------------------------------------------------------------
178
193
// Sorting ---------------------------------------------------------------------
179
194
//------------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ module Data.Array
64
64
, concat
65
65
, concatMap
66
66
, filter
67
+ , partition
67
68
, filterM
68
69
, mapMaybe
69
70
, catMaybes
@@ -369,6 +370,13 @@ concatMap = flip bind
369
370
-- | creating a new array.
370
371
foreign import filter :: forall a . (a -> Boolean ) -> Array a -> Array a
371
372
373
+ -- | Partition an array using a predicate function, creating a set of
374
+ -- | new arrays. One for the values satisfying the predicate function
375
+ -- | and one for values that don't.
376
+ foreign import partition :: forall a . (a -> Boolean )
377
+ -> Array a
378
+ -> { yes :: Array a , no :: Array a }
379
+
372
380
-- | Filter where the predicate returns a monadic `Boolean`.
373
381
-- |
374
382
-- | ```purescript
You can’t perform that action at this time.
0 commit comments