Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions spec/Map.Ordered.Spec.savi
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,3 @@

assert: keys == ["bar", "baz", "foo"]
assert: values == [22, 55, 66]

:it "yields each key and value until the criteria is met"
map = @new_map
map["foo"] = 11
map["bar"] = 22
map["baz"] = 33

count = USize[0]
key = ""
found_it = map.each_until -> (k, v | count += 1, key = k, v == 22)
assert: found_it
assert: count == 2
assert: key == "bar"

count = USize[0]
key = ""
found_it = map.each_until -> (k, v | count += 1, key = k, v == 33)
assert: found_it
assert: count == 3
assert: key == "baz"

count = USize[0]
key = ""
found_it = map.each_until -> (k, v | count += 1, key = k, v == 99)
assert: count == 3
assert: key == "baz"
assert: found_it.is_false
21 changes: 0 additions & 21 deletions spec/Map.Readable.Spec.savi
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,6 @@
map.each_value -> (value | total_value += value)
assert: total_value == 66

:it "yields each key and each value (separately) until the criteria is met"
map = @build_map -> (map |
map["foo"] = 11
map["bar"] = 22
map["baz"] = 33
)

this_key = ""
found_it = map.each_key_until -> (key | this_key = key, key.ends_with("o"))
assert: found_it
assert: this_key == "foo"

this_key = ""
found_it = map.each_key_until -> (key | this_key = key, key.ends_with("z"))
assert: found_it
assert: this_key == "baz"

this_key = ""
found_it = map.each_key_until -> (key | this_key = key, key.ends_with("x"))
assert: found_it.is_false

:it "checks if any pair in the map meets the given condition"
map = @build_map -> (map |
map["foo"] = 11
Expand Down
20 changes: 0 additions & 20 deletions spec/Map.Spec.savi
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,3 @@
assert: copy["foo"]! == 11
assert: copy["bar"]! == 22
assert: copy["baz"]! == 33

:it "yields each key and value until the criteria is met"
map = @new_map
map["foo"] = 11
map["bar"] = 22
map["baz"] = 33

this_key = ""
found_it = map.each_until -> (key, value | this_key = key, value == 22)
assert: found_it
assert: this_key == "bar"

this_key = ""
found_it = map.each_until -> (key, value | this_key = key, value == 33)
assert: found_it
assert: this_key == "baz"

this_key = ""
found_it = map.each_until -> (key, value | this_key = key, value == 99)
assert: found_it.is_false
18 changes: 0 additions & 18 deletions src/Map.Ordered.savi
Original file line number Diff line number Diff line change
Expand Up @@ -260,21 +260,3 @@
yield (entry.key, entry.value) // yield once more for the head
)
None

:: Yield each key and value in the map, in the order in they were inserted,
:: with the oldest key/value pairs appearing first, ending with the newest.
:fun each_until
:yields for Bool
early_stop = False
try ( // this should only fail when the map is empty, thus yielding nothing
head = @_head.not!(None)
entry = head.after!
while entry !== head && !early_stop (
early_stop = yield (entry.key, entry.value)
entry = entry.after!
)
if !early_stop (
early_stop = yield (entry.key, entry.value) // yield once more for the head
)
)
early_stop
23 changes: 3 additions & 20 deletions src/Map.Readable.savi
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
:fun each None
:yields (@->(K'aliased), @->(V'aliased)) for None

:: Yield each key and value in the map, stopping iteration if the yield block
:: returns True. Returns True if iteration was stopped early; else, False.
:fun each_until Bool
:yields (@->(K'aliased), @->(V'aliased)) for Bool

:: Yield each key in the map.
:fun each_key
@each -> (k, v | yield k)
Expand All @@ -33,26 +28,14 @@
:fun each_value
@each -> (k, v | yield v)

:: Yield each key in the map, stopping iteration if the yield block
:: returns True. Returns True if iteration was stopped early; else, False.
:fun each_key_until
:yields for Bool
@each_until -> (k, v | yield k)

:: Yield each value in the map, stopping iteration if the yield block
:: returns True. Returns True if iteration was stopped early; else, False.
:fun each_value_until
:yields for Bool
@each_until -> (k, v | yield v)

:: Return True after finding a key/value pair for which the yield block
:: returns True, defaulting to False if no such key/value pair is found.
:fun has_any // TODO: define as simple alias of each_until?
:fun has_any
:yields for Bool
@each_until -> (k, v | yield (k, v))
@each -> (k, v | has = yield (k, v), return True if has), False

:: Return False after finding a key/value pair for which the yield block
:: returns False, defaulting to True if no such key/value pair is found.
:fun has_all
:yields for Bool
@each_until -> (k, v | (yield (k, v)).not).not
@each -> (k, v | has = yield (k, v), return False unless has), True
12 changes: 0 additions & 12 deletions src/Map.savi
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,3 @@
)
)
None

:: Yield each key and value in the map, stopping iteration if the yield block
:: returns True. Returns True if iteration was stopped early; else, False.
:fun each_until
:yields for Bool
@_array.each_until -> (entry |
if entry <: @->(Pair(K, V)) (
yield (entry.key, entry.value)
|
False
)
)