Skip to content

Commit

Permalink
refactor(array): bind to flatMap instead of reimplementing it
Browse files Browse the repository at this point in the history
  • Loading branch information
glennsl committed Feb 18, 2023
1 parent 39c6af0 commit 85372d5
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 9 deletions.
6 changes: 0 additions & 6 deletions src/Core__Array.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import * as Curry from "rescript/lib/es6/curry.js";
import * as Js_math from "rescript/lib/es6/js_math.js";
import * as Caml_option from "rescript/lib/es6/caml_option.js";
import * as Caml_splice_call from "rescript/lib/es6/caml_splice_call.js";

function make(len, x) {
if (len <= 0) {
Expand Down Expand Up @@ -130,10 +129,6 @@ function keepSome(__x) {
}));
}

function flatMap(a, f) {
return Caml_splice_call.spliceObjApply([], "concat", [a.map(f)]);
}

function findMap(arr, f) {
var _i = 0;
while(true) {
Expand Down Expand Up @@ -164,7 +159,6 @@ export {
keepSome ,
shuffle ,
shuffleInPlace ,
flatMap ,
findMap ,
}
/* No side effect */
3 changes: 1 addition & 2 deletions src/Core__Array.res
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ let filterMap = (a, f) => filterMapU(a, (. a) => f(a))

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

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

let findMap = (arr, f) => {
let rec loop = i =>
Expand Down
2 changes: 1 addition & 1 deletion src/Core__Array.resi
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ let filterMap: (array<'a>, 'a => option<'b>) => array<'b>
let keepSome: array<option<'a>> => array<'a>
let shuffle: array<'a> => array<'a>
let shuffleInPlace: array<'a> => unit
let flatMap: (array<'a>, 'a => array<'b>) => array<'b>
@send external flatMap: (array<'a>, 'a => array<'b>) => array<'b> = "flatMap"
let findMap: (array<'a>, 'a => option<'b>) => option<'b>

/**
Expand Down

0 comments on commit 85372d5

Please sign in to comment.