Skip to content

Commit 85372d5

Browse files
committed
refactor(array): bind to flatMap instead of reimplementing it
1 parent 39c6af0 commit 85372d5

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) {
@@ -130,10 +129,6 @@ function keepSome(__x) {
130129
}));
131130
}
132131

133-
function flatMap(a, f) {
134-
return Caml_splice_call.spliceObjApply([], "concat", [a.map(f)]);
135-
}
136-
137132
function findMap(arr, f) {
138133
var _i = 0;
139134
while(true) {
@@ -164,7 +159,6 @@ export {
164159
keepSome ,
165160
shuffle ,
166161
shuffleInPlace ,
167-
flatMap ,
168162
findMap ,
169163
}
170164
/* No side effect */

src/Core__Array.res

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

219219
let keepSome = filterMap(_, x => x)
220220

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

224223
let findMap = (arr, f) => {
225224
let rec loop = i =>

src/Core__Array.resi

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

111111
/**

0 commit comments

Comments
 (0)