Skip to content

Commit

Permalink
FEAT: added supplement mezzanine function which appends a value int…
Browse files Browse the repository at this point in the history
…o a block if not yet present

resolves: Oldes/Rebol-wishes#11
  • Loading branch information
Oldes committed Nov 26, 2020
1 parent 285ae9b commit 52ee407
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/mezz/mezz-series.reb
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,23 @@ alter: func [
) [append series :value]
]

supplement: func [
"Append value if not found; returns series at same position."
series [block!] {(modified)}
value
/case "Case-sensitive comparison"
/local result
][
result: series ; to return series at same position if value is found
any[
either case [
find/case series :value
][ find series :value ]
append series :value
]
result
]

collect: func [
"Evaluates a block, storing values via KEEP function, and returns block of collected values."
body [block!] "Block to evaluate"
Expand Down
10 changes: 5 additions & 5 deletions src/tests/units/module-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ Rebol [
Author: "Peter W A Wood, Oldes"
File: %module-test.r3
Tabs: 4
Needs: [%../quick-test-module.r3]
Needs: %../quick-test-module.r3
]

~~~start-file~~~ "module!"

modules-test-dir: join what-dir %units/files/
unless find system/options/module-paths modules-test-dir [
append system/options/module-paths modules-test-dir
]
; extend module-paths with units/files/ directory
; so modules there can be located
supplement system/options/module-paths join what-dir %units/files/


===start-group=== "module keywords"
--test-- "hidden"
Expand Down
10 changes: 10 additions & 0 deletions src/tests/units/series-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ Rebol [
--assert #"b" = select/same "aAbcdAe" "A"
--assert #"e" = select/same/last "aAbcdAe" "A"

--test- "SUPPLEMENT"
;@@ https://github.com/Oldes/Rebol-wishes/issues/11
b: []
--assert [%a] = supplement b %a
--assert [%a %b] = supplement b %b
--assert [%a %b] = supplement b %a
--assert [%a %b #"a"] = supplement b #"a"
--assert [%a %b #"a"] = supplement b #"A" ; case-insensitive
--assert [%a %b #"a" #"A"] = supplement/case b #"A"

===end-group===

===start-group=== "PATH notation"
Expand Down

0 comments on commit 52ee407

Please sign in to comment.