File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,11 @@ let mapU a f =
267
267
268
268
let map a f = mapU a (fun[@ bs] a -> f a)
269
269
270
+ let flatMapU a f =
271
+ concatMany (mapU a f)
272
+
273
+ let flatMap a f = flatMapU a (fun[@ bs] a -> f a)
274
+
270
275
let getByU a p =
271
276
let l = length a in
272
277
let i = ref 0 in
Original file line number Diff line number Diff line change @@ -395,6 +395,19 @@ val map: 'a array -> ('a -> 'b ) -> 'b array
395
395
```
396
396
*)
397
397
398
+ val flatMapU : 'a array -> ('a -> 'b array [@ bs]) -> 'b array
399
+ val flatMap : 'a array -> ('a -> 'b array ) -> 'b array
400
+ (* *
401
+ `flatMap xs f `
402
+
403
+ **return** a new array by calling `f` for each element of `xs` from
404
+ the beginning to end, and then concatenating the results
405
+
406
+ ```
407
+ flatMap [|1;2|] (fun x-> [|x + 10;x + 20|]) = [|11;21;12;22|]
408
+ ```
409
+ *)
410
+
398
411
val getByU : 'a array -> ('a -> bool [@ bs]) -> 'a option
399
412
val getBy : 'a array -> ('a -> bool ) -> 'a option
400
413
(* *
Original file line number Diff line number Diff line change @@ -315,6 +315,14 @@ function map(a, f) {
315
315
return mapU ( a , Curry . __1 ( f ) ) ;
316
316
}
317
317
318
+ function flatMapU ( a , f ) {
319
+ return concatMany ( map ( a , f ) ) ;
320
+ }
321
+
322
+ function flatMap ( a , f ) {
323
+ return flatMapU ( a , Curry . __1 ( f ) )
324
+ }
325
+
318
326
function getByU ( a , p ) {
319
327
var l = a . length ;
320
328
var i = 0 ;
@@ -706,6 +714,8 @@ exports.forEachU = forEachU;
706
714
exports . forEach = forEach ;
707
715
exports . mapU = mapU ;
708
716
exports . map = map ;
717
+ exports . flatMapU = flatMapU ;
718
+ exports . flatMap = flatMap ;
709
719
exports . getByU = getByU ;
710
720
exports . getBy = getBy ;
711
721
exports . getIndexByU = getIndexByU ;
You can’t perform that action at this time.
0 commit comments