Getting first and last set of elements in Julia – front() and tail() Methods
The front() is an inbuilt function in julia which is used to return a tuple consisting of all but the last component of x, where x is the specified tuple.
Syntax: front(x::Tuple)::Tuple
Parameters:
- x::Tuple: Specified tuple.
Returns: It returns a tuple consisting of all but the last component of x, where x is the specified tuple.
Example:
# Julia program to illustrate # the use of front() method # Getting a tuple consisting of# all but the last component of x, # where x is the specified tuple.println(Base.front((1, 2, 3)))println(Base.front((2, 4, 6, 8)))println(Base.front((3, 5))) |
Output:
(1, 2) (2, 4, 6) (3, )
The tail() is an inbuilt function in julia which is used to return a tuple consisting of all but the first component of x, where x is the specified tuple.
Syntax: tail(x::Tuple)::Tuple
Parameters:
- x::Tuple: Specified tuple.
Returns: It returns a tuple consisting of all but the first component of x, where x is the specified tuple.
Example:
# Julia program to illustrate # the use of tail() method # Getting a tuple consisting of# all but the first component of x, # where x is the specified tuple.println(Base.tail((1, 2, 3)))println(Base.tail((2, 4, 6, 8)))println(Base.tail((3, 5))) |
Output:
(2, 3) (4, 6, 8) (5, )


Please Login to comment...