Packages

p

linkedlist

typedlist

package typedlist

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. All

Type Members

  1. case class TypedCons[Element, Size <: Natural](_head: Element, _tail: TypedList[Element, Size]) extends TypedList[Element, Suc[Size]] with Product with Serializable
  2. sealed trait TypedList[+Element, Size <: Natural] extends AnyRef

    A linked list with compile time size.

    A linked list with compile time size.

    Element

    Refers to the contents of the list, the same away as the A on the standard library's List[A]. It is covariant for the same reason as the List is.

    Size

    Natural number describing the size of the list.

    Example:
    1. import linkedlist.naturalnumbers.Natural._
      
      val aListOfSizeEight = 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: TypedNil
      
      // Compile error when accessing element outside bounds (as the bounds are known at compile time)
      aListOfSizeEight.get[Nat10]
      
      // Compile error when accessing head/tail of empty list
      val aListOfSizeOne = "Foo" :: TypedNil
      val anEmptyList = aListOfSizeOne.tail
      
      // You can get an element at a specific index
      val elemAtIndex = aListOfSizeEight.get[Nat3]
      
      // You can split into two lists maintaining typed size on both.
      val (ofSize2, ofSize6) = aListOfSizeEight.split[Nat2]
      
      // You can map over the list
      val stringList = aListOfSizeEight.map(i => s"cmhteixeira-$i")
      
      // You can concatenate two lists and the resulting list has correct typed size
      val firstList = "Foo" :: "Bar" :: "Baz" :: TypedNil
      val secondList = "Qux" :: "Quux" :: TypedNil
      val concatenatedList = firstList concat secondList
      
      // You can flatmap the list, and the resulting list will have the correct size !! -> natural multiplication
      val someList = "Foo" :: "Bar" :: "Baz" :: TypedNil
      val result = someList.flatMap(i => s"$i-1" :: s"$i-2" :: TypedNil)
    See also

    package linkedlist.naturalnumbers

Value Members

  1. object TypedList

    The TypedList.typedListOfNats TypedList.emptyList implicit functions, leverage iterative implicit resolution to automatically construct a typed list of naturals of the specified size.

    The TypedList.typedListOfNats TypedList.emptyList implicit functions, leverage iterative implicit resolution to automatically construct a typed list of naturals of the specified size.

    Example:
    1. val oneToEleven = implicitly[[TypedList[Natural, Nat10]]]
      //res = TypedList(1, 2, 3, 4, 5, 6, 7, 8, 9, 11)
    Note

    The typed list will have a size one greater than the value specified in the type parameter.

  2. object TypedNil extends TypedList[Nothing, Zero.type] with Product with Serializable

Ungrouped