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 3
3
## Next version
4
4
5
5
- 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
6
7
7
8
## 1.1.0
8
9
Original file line number Diff line number Diff line change @@ -230,6 +230,7 @@ let filterMap = (a, f) => {
230
230
let keepSome = filterMap (_ , x => x )
231
231
232
232
@send external flatMap : (array <'a >, 'a => array <'b >) => array <'b > = "flatMap"
233
+ @send external flatMapWithIndex : (array <'a >, ('a , int ) => array <'b >) => array <'b > = "flatMap"
233
234
234
235
let findMap = (arr , f ) => {
235
236
let rec loop = i =>
Original file line number Diff line number Diff line change @@ -968,6 +968,30 @@ Console.log(
968
968
@send
969
969
external flatMap : (array <'a >, 'a => array <'b >) => array <'b > = "flatMap"
970
970
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
+
971
995
/**
972
996
`findMap(arr, fn)`
973
997
You can’t perform that action at this time.
0 commit comments