#' Smart Sequence Generation
#'
#' @param from the starting value of the sequence
#' @param to the ending value of the sequence
#' @param decreasing = 1 to generate the decreasing sequence
#'
#' @details
#' This function is defined as
#' \preformatted{
#'   from-1 + seq_len(max(0,to-from+1))
#' }
#' so that
#' when \code{from > to} \code{Seq( from, to )} returns \code{numeric(0)}.
#'
#' Basically, same as
#' \preformatted{
#' Seq <- function(from, to) {
#'   if (from <= to) {
#'      return(from:to)
#'   } else {
#'      return(numeric(0))
#'   }
#' }
#' }
#'
#' @examples
#' cat("Seq(3,5)\n")
#' for( i in Seq(3,5) ) print(i)
#' cat("Seq(5,3)\n")
#' for( i in Seq(5,3) ) print(i)
#' cat("seq(5,3)\n")
#' for( i in seq(5,3) ) print(i)
#' cat("\nSeq(3,5, decreasing=1)\n")
#' for( i in Seq(3,5, decreasing=1) ) print(i)
#' cat("Seq(5,3, decreasing=1)\n")
#' for( i in Seq(5,3, decreasing=1) ) print(i)
#'
#' @export
#'

Seq <- function( from, to, decreasing=0 ){
 # smart sequence generation
 # Shin-ichi Mayekawa
 # consulted with chatGPT: 20240217
 # as a function: 20240311
 # decreasing: 20240626
 #

 if( decreasing )  rev( to-1 + seq_len(max(0,from-to+1)) )
 else from-1 + seq_len(max(0,to-from+1))

} # end of Seq



