Packages

  • package root
    Definition Classes
    root
  • package o1

    O1Library is a toolkit designed for the course Programming 1 (a.k.a. O1) at Aalto University.

    O1Library is a toolkit designed for the course Programming 1 (a.k.a. O1) at Aalto University. It contains an assortment of tools; most prominently, it provides a framework for simple graphical programming and utilities for playing sound.

    This is the front page of O1Library’s documentation. However, this is probably not the best place to start learning about O1Library as a student. That’s because the relevant content of this library is introduced bit by bit in the chapters of O1’s custom ebook alongside the associated programming concepts and assignments.

    You may still find this documentation useful as a reference. You can also find some optional content here that you may wish to try.

    This front page lists the content available in the top-level package called simply o1. These tools are available with the simple command import o1._ in your Scala programs. Some of them you’ll use a lot; some of them you won’t necessarily need at all.

    The tools listed here are actually implemented in a number of subpackages (o1.gui, o1.sound, etc.); what you see here are just “shortcut aliases” to those actual implementations. The aliases are here to make that convenient import command work and to provide you with this list of links to some of the more commonly used tools in O1Library. The subpackages also contain additional content not listed here.

    O1Library has been developed by Aleksi Lukkarinen and Juha Sorva. Several of the key components in o1.gui and o1.world are built upon Aleksi’s Scala Media Computation Library. Some parts of O1Library draw inspiration from the “teachpacks” of the Racket programming language.

    We are grateful to Riku Autio, Joonatan Honkamaa, Juhani Numminen, Leo Varis, Veera Kahva, and anonymous students for bug reports and fixes. We thank Otto Seppälä for helpful discussions.

    Definition Classes
    root
  • package grid

    This package contains tools for working with grid-like two-dimensional structures.

    This package contains tools for working with grid-like two-dimensional structures.

    The contents of this package have aliases in the top-level package o1, so they are accessible to students simply via import o1._.

    Definition Classes
    o1
  • package gui

    This package contains tools for building simple GUIs.

    This package contains tools for building simple GUIs. The toolkit is particularly well suited to constructing GUIs that display information as 2D images and/or geometric shapes. It is not designed for demanding graphical needs that call for high efficiency. Some of the tools in this package are built on the Swing GUI library, and the two libraries can be used in combination.

    Some of the types in this package have aliases in the top-level package o1, so they are accessible to students simply via import o1._. Some of the package contents are not available in the top-level package or included in this documentation.

    Please note: One of this package’s key components (views) comes in multiple varieties, which which are defined in the subpackages o1.gui.mutable and o1.gui.immutable and not listed below. The View that is most commonly used in O1 (and aliased as o1.View in the top-level package) is o1.gui.mutable.ViewFrame.

    Definition Classes
    o1
  • package sound

    Please see one of the two subpackages:

    Please see one of the two subpackages:

    • o1.sound.midi for MIDI sound described in terms of notes, instruments, and other directives
    • o1.sound.sampled for working with recorded sound samples.
    Definition Classes
    o1
  • package util

    The package o1.util contains miscellaneous tools that are used internally by some of the given programs in O1 for added convenience.

    The package o1.util contains miscellaneous tools that are used internally by some of the given programs in O1 for added convenience.

    NOTE TO STUDENTS: In this course, you don't need to understand how this package works or can be used.

    This documentation lists only some of the tools in the package. The listed tools are largely a mix of:

    • functions for simple I/O from files and URLs;
    • aliases for easy access (via import o1.util._) to some of the tools from scala.util; and
    • implicit classes that add a few convenience methods to selected types from the Scala API.
    Definition Classes
    o1
  • ConvenientCollection
  • ConvenientDouble
  • ConvenientFloat
  • ConvenientInt
  • ConvenientLong
  • ConvenientMap
  • ConvenientOption
  • ConvenientPath
  • ConvenientSeq
  • package world

    This package contains tools for locations and movement in two-dimensional space.

    This package contains tools for locations and movement in two-dimensional space.

    The tools in this package have aliases in the top-level package o1, so they are accessible to students simply via import o1._.

    The subpackage o1.world.objects contains additional tools for representing entities that reside within two-dimensional spaces.

    Definition Classes
    o1
p

o1

util

package util

The package o1.util contains miscellaneous tools that are used internally by some of the given programs in O1 for added convenience.

NOTE TO STUDENTS: In this course, you don't need to understand how this package works or can be used.

This documentation lists only some of the tools in the package. The listed tools are largely a mix of:

  • functions for simple I/O from files and URLs;
  • aliases for easy access (via import o1.util._) to some of the tools from scala.util; and
  • implicit classes that add a few convenience methods to selected types from the Scala API.
