Skip to content

Commit

Permalink
Merge pull request #185 from maxonfjvipon/collections-hamcrest-strings
Browse files Browse the repository at this point in the history
collections 0.10.0 + hamcrest 0.5.0 + strings 0.5.0
  • Loading branch information
yegor256 authored Oct 5, 2023
2 parents edf0895 + fe1b8d9 commit ee6d14e
Show file tree
Hide file tree
Showing 82 changed files with 491 additions and 292 deletions.
4 changes: 2 additions & 2 deletions objects/org/eolang/collections/bytes-as-array.eo
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

+home https://github.com/objectionary/eo-collections
+package org.eolang.collections
+rt jvm org.eolang:eo-collections:0.0.9
+version 0.0.9
+rt jvm org.eolang:eo-collections:0.10.0
+version 0.10.0

[b] > bytes-as-array
slice-byte > @
Expand Down
9 changes: 4 additions & 5 deletions objects/org/eolang/collections/hash-code-of.eo
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
+alias org.eolang.collections.bytes-as-array
+home https://github.com/objectionary/eo-collections
+package org.eolang.collections
+rt jvm org.eolang:eo-collections:0.0.9
+version 0.0.9
+rt jvm org.eolang:eo-collections:0.10.0
+version 0.10.0

# Hash code - the pseudo-unique integer representation of an object.
#
# Here "h" must be an object that can be converted to bytes via "as-bytes"
# object.
[h] > hash-code-of
Expand All @@ -35,7 +36,7 @@
eq.
h.as-bytes > h-as-bytes!
01-
1232
1231
*
h-as-bytes.eq 00-
1237
Expand Down Expand Up @@ -65,9 +66,7 @@
index.plus 1
bytes
zero-as-bytes

0.as-bytes > zero-as-bytes!

rec-hash-code > @
1
0
Expand Down
128 changes: 71 additions & 57 deletions objects/org/eolang/collections/list.eo
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

+home https://github.com/objectionary/eo-collections
+package org.eolang.collections
+rt jvm org.eolang:eo-collections:0.0.9
+version 0.0.9
+rt jvm org.eolang:eo-collections:0.10.0
+version 0.10.0

[arr] > list
arr > @
Expand All @@ -48,13 +48,11 @@
concat. > @
with.
head.
list
arr
^
i
x
tail.
list
arr
^
minus.
arr.length
i
Expand All @@ -63,8 +61,7 @@
# Here "f" must be an abstract
# object with three free attributes. The first
# one for the accumulator, the second one
# for the index and the third one for the element
# of the array.
# for the element of the array and the third one for the index.
[a f] > reducedi
if. > @
arr.length.eq 0
Expand All @@ -82,8 +79,8 @@
carr.length
func > new-acc
acc-index.at 0
index
carr.at index
index
rec-reduced
*
new-acc
Expand All @@ -95,7 +92,7 @@
[a f] > reduced
^.reducedi > @
a
[a idx item]
[a item idx]
&.f > @
a
item
Expand All @@ -108,7 +105,7 @@
list > @
^.reducedi
*
[a idx item]
[a item idx]
with. > @
a
&.f item idx
Expand All @@ -123,21 +120,33 @@

# 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 x i]
&.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 > @
*
[a idx item]
[a item idx]
if. > @
idx.eq i
a
Expand All @@ -161,7 +170,7 @@
x.length
^.reducedi
TRUE
[a idx item]
[a item idx]
and. > @
a
eq.
Expand All @@ -182,7 +191,7 @@
[wanted] > index-of
^.reducedi > @
-1
[acc i item]
[acc item i]
if. > @
and.
eq.
Expand All @@ -199,7 +208,7 @@
[wanted] > last-index-of
^.reducedi > @
-1
[acc i item]
[acc item i]
if. > @
eq.
item
Expand All @@ -220,7 +229,7 @@
reducedi. > res!
^
*
[a i x]
[a x i]
a.with (memory i) > @
memory 0 > i
memory 0 > j
Expand Down Expand Up @@ -275,26 +284,23 @@
list *

