What is the combine() method in Euphoria?

Overview

The combine() method combines the sub-sequences provided to it into one sorted or unsorted sequence. It is an inbuilt method in the sequence.e module of the standard Euphoria library.

Syntax

combine(source_data, proc_option)

Parameters:

  • source_data: This is a sequence. It is a required parameter and contains all the sub-sequences that we want to join as a single sequence.

  • proc_option: This is an optional parameter. Its default value is COMBINE_SORTED. This parameter determines whether the returned sequence is sorted or unsorted. This parameter can have either of the following values:

    • COMBINE_SORTED: This is the default proc_option parameter value. With this value supplied, the sequence returned will be sorted.

    • COMBINE_UNSORTED: If this option is used, the sequence returned will not be sorted.

Return value

The combine() method will return a sequence that has all the elements from all the sub-sequences from source_data.

We don’t have to sort the elements of the sub-sequences in source_data beforehand.

Code

Let’s take a look at the combine() method using both string and integer sequences, while also trying the two possible proc_option values, in the code snippet below.

include std/sequence.e
sequence source1 = { {3,5,8}, {8,3,6,10}, {1,5}, {6}, {7,8} }
print(1 , combine(source1, COMBINE_SORTED))
puts(1,"\n")
print(1, combine(source1, COMBINE_UNSORTED))
sequence source2 = { "mat", "cart","kiss", "meal", "wish", "small", "sworn" }
printf(1,"\n%s",{ combine(source2, COMBINE_SORTED) })
printf(1,"\n%s",{ combine(source2, COMBINE_UNSORTED) })

Explanation

  • Line 1: We include the sequence.e module.
  • Lines 3 and 9 : We declare our source variables.
  • Lines 5, 7, 11, and 12: We use the combine() method to combine the sub-sequences in source. Then, using the print function, we display the output.

Free Resources