Created
August 8, 2018 20:57
-
-
Save greggirwin/24c022cb5dde5771531a8939309ccb43 to your computer and use it in GitHub Desktop.
Red JOIN/COMBINE mezzanine ideas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [] | |
; TBD: pair tuple | |
combine: func [ | |
"Merge values, modifying a if possible" | |
a "Modified if series or map" | |
b "Single value or block of values; reduced if `a` is not an object or map" | |
][ | |
if all [block? :b not object? :a not map? :a] [b: reduce b] | |
case [ | |
series? :a [append a :b] | |
map? :a [extend a :b] | |
object? :a [make a :b] ; extend doesn't work on objects yet | |
'else [append form :a :b] | |
] | |
] | |
join: func [ | |
"Concatenate/merge values; a is not modified" | |
a "Coerced to string if not a series, map, or object" | |
b "Single value or block of values; reduced if `a` is not an object or map" | |
][ | |
if all [block? :b not object? :a not map? :a] [b: reduce b] | |
case [ | |
series? :a [a: copy a] | |
map? :a [a: copy a] | |
object? :a [] ; form or mold? | |
'else [a: form :a] | |
] | |
combine a b | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment