Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
#181 - introduced list.eachi
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Jun 1, 2023
1 parent bd4b578 commit d1ff03e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/main/eo/org/eolang/collections/list.eo
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
arr.length
i

# @todo #181:30min Wrong order of the attributes of object "f". For some
# reason "reducedi" is the only object that walks through array and where
# function has attributes in next order: accumulator, index, item. All
# other objects like mappedi, filteredi, eachi have attributes in the next
# order: item, index. So "index" must be after "item" object. Also need to
# change the order of attributes in all other objects that use "reducedi"
#
# Reduce with index from start "a" using the function "f".
# Here "f" must be an abstract
# object with three free attributes. The first
Expand Down Expand Up @@ -123,16 +130,28 @@

# For each array element dataize the object
# Here "f" must be an abstract object with
# one free attribute, the element of the
# array.
[f] > each
# two free attributes: the element of the
# array and its index.
[f] > eachi
seq > @
^.reduced
^.reducedi
TRUE
[a x]
f x > @
[a i x]
&.f > @
x
i
TRUE

# For each array element dataize the object
# Here "f" must be an abstract object with
# one free attribute, the element of the
# array.
[f] > each
^.eachi > @
[x i]
&.f > @
x

# Create a new list without the i-th element
[i] > withouti
^.reducedi > @
Expand Down
14 changes: 14 additions & 0 deletions src/test/eo/org/eolang/collections/list-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,20 @@
.each > @
[i] (stdout i > @)

[] > iterates-with-eachi
list
*
"one"
"two"
"three"
.eachi > @
[item index]
stdout > @
sprintf
"[%d]: %s\n"
index
item

[] > list-withouti
assert-that > @
withouti.
Expand Down

1 comment on commit d1ff03e

@0pdd
Copy link

@0pdd 0pdd commented on d1ff03e Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 181-fed906c0 discovered in src/main/eo/org/eolang/collections/list.eo) and submitted as #187. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.