Skip to content

Commit 39c6af0

Browse files
committed
feat(array): add keepSome
1 parent 3c1d743 commit 39c6af0

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/Core__Array.mjs

+7
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ function filterMap(a, f) {
124124
return r;
125125
}
126126

127+
function keepSome(__x) {
128+
return filterMap(__x, (function (x) {
129+
return x;
130+
}));
131+
}
132+
127133
function flatMap(a, f) {
128134
return Caml_splice_call.spliceObjApply([], "concat", [a.map(f)]);
129135
}
@@ -155,6 +161,7 @@ export {
155161
findIndexOpt ,
156162
reverse ,
157163
filterMap ,
164+
keepSome ,
158165
shuffle ,
159166
shuffleInPlace ,
160167
flatMap ,

src/Core__Array.res

+2
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ let filterMapU = (a, f) => {
216216

217217
let filterMap = (a, f) => filterMapU(a, (. a) => f(a))
218218

219+
let keepSome = filterMap(_, x => x)
220+
219221
// TODO: Change this implementation?
220222
let flatMap = (a, f) => []->concatMany(map(a, f))
221223

src/Core__Array.resi

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ external setUnsafe: (array<'a>, int, 'a) => unit = "%array_unsafe_set"
102102
let findIndexOpt: (array<'a>, 'a => bool) => option<int>
103103
let reverse: array<'a> => array<'a>
104104
let filterMap: (array<'a>, 'a => option<'b>) => array<'b>
105+
let keepSome: array<option<'a>> => array<'a>
105106
let shuffle: array<'a> => array<'a>
106107
let shuffleInPlace: array<'a> => unit
107108
let flatMap: (array<'a>, 'a => array<'b>) => array<'b>

0 commit comments

Comments
 (0)