[index-carr func new-list] > rec-filtered
index-carr.at 0 > index
index-carr.at 1 > carr
carr.at index > item
seq > @
func > acc!
item
index
if. > filt-list
eq.
acc
TRUE
new-list.with item
new-list
if.
(index.plus 1).eq (carr.length)
filt-list
rec-filtered
* (index.plus 1) carr
if. > @
eq.
index-carr.at 0 > index
length.
index-carr.at 1 > carr
new-list
rec-filtered
*
index.plus 1
carr
func
if.
func
filt-list
carr.at index > item
index
new-list.with item
new-list

# Filter list without index with the function "f".
# Here "f" must be an abstract object
Expand Down Expand Up @@ -334,24 +340,32 @@
1
func

# Get the first i-th elements from
# the start of the list
# Get the first i-th elements from the start of the list
[i] > head
i > index!

if. > @
index.lte 0
list *
if.
index.gte (^.length)
0 > zero!
switch > @
*
index.eq zero
list *
*
index.lt zero
^.tail
index.neg
*
index.gte
^.length
^
^.reducedi
list *
[acc idx item]
if. > @
idx.gte index
acc
acc.with item
*
TRUE
list
^.reducedi
*
[acc item idx]
if. > @
idx.gte index
acc
acc.with item

# Get the last i-th elements from
# the end of the list
Expand All @@ -364,7 +378,7 @@
^
^.reducedi
list *
[acc idx item]
[acc item idx]
if. > @
gte.
idx
Expand Down
13 changes: 6 additions & 7 deletions objects/org/eolang/collections/map.eo
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

+alias org.eolang.collections.hash-code-of
+alias org.eolang.collections.list
+alias org.eolang.collections.multimap
+alias org.eolang.math.number
+home https://github.com/objectionary/eo-collections
+package org.eolang.collections
+rt jvm org.eolang:eo-collections:0.0.9
+version 0.0.9
+rt jvm org.eolang:eo-collections:0.10.0
+version 0.10.0

[m] > map
memory 0 > elements-amount
elements-amount > size

# Returns list of all keys in multimap
[] > keys
Expand All @@ -53,10 +55,6 @@
x
key

# Returns amount of elements in multimap
[] > size
elements-amount > @

# Returns the new map with added object
# Replaces if there was one before
[key value] > with
Expand All @@ -76,7 +74,8 @@
# If no element was found, it returns an empty array
[key] > found
multimap * > mmp!
number (key.as-hash) > num!
number > num!
hash-code-of key
if. > @
eq.
m.length
Expand Down
21 changes: 11 additions & 10 deletions objects/org/eolang/collections/multimap.eo
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

+alias org.eolang.collections.hash-code-of
+alias org.eolang.collections.list
+alias org.eolang.math.number
+home https://github.com/objectionary/eo-collections
+package org.eolang.collections
+rt jvm org.eolang:eo-collections:0.0.9
+version 0.0.9
+rt jvm org.eolang:eo-collections:0.10.0
+version 0.10.0

[m] > multimap
memory 0 > elements-amount
elements-amount > size

# Returns list of all keys in multimap
[] > keys
Expand All @@ -39,10 +41,6 @@
[curr]
curr.at 0 > @

# Returns amount of elements in multimap
[] > size
elements-amount > @

[arr] > concat-all-arrays
reduced. > @
list
Expand All @@ -59,7 +57,9 @@
arr
*
[a x]
a.with (x.at 0).as-hash > @
a.with > @
hash-code-of
x.at 0

# Returns the new map with added object
[key value] > with
Expand Down Expand Up @@ -89,7 +89,8 @@
# Returns an array with the found value
# If no element was found, it returns an empty array
[key] > found
number (key.as-hash) > num!
number > num!
hash-code-of key
if. > @
eq.
m.length
Expand Down Expand Up @@ -130,7 +131,7 @@
list
sorted-pairs
*
[a i x]
[a x i]
if. > @
gte.
x.at 0
Expand Down Expand Up @@ -168,7 +169,7 @@
list
arr
*
[a i x]
[a x i]
if. > @
and.
gte.
Expand Down
Loading

0 comments on commit ee6d14e

Please sign in to comment.