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) {
174174 } ;
175175} ;
176176
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+
177192//------------------------------------------------------------------------------
178193// Sorting ---------------------------------------------------------------------
179194//------------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ module Data.Array
6464 , concat
6565 , concatMap
6666 , filter
67+ , partition
6768 , filterM
6869 , mapMaybe
6970 , catMaybes
@@ -369,6 +370,13 @@ concatMap = flip bind
369370-- | creating a new array.
370371foreign import filter :: forall a . (a -> Boolean ) -> Array a -> Array a
371372
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+
372380-- | Filter where the predicate returns a monadic `Boolean`.
373381-- |
374382-- | ```purescript
You can’t perform that action at this time.
0 commit comments