Skip to content

Commit af77b3a

Browse files
committed
refactor(iter): simplify take and drop
1 parent c54569a commit af77b3a

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/iter.fnk

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,18 @@ unique = fn iterable: new Set iterable
6666

6767
drop = fn num_items: fn items:
6868
pipe items:
69-
map item, idx=0: ([item, idx], idx + 1)
70-
# TODO: should loxia add an accu to filter?
71-
filter [, idx]: idx >= num_items
72-
map [item]: item
69+
filter , idx=0:
70+
(idx >= num_items, idx + 1)
7371

7472

7573
take = fn num_items: fn items:
76-
iter = items.(Symbol.iterator) _
77-
pipe count 0:
78-
while ctr: ctr < num_items
79-
map ctr: iter.next _
80-
while {done}: done == false
81-
map {value}: value
74+
match num_items:
75+
0:
76+
[]
77+
else:
78+
pipe items:
79+
until , ctr=1:
80+
(ctr >= num_items, ctr + 1)
8281

8382

8483
slice = fn start, end=max_int: fn items:

0 commit comments

Comments
 (0)