Linear Supertypes
iofuncs, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. util
  2. iofuncs
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. type Closeable = AutoCloseable

    A structural supertype for everything that has a close method.

    A structural supertype for everything that has a close method. This is an alias for java.lang.AutoCloseable.

    Definition Classes
    iofuncs
    See also

    useAndClose

  2. implicit final class ConvenientCollection[Element, Collection[Element] <: Iterable[Element]] extends AnyVal

    This class extends the interface of scala.Iterable with convenience methods.

  3. implicit final class ConvenientDouble extends AnyVal

    This class extends the interface of Double with convenience methods.

  4. implicit final class ConvenientFloat extends AnyVal

    This class extends the interface of Float with convenience methods.

  5. implicit final class ConvenientInt extends AnyVal

    This class extends the interface of Int with convenience methods.

  6. implicit final class ConvenientLong extends AnyVal

    This class extends the interface of Long with convenience methods.

  7. implicit final class ConvenientMap[Key, Value] extends AnyVal

    This class extends the interface of scala.Map with convenience methods.

  8. implicit final class ConvenientOption[Content] extends AnyVal

    This class extends the interface of Option with convenience methods.

  9. implicit class ConvenientPath extends AnyRef

    This class extends the interface of Java’s Path with convenience methods.

    This class extends the interface of Java’s Path with convenience methods.

    Definition Classes
    iofuncs
  10. implicit final class ConvenientSeq[Element] extends AnyVal

    This class extends the interface of scala.Seq with convenience methods.

  11. type Failure[T] = scala.util.Failure[T]

    An alias for convenient use of scala.util.Try via import o1.util._.

  12. type Path = java.nio.file.Path

    An alias for convenient use of java.nio.file.Path via import o1.util._.

  13. type Random = scala.util.Random

    An alias for convenient use of scala.util.Random via import o1.util._.

  14. type Source = scala.io.Source

    An alias for convenient use of scala.io.Source via import o1.util._.

  15. type Success[T] = scala.util.Success[T]

    An alias for convenient use of scala.util.Try via import o1.util._.

  16. type Try[T] = scala.util.Try[T]

    An alias for convenient use of scala.util.Try via import o1.util._.

  17. type URL = java.net.URL

    An alias for convenient use of java.net.URL via import o1.util._.

