[ library(lists) | Reference Manual | Alphabetic Index ]
collection_to_list(+Collection, ?List)
Convert a "collection" into a list
Description
Converts various "collection" data structures into a list. Fails if it
does not know how to do this. The supported collection types are:
- List
-
The list is returned unchanged.
- Array
-
The array is flattened into a list using flatten_array/2.
- Subscript reference (Array[...])
-
subscript/3 is called to evaluate the subscript reference. Note
that the result is not flattened, so if subscript/3 results in a
nested list, the result is a nested list. However if the result is
a single element of the array that is not a list, this is converted
into a list containing that element.
- flatten(Collection)
-
Calls collection_to_list/2 on Collection and then flattens the
result using flatten/2.
- flatten(MaxDepth, Collection)
-
Calls collection_to_list/2 on Collection and then flattens the
result up to MaxDepth levels of nesting using flatten/3.
Modes and Determinism
- collection_to_list(+, -) is det
Examples
?- collection_to_list([a,b,[c,d]], List).
List = [a, b, [c, d]]
Yes
?- collection_to_list([](a,b,[c,d]), List).
List = [a, b, [c, d]]
Yes
?- collection_to_list([]([](a,b),[](c,d)), List).
List = [a, b, c, d]
Yes
?- A = []([](a,b),[](c,d)),
collection_to_list(A[1..2,1], List).
List = [a, c]
Yes
?- A = []([](a,b,c),[](d,e,f)),
collection_to_list(A[1..2,2..3], List).
List = [[b, c], [e, f]]
Yes
?- collection_to_list(flatten([a,b,[c,d]]), List).
List = [a, b, c, d]
Yes
?- collection_to_list(flatten([](a,b,[c,d])), List).
List = [a, b, c, d]
Yes
?- A = []([](a,b,c),[](d,e,f)),
collection_to_list(flatten(A[1..2,2..3]), List).
List = [b, c, e, f]
Yes
?- L = [[a,b],[[c,d],[e,f]],g],
collection_to_list(flatten(1, L), List).
List = [a, b, [c, d], [e, f], g]
Yes
See Also
subscript / 3, flatten / 2, flatten / 3, flatten_array / 2