Skip to content

Commit 2370ea6

Browse files
committed
refactor(array): bind to flatMap instead of reimplementing it
1 parent 12402ae commit 2370ea6

File tree

3 files changed

+2
-9
lines changed

3 files changed

+2
-9
lines changed

src/Core__Array.mjs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import * as Curry from "rescript/lib/es6/curry.js";
44
import * as Js_math from "rescript/lib/es6/js_math.js";
55
import * as Caml_option from "rescript/lib/es6/caml_option.js";
6-
import * as Caml_splice_call from "rescript/lib/es6/caml_splice_call.js";
76

87
function make(len, x) {
98
if (len <= 0) {
@@ -136,10 +135,6 @@ function keepSome(__x) {
136135
}));
137136
}
138137

139-
function flatMap(a, f) {
140-
return Caml_splice_call.spliceObjApply([], "concat", [a.map(f)]);
141-
}
142-
143138
function findMap(arr, f) {
144139
var _i = 0;
145140
while(true) {
@@ -171,7 +166,6 @@ export {
171166
keepSome ,
172167
shuffle ,
173168
shuffleInPlace ,
174-
flatMap ,
175169
findMap ,
176170
}
177171
/* No side effect */

src/Core__Array.res

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ let filterMap = (a, f) => filterMapU(a, (. a) => f(a))
224224

225225
let keepSome = filterMap(_, x => x)
226226

227-
// TODO: Change this implementation?
228-
let flatMap = (a, f) => []->concatMany(map(a, f))
227+
@send external flatMap: (array<'a>, 'a => array<'b>) => array<'b> = "flatMap"
229228

230229
let findMap = (arr, f) => {
231230
let rec loop = i =>

src/Core__Array.resi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ let filterMap: (array<'a>, 'a => option<'b>) => array<'b>
106106
let keepSome: array<option<'a>> => array<'a>
107107
let shuffle: array<'a> => array<'a>
108108
let shuffleInPlace: array<'a> => unit
109-
let flatMap: (array<'a>, 'a => array<'b>) => array<'b>
109+
@send external flatMap: (array<'a>, 'a => array<'b>) => array<'b> = "flatMap"
110110
let findMap: (array<'a>, 'a => option<'b>) => option<'b>
111111

112112
/**

0 commit comments

Comments
 (0)