File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed
Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 33## Next version
44
55- Fix: Expose Intl.Common. https://github.com/rescript-association/rescript-core/pull/197
6+ - Add ` Array.flatMapWithIndex ` https://github.com/rescript-association/rescript-core/pull/199
67
78## 1.1.0
89
Original file line number Diff line number Diff line change @@ -230,6 +230,7 @@ let filterMap = (a, f) => {
230230let keepSome = filterMap (_ , x => x )
231231
232232@send external flatMap : (array <'a >, 'a => array <'b >) => array <'b > = "flatMap"
233+ @send external flatMapWithIndex : (array <'a >, ('a , int ) => array <'b >) => array <'b > = "flatMap"
233234
234235let findMap = (arr , f ) => {
235236 let rec loop = i =>
Original file line number Diff line number Diff line change @@ -968,6 +968,30 @@ Console.log(
968968@send
969969external flatMap : (array <'a >, 'a => array <'b >) => array <'b > = "flatMap"
970970
971+ /**
972+ `flatMapWithIndex(array, mapper)` returns a new array concatenating the arrays returned from running `mapper` on all items in `array`.
973+
974+ ## Examples
975+ ```rescript
976+ type language = ReScript | TypeScript | JavaScript
977+
978+ let array = [ReScript, TypeScript, JavaScript]
979+
980+ Console.log(
981+ array->Array.flatMapWithIndex((item, index) =>
982+ switch item {
983+ | ReScript => [index]
984+ | TypeScript => [index, index + 1]
985+ | JavaScript => [index, index + 1, index + 2]
986+ }
987+ ),
988+ )
989+ // [0, 1, 2, 2, 3, 4]
990+ ```
991+ */
992+ @send
993+ external flatMapWithIndex : (array <'a >, ('a , int ) => array <'b >) => array <'b > = "flatMap"
994+
971995/**
972996 `findMap(arr, fn)`
973997
You can’t perform that action at this time.
0 commit comments