Skip to content
Related Articles

Related Articles

Getting first and last set of elements in Julia – front() and tail() Methods
  • Last Updated : 26 Mar, 2020

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, )

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :