Skip to content

Commit 046f97d

Browse files
committed
replace map..flatten.compact instance with .each_with_object
1 parent e36aa4c commit 046f97d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/json/ld/expand.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ def expand(input, active_property, context, ordered: true)
2424
when Array
2525
# If element is an array,
2626
is_list = context.container(active_property) == '@list'
27-
value = input.map do |v|
27+
value = input.each_with_object([]) do |v, memo|
2828
# Initialize expanded item to the result of using this algorithm recursively, passing active context, active property, and item as element.
2929
v = expand(v, active_property, context, ordered: ordered)
3030

3131
# If the active property is @list or its container mapping is set to @list, the expanded item must not be an array or a list object, otherwise a list of lists error has been detected and processing is aborted.
3232
raise JsonLdError::ListOfLists,
3333
"A list may not contain another list" if
3434
is_list && (v.is_a?(Array) || list?(v))
35-
v
36-
end.flatten.compact
35+
memo << v unless v.nil?
36+
end
3737

3838
value
3939
when Hash

0 commit comments

Comments
 (0)