File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 245
245
_output
246
246
}))
247
247
248
+ ###
249
+ # @meta List
250
+ # @brief Take the first n elements of
251
+ # @param _L the list to work on
252
+ # @param _f the predicate
253
+ # @details The original list is left unmodified.
254
+ # =begin
255
+ # (print (takeWhile [1 2 3 4 5 6 7 8 9 10] (fun (a) (< a 4)))) # [1 2 3]
256
+ # =end
257
+ # @author https://github.com/rakista112
258
+ ##
259
+ (let list:takeWhile (fun (_L _f) {
260
+ (mut _index 0)
261
+ (mut _output [])
262
+
263
+ (mut continue true)
264
+ (while continue
265
+ (if (_f (@ _L _index))
266
+ {
267
+ (set _output (append _output (@ _L _index)))
268
+ (set _index (+ 1 _index))
269
+ }
270
+ (set continue false)
271
+ )
272
+ )
273
+ _output
274
+ }))
275
+
248
276
###
249
277
# @brief Unzip a list of [[a b] [c d]...] into [[a c ...] [b d ...]]
250
278
# @param _L the list to work on
You can’t perform that action at this time.
0 commit comments