What is the minsize() method in Euphoria?

Overview

In Euphoria, we use the length() method to get the size of a sequence value, which is as follows:

length(sequence_value)

This method is significant because its output can serve as a part of a condition in a conditional statement. One of these conditions is mainly because a sequence may not have a predetermined size. Hence, we can confirm the size by using an if statement. We can use the minsize() method to ensure that the sequence has a minimum required size by padding it up if less.

The minsize() method ensures that a sequence has the minimum size indicated by padding it to the right with a value as provided.

Syntax

minsize(source_data, min_size, pad_data)

Parameter

  • source_data: This is the value to be maintained at a specified minimum length. It is an object data type. It may need an extension to meet the minimum size if less.
  • min_size: This is an integer value. It represents the least size the sequence should be.
  • pad_data: This is the data added to the right side of the source_data to make its length up to the min_size if it was initially less.

Return value

It returns a sequence. If the initial size is less than the min_size, this must have been padded. It will return the initial sequence unchanged if its size is greater than the min_size.

Code

Below is a sample code to use the minsize() method:

include std/sequence.e
object source_data1, source_data2
sequence output1, output2
source_data1 = {7,8,5,1,3,9,10}
source_data2 = {2,4,8,4,5,3,4}
output1 = minsize({4,3,6,2,7,1,2}, 10, -5)
output2 = minsize({4,3,6,2,7,1,2}, 5, -1)
print(1,output1)
puts(1,"\n")
print(1,output2)

Explanation

  • Line 1: We will include an inbuilt module.
  • Line 3–4: We declare variables that we will use later.
  • Line 6–7: We will save the output from the operation of minsize().
  • Line 12-14: We print the output to the screen.

Free Resources