Value Members

  1. val DoubleOrdering: TotalOrdering.type

    An alias for convenient use of scala.math.Ordering.Double.TotalOrdering via import o1.util._.

  2. val Failure: scala.util.Failure.type

    An alias for convenient use of scala.util.Try via import o1.util._.

  3. def Path(url: URL): Path

    Constructs a new Path object from a given string URL.

    Constructs a new Path object from a given string URL.

    Definition Classes
    iofuncs
  4. def Path(name: String): Path

    Constructs a new Path object from a given string.

    Constructs a new Path object from a given string.

    Definition Classes
    iofuncs
  5. val Random: scala.util.Random.type

    An alias for convenient use of scala.util.Random via import o1.util._.

  6. val Source: scala.io.Source.type

    An alias for convenient use of scala.io.Source via import o1.util._.

  7. val Success: scala.util.Success.type

    An alias for convenient use of scala.util.Try via import o1.util._.

  8. val Try: scala.util.Try.type

    An alias for convenient use of scala.util.Try via import o1.util._.

  9. def findReadable(name: String): Option[Path]

    Searches the working directory and, failing that, the classpath for a readable file or folder with the given relative path.

    Searches the working directory and, failing that, the classpath for a readable file or folder with the given relative path. Returns the Path in an Option wrapper.

    Definition Classes
    iofuncs
  10. def forEachLine(source: Source)(effect: (String) => Unit): Unit

    Calls getLines on the given Source and performs the specified effect on each of the lines.

    Calls getLines on the given Source and performs the specified effect on each of the lines. Calls close() on the source even if an exception occurs, but doesn’t catch any exceptions.

    Definition Classes
    iofuncs
  11. def ifImplemented[Result](computation: => Result): Option[Result]

    Performs a given computation and checks to see if it crashes with a NotImplementedError.

    Performs a given computation and checks to see if it crashes with a NotImplementedError. Returns the result of the computation in an Option; returns None only in the computation wasn’t implemented. Any other exception is thrown.

    Result

    the type of the given computation

    computation

    a computation that may or may not be implemented

  12. def isImplemented[Result](computation: => Result): Boolean

    Performs a given computation and determines whether it crashes with a NotImplementedError.

    Performs a given computation and determines whether it crashes with a NotImplementedError. Returns true if it did and false otherwise.

    Result

    the type of the given computation

    computation

    a computation that may or may not be implemented

  13. def localFile(resourcePath: String): Option[Path]

    Searches the classpath for a file with the given relative path and returns the corresponding Path.

    Searches the classpath for a file with the given relative path and returns the corresponding Path. The result comes in an Option wrapper in case no such file is accessible.

    Definition Classes
    iofuncs
  14. def localSource(resourcePath: String): Option[Source]

    Searches the classpath for a file with the given relative path and returns a corresponding Source.

    Searches the classpath for a file with the given relative path and returns a corresponding Source. The result comes in an Option wrapper in case no such file is accessible. Assumes UTF-8 encoding.

    Definition Classes
    iofuncs
  15. def localURL(resourcePath: String): Option[URL]

    Searches the classpath for a file with the given relative path.

    Searches the classpath for a file with the given relative path. Delegates the task to the class loader. Returns the URL of any found file in an Option wrapper.

    Definition Classes
    iofuncs
  16. def readFileLines(relativePath: String, trimEach: Boolean = true, excludeIfEmpty: Boolean = true): Option[Vector[String]]

    Reads and returns the lines from a classpath-relative text file.

    Reads and returns the lines from a classpath-relative text file. The result comes in an Option wrapper in case no such file is accessible. Calls close() on the file even if an exception occurs, but doesn’t catch any exceptions. Assumes UTF-8 encoding.

    relativePath

    the path to a resource; relative to a classpath entry

    trimEach

    whether to remove whitespace around each of the lines

    excludeIfEmpty

    whether to exclude (possibly trimmed) empty lines from the return value

    Definition Classes
    iofuncs
  17. def readLinesFromSource(source: Source, trimEach: Boolean = true, excludeIfEmpty: Boolean = true): Vector[String]

    Calls getLines on the given Source and returns the lines in a vector.

    Calls getLines on the given Source and returns the lines in a vector. Calls close() on the source even if an exception occurs, but doesn’t catch any exceptions.

    source

    the source to read the lines from

    trimEach

    whether to remove whitespace around each of the lines

    excludeIfEmpty

    whether to exclude (possibly trimmed) empty lines from the return value

    Definition Classes
    iofuncs
  18. def readTextFile(relativePath: String): Option[String]

    Returns, as a single String, the entire contents of a classpath-relative text file.

    Returns, as a single String, the entire contents of a classpath-relative text file. The result comes in an Option wrapper in case no such file is accessible. Calls close() on the file even if an exception occurs, but doesn’t catch any exceptions. Assumes UTF-8 encoding.

    relativePath

    the path to a resource; relative to a classpath entry

    Definition Classes
    iofuncs
  19. val reflect: JavaUniverse

    An alias for convenient access to the macros in scala.reflect.runtime.universe via import o1.util._.

  20. def tryForSource(pathOrURL: String): Try[Source]

    Takes in a path or a URL as a string and tries to construct a corresponding Source.

    Takes in a path or a URL as a string and tries to construct a corresponding Source. Tries to interpret the given string as one of the following, in order:

    1. A resource relative to the classpath (as per localURL).
    2. A complete URL string, with protocol and all (e.g., "http://example.com/").
    3. A URL string with "http://" missing (e.g., "example.com").
    4. A URL string with "https://" missing. Calls scala.io.Source.fromURL on each of those candidates until a source is successfully constructed or all attempts have failed. Assumes UTF-8 encoding.
    pathOrURL

    the possible path or URL to a resource

    returns

    the first Success, or a Failure if none of the candidates can be read as a Source

    Definition Classes
    iofuncs
  21. def tryForURL(pathOrURL: String): Try[URL]

    Takes in a path or a URL as a string and tries to locate the corresponding resource.

    Takes in a path or a URL as a string and tries to locate the corresponding resource. Tries to interpret the given string as one of the following (in order until a match is found):

    1. A resource relative to the classpath (as per localURL).
    2. A complete URL string, with protocol and all (e.g., "http://example.com/").
    3. A URL string with "http://" missing (e.g., "example.com").
    pathOrURL

    the possible path or URL to a resource

    returns

    the first Success, or a Failure if the string isn’t even valid for forming a URL

    Definition Classes
    iofuncs
  22. def useAndClose[Resource <: Closeable, Result](resource: Resource)(operation: (Resource) => Result): Result

    Attempts to apply the given operation to the given resource and returns the result, making sure to close the resource.

    Attempts to apply the given operation to the given resource and returns the result, making sure to close the resource. Calls close() on the resource even if the attempt fails with an exception. Doesn’t catch any exceptions. (This in an implementation of the so-called “loan pattern”.) Since Scala 2.13, the functionality is available in the standard API, and this is now just an alias for scala.util.Using.resource.)

    resource

    a resource, such as a file, that has a close() method

    operation

    an operation that can be applied to resource

    Definition Classes
    iofuncs
  23. def workingDir: String

    An alias for convenient access to java.lang.System.getProperty("user.dir") via import o1.util._.

  24. def writeTextFile(filePath: String, text: String): Unit

    Writes the given text in a new text file at the given filePath.

    Writes the given text in a new text file at the given filePath. Overwrites any existing file there. Encodes the output as UTF-8. Calls close() on the output stream even if an exception occurs, but doesn’t catch any exceptions.

    filePath

    an absolute path to a local file or a path relative to the working directory

    Definition Classes
    iofuncs

Inherited from iofuncs

Inherited from AnyRef

Inherited from Any

Ungrouped