File tree Expand file tree Collapse file tree 3 files changed +10
-6
lines changed
Expand file tree Collapse file tree 3 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -136,4 +136,7 @@ let mapi f a =
136136 r
137137 end
138138
139+ let append x a =
140+ Js.Array. concat [|x|] a
141+
139142(* TODO: add [append] *)
Original file line number Diff line number Diff line change @@ -85,12 +85,8 @@ val init : int -> (int -> 'a [@bs]) -> 'a t
8585 @param fn callback
8686 @raise RangeError when [n] is negative *)
8787
88- (* val append : 'a t -> 'a t -> 'a t *)
89- (* * create a new array, there is no shallow-sharing
90- between the output and input
91- *)
88+ val append : 'a -> 'a t -> 'a t
89+ (* * [append x a] returns a fresh array with x appended to a *)
9290
9391external unsafe_get : 'a t -> int -> 'a = " %array_unsafe_get"
9492external unsafe_set : 'a t -> int -> 'a -> unit = " %array_unsafe_set"
95-
96-
Original file line number Diff line number Diff line change @@ -143,6 +143,10 @@ function mapi(f, a) {
143143 }
144144}
145145
146+ function append ( x , a ) {
147+ return a . concat ( /* array */ [ x ] ) ;
148+ }
149+
146150exports . filterInPlace = filterInPlace ;
147151exports . empty = empty ;
148152exports . pushBack = pushBack ;
@@ -157,4 +161,5 @@ exports.mapi = mapi;
157161exports . foldLeft = foldLeft ;
158162exports . foldRight = foldRight ;
159163exports . init = init ;
164+ exports . append = append ;
160165/* No side effect */
You can’t perform that action at this time.
0 commit comments