Navigation
Synopsis Merge the elements of two sorted lists into one list.
Function
  1. list[&T] merge(list[&T] left, list[&T] right)
  2. list[&T] merge(list[&T] left, list[&T] right, bool (&T a, &T b) lessOrEqual)
Usage import List;
Description Merge the elements of two sorted lists into one list using the built-in ordering between values. Optional, a comparison function lessOrEqual may be given for a user-defined ordering between values.
Examples
rascal>import List;
ok
rascal>merge([1, 3, 5], [2, 7, 9, 15]);
list[int]: [1,2,3,5,7,9,15]
rascal>merge(["ape", "elephant", "owl", "snale", "zebra"], ["apple", "berry", "orange", "pineapple"]);
list[str]: ["ape","apple","berry","elephant","orange","owl","pineapple","snale","zebra"]
Merge two lists of strings and use their length as ordering:
rascal>import String;
ok
rascal>merge(["ape", "owl", "snale", "zebra", "elephant"], ["apple", "berry", "orange", "pineapple"], bool(str x, str y){ return size(x) <= size(y); });
list[str]: ["ape","owl","snale","zebra","apple","berry","orange","elephant","pineapple"]

Questions
Question [1].
The type of merge([-14,-10,4], [-16,6,8,12,16]) is

Question [2].
merge(["Bruno","Raspberry"], ["Count Von Count","H","Pepper","T","Thyme"]) == 

Question [3].
merge(["Gooseberry","Eggplant","Guava","V"], ["Count Von Count","Darth Sidious"], ) == ["Count Von Count","Darth Sidious","Gooseberry","Eggplant","Guava","V"]



Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.