Linear Search in Scala

Published on 31 October 2025 (Updated: 11 April 2026)

Welcome to the Linear Search in Scala page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

import scala.util.Try

object LinearSearch:

  private val usage =
    """Usage: please provide a list of integers ("1, 4, 5, 11, 12") and the integer to find ("11")"""

  def main(args: Array[String]): Unit =
    if args.length < 2 then
      println(usage)
    else
      val listStr = args(0)
      val targetStr = args(1)

      val output =
        for
          numbers <- parseNumbers(listStr)
          target   <- targetStr.toIntOption
        yield numbers.contains(target)

      println(output.map(_.toString).getOrElse(usage))

  private def parseNumbers(input: String): Option[List[Int]] =
    Try(input.split(',').map(_.trim.toInt).toList).toOption

Linear Search in Scala was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.