Skip to content

Instantly share code, notes, and snippets.

@greggirwin
Created August 8, 2018 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greggirwin/24c022cb5dde5771531a8939309ccb43 to your computer and use it in GitHub Desktop.
Save greggirwin/24c022cb5dde5771531a8939309ccb43 to your computer and use it in GitHub Desktop.
Red JOIN/COMBINE mezzanine ideas
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