Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EmptyLinkedList<T>

EmptyLinkedList is the empty linked list; every non-empty linked list also has a pointer to an empty linked list after its last element. "static methods" available through LinkedListStatic

Type parameters

  • T

    the item type

Hierarchy

  • EmptyLinkedList

Implements

  • any

Index

Methods

__@iterator

  • __@iterator(): Iterator<T>
  • Implementation of the Iterator interface.

    Returns Iterator<T>

__computed

  • __computed(): string

allMatch

  • allMatch(predicate: function): boolean
  • Returns true if the predicate returns true for all the elements in the collection.

    Parameters

    • predicate: function
        • (v: T): boolean
        • Parameters

          • v: T

          Returns boolean

    Returns boolean

anyMatch

  • anyMatch(predicate: function): boolean
  • Returns true if there the predicate returns true for any element in the collection.

    Parameters

    • predicate: function
        • (v: T): boolean
        • Parameters

          • v: T

          Returns boolean

    Returns boolean

append

  • Append an element at the end of this LinkedList. Warning: appending in a loop on a linked list is going to be very slow!

    Parameters

    • v: T

    Returns LinkedList<T>

appendAll

arrangeBy

asLinkedList

  • View this Some a as LinkedList. Useful to help typescript type inference sometimes.

    Returns LinkedList<T>

contains

distinctBy

  • distinctBy<U>(keyExtractor: function): LinkedList<T>
  • Remove duplicate items; elements are mapped to keys, those get compared.

    LinkedList.of(1,1,2,3,2,3,1).distinctBy(x => x)
    => LinkedList.of(1,2,3)
    

    Type parameters

    • U

    Parameters

    Returns LinkedList<T>

drop

  • Returns a new collection with the first n elements discarded. If the collection has less than n elements, returns the empty collection.

    Parameters

    • n: number

    Returns LinkedList<T>

dropRight

  • Returns a new collection with the last n elements discarded. If the collection has less than n elements, returns the empty collection.

    Parameters

    • n: number

    Returns LinkedList<T>

dropRightWhile

  • dropRightWhile(predicate: function): LinkedList<T>
  • Returns a new collection, discarding the last elements until one element fails the predicate. All elements before that point are retained.

    Parameters

    • predicate: function
        • (x: T): boolean
        • Parameters

          • x: T

          Returns boolean

    Returns LinkedList<T>

dropWhile

  • Returns a new collection, discarding the first elements until one element fails the predicate. All elements after that point are retained.

    Parameters

    • predicate: function
        • (x: T): boolean
        • Parameters

          • x: T

          Returns boolean

    Returns LinkedList<T>

equals

  • Two objects are equal if they represent the same value, regardless of whether they are the same object physically in memory.

    Parameters

    Returns boolean

filter

  • Call a predicate for each element in the collection, build a new collection holding only the elements for which the predicate returned true.

    Type parameters

    • U: T

    Parameters

    • predicate: function
        • (v: T): boolean
        • Parameters

          • v: T

          Returns boolean

    Returns LinkedList<U>

  • Parameters

    • predicate: function
        • (v: T): boolean
        • Parameters

          • v: T

          Returns boolean

    Returns LinkedList<T>

find

  • find(predicate: function): Option<T>
  • Search for an item matching the predicate you pass, return Option.Some of that element if found, Option.None otherwise.

    Parameters

    • predicate: function
        • (v: T): boolean
        • Parameters

          • v: T

          Returns boolean

    Returns Option<T>

flatMap

  • Calls the function you give for each item in the collection, your function returns a collection, all the collections are concatenated. This is the monadic bind.

    Type parameters

    • U

    Parameters

    Returns LinkedList<U>

fold

  • fold(zero: T, fn: function): T
  • Reduces the collection to a single value using the associative binary function you give. Since the function is associative, order of application doesn't matter.

    Example:

    LinkedList.of(1,2,3).fold(0, (a,b) => a + b);
    => 6
    

    Parameters

    • zero: T
    • fn: function
        • (v1: T, v2: T): T
        • Parameters

          • v1: T
          • v2: T

          Returns T

    Returns T

foldLeft

  • foldLeft<U>(zero: U, fn: function): U
  • Reduces the collection to a single value. Left-associative.

    Example:

    Vector.of("a", "b", "c").foldLeft("!", (xs,x) => x+xs);
    => "cba!"
    

    Type parameters

    • U

    Parameters

    • zero: U

      The initial value

    • fn: function

      A function taking the previous value and the current collection item, and returning an updated value.

        • (soFar: U, cur: T): U
        • Parameters

          • soFar: U
          • cur: T

          Returns U

    Returns U

foldRight

  • foldRight<U>(zero: U, fn: function): U
  • Reduces the collection to a single value. Right-associative.

    Example:

    Vector.of("a", "b", "c").foldRight("!", (x,xs) => xs+x);
    => "!cba"
    

    Type parameters

    • U

    Parameters

    • zero: U

      The initial value

    • fn: function

      A function taking the current collection item and the previous value , and returning an updated value.

        • (cur: T, soFar: U): U
        • Parameters

          • cur: T
          • soFar: U

          Returns U

    Returns U

forEach

  • Call a function for element in the collection.

    Parameters

    • fn: function
        • (v: T): void
        • Parameters

          • v: T

          Returns void

    Returns LinkedList<T>

get

  • Retrieve the element at index idx. Returns an option because the collection may contain less elements than the index.

    Careful this is going to have poor performance on LinkedList, which is not a good data structure for random access!

    Parameters

    • idx: number

    Returns Option<T>

groupBy

  • Group elements in the collection using a classifier function. Elements are then organized in a map. The key is the value of the classifier, and in value we get the list of elements matching that value.

    also see ConsLinkedList.arrangeBy

    Type parameters

    • C

    Parameters

    Returns HashMap<C, LinkedList<T>>

hashCode

  • hashCode(): number
  • Get a number for that object. Two different values may get the same number, but one value must always get the same number. The formula can impact performance.

    Returns number

head

  • Get the first value of the collection, if any. In this case the list is empty, so returns Option.none

    Returns None<T>

isEmpty

  • isEmpty(): boolean
  • true if the collection is empty, false otherwise.

    Returns boolean

last

  • Get the last value of the collection, if any. returns Option.Some if the collection is not empty, Option.None if it's empty.

    Returns Option<T>

length

  • length(): number

map

  • Return a new collection where each element was transformed by the mapper function you give.

    Type parameters

    • U

    Parameters

    • mapper: function
        • (v: T): U
        • Parameters

          • v: T

          Returns U

    Returns LinkedList<U>

mapOption

  • Apply the mapper function on every element of this collection. The mapper function returns an Option; if the Option is a Some, the value it contains is added to the result Collection, if it's a None, the value is discarded.

    LinkedList.of(1,2,6).mapOption(x => x%2===0 ?
        Option.of(x+1) : Option.none<number>())
    => LinkedList.of(3, 7)
    

    Type parameters

    • U

    Parameters

    • mapper: function

    Returns LinkedList<U>

maxBy

  • maxBy(compare: function): Option<T>

maxOn

  • Call the function you give for each value in the collection and return the element for which the result was the largest. Returns Option.none if the collection is empty.

    LinkedList.of({name:"Joe", age:12}, {name:"Paula", age:6}).maxOn(x=>x.age)
    => Option.of({name:"Joe", age:12})
    

    also see ConsLinkedList.maxBy

    Parameters

    Returns Option<T>

minBy

  • minBy(compare: function): Option<T>

minOn

  • Call the function you give for each value in the collection and return the element for which the result was the smallest. Returns Option.none if the collection is empty.

    LinkedList.of({name:"Joe", age:12}, {name:"Paula", age:6}).minOn(x=>x.age)
    => Option.of({name:"Paula", age:6})
    

    also see ConsLinkedList.minBy

    Parameters

    Returns Option<T>

mkString

  • mkString(separator: string): string
  • Joins elements of the collection by a separator. Example:

    LinkedList.of(1,2,3).mkString(", ")
    => "1, 2, 3"
    

    Parameters

    • separator: string

    Returns string

partition

  • Returns a pair of two collections; the first one will only contain the items from this collection for which the predicate you give returns true, the second will only contain the items from this collection where the predicate returns false.

    LinkedList.of(1,2,3,4).partition(x => x%2===0)
    => [LinkedList.of(2,4),LinkedList.of(1,3)]
    

    Type parameters

    • U: T

    Parameters

    • predicate: function
        • (v: T): boolean
        • Parameters

          • v: T

          Returns boolean

    Returns [LinkedList<U>, LinkedList<Exclude<T, U>>]

  • Parameters

    • predicate: function
        • (x: T): boolean
        • Parameters

          • x: T

          Returns boolean

    Returns [LinkedList<T>, LinkedList<T>]

prepend

prependAll

  • Prepend multiple elements at the beginning of the collection.

    Parameters

    • elt: Iterable<T>

    Returns LinkedList<T>

reduce

  • reduce(combine: function): Option<T>
  • Reduces the collection to a single value by repeatedly calling the combine function. No starting value. The order in which the elements are passed to the combining function is undetermined.

    Parameters

    • combine: function
        • (v1: T, v2: T): T
        • Parameters

          • v1: T
          • v2: T

          Returns T

    Returns Option<T>

removeAll

  • Remove multiple elements from a LinkedList

    LinkedList.of(1,2,3,4,3,2,1).removeAll([2,4])
    => LinkedList.of(1,3,3,1)
    

    Parameters

    Returns LinkedList<T>

removeFirst

  • Removes the first element matching the predicate (use Seq.filter to remove all elements matching a predicate)

    Parameters

    • predicate: function
        • (x: T): boolean
        • Parameters

          • x: T

          Returns boolean

    Returns LinkedList<T>

reverse

  • Reverse the collection. For instance:

    LinkedList.of(1,2,3).reverse();
    => LinkedList.of(3,2,1)
    

    Returns LinkedList<T>

scanLeft

  • scanLeft<U>(init: U, fn: function): LinkedList<U>
  • Apply the function you give to all elements of the sequence in turn, keeping the intermediate results and returning them along with the final result in a list. The last element of the result is the final cumulative result.

    LinkedList.of(1,2,3).scanLeft(0, (soFar,cur)=>soFar+cur)
    => LinkedList.of(0,1,3,6)
    

    Type parameters

    • U

    Parameters

    • init: U
    • fn: function
        • (soFar: U, cur: T): U
        • Parameters

          • soFar: U
          • cur: T

          Returns U

    Returns LinkedList<U>

scanRight

  • scanRight<U>(init: U, fn: function): LinkedList<U>
  • Apply the function you give to all elements of the sequence in turn, keeping the intermediate results and returning them along with the final result in a list. The first element of the result is the final cumulative result.

    LinkedList.of(1,2,3).scanRight(0, (cur,soFar)=>soFar+cur)
    => LinkedList.of(6,5,3,0)
    

    Type parameters

    • U

    Parameters

    • init: U
    • fn: function
        • (cur: T, soFar: U): U
        • Parameters

          • cur: T
          • soFar: U

          Returns U

    Returns LinkedList<U>

shuffle

single

  • If the collection contains a single element, return Some of its value, otherwise return None.

    Returns Option<T>

sliding

  • Slides a window of a specific size over the sequence. Returns a lazy stream so memory use is not prohibitive.

    LinkedList.of(1,2,3,4,5,6,7,8).sliding(3)
    => Stream.of(LinkedList.of(1,2,3), LinkedList.of(4,5,6), LinkedList.of(7,8))
    

    Parameters

    • count: number

    Returns Stream<ConsLinkedList<T>>

sortBy

  • Returns a new collection with elements sorted according to the comparator you give.

    const activityOrder = ["Writer", "Actor", "Director"];
    LinkedList.of({name:"George", activity: "Director"}, {name:"Robert", activity: "Actor"})
        .sortBy((p1,p2) => activityOrder.indexOf(p1.activity) - activityOrder.indexOf(p2.activity));
    => LinkedList.of({"name":"Robert","activity":"Actor"}, {"name":"George","activity":"Director"})
    

    also see ConsLinkedList.sortOn

    Parameters

    • compare: function

    Returns LinkedList<T>

sortOn

  • Give a function associating a number or a string with elements from the collection, and the elements are sorted according to that value.

    LinkedList.of({a:3,b:"b"},{a:1,b:"test"},{a:2,b:"a"}).sortOn(elt=>elt.a)
    => LinkedList.of({a:1,b:"test"},{a:2,b:"a"},{a:3,b:"b"})
    

    You can also sort by multiple criteria, and request 'descending' sorting:

    LinkedList.of({a:1,b:"b"},{a:1,b:"test"},{a:2,b:"a"}).sortOn(elt=>elt.a,{desc:elt=>elt.b})
    => LinkedList.of({a:1,b:"test"},{a:1,b:"b"},{a:2,b:"a"})
    

    also see ConsLinkedList.sortBy

    Parameters

    Returns LinkedList<T>

span

  • Takes a predicate; returns a pair of collections. The first one is the longest prefix of this collection which satisfies the predicate, and the second collection is the remainder of the collection.

    LinkedList.of(1,2,3,4,5,6).span(x => x <3) => [LinkedList.of(1,2), LinkedList.of(3,4,5,6)]

    Parameters

    • predicate: function
        • (x: T): boolean
        • Parameters

          • x: T

          Returns boolean

    Returns [LinkedList<T>, LinkedList<T>]

splitAt

  • Split the collection at a specific index.

    LinkedList.of(1,2,3,4,5).splitAt(3)
    => [LinkedList.of(1,2,3), LinkedList.of(4,5)]
    

    Parameters

    • index: number

    Returns [LinkedList<T>, LinkedList<T>]

sumOn

  • sumOn(getNumber: function): number
  • Call the function you give for each element in the collection and sum all the numbers, return that sum. Will return 0 if the collection is empty.

    LinkedList.of(1,2,3).sumOn(x=>x)
    => 6
    

    Parameters

    • getNumber: function
        • (v: T): number
        • Parameters

          • v: T

          Returns number

    Returns number

tail

take

  • Return a new stream keeping only the first n elements from this stream.

    Parameters

    • n: number

    Returns LinkedList<T>

takeRightWhile

  • takeRightWhile(predicate: function): LinkedList<T>
  • Returns a new collection, discarding the elements after the first element which fails the predicate, but starting from the end of the collection.

    LinkedList.of(1,2,3,4).takeRightWhile(x => x > 2)
    => LinkedList.of(3,4)
    

    Parameters

    • predicate: function
        • (x: T): boolean
        • Parameters

          • x: T

          Returns boolean

    Returns LinkedList<T>

takeWhile

  • Returns a new collection, discarding the elements after the first element which fails the predicate.

    Parameters

    • predicate: function
        • (x: T): boolean
        • Parameters

          • x: T

          Returns boolean

    Returns LinkedList<T>

toArray

  • toArray(): T[]
  • Convert to array. Don't do it on an infinite stream!

    Returns T[]

toMap

  • toMap<K, V>(converter: function): HashMap<K, V>
  • Convert this collection to a map. You give a function which for each element in the collection returns a pair. The key of the pair will be used as a key in the map, the value, as a value in the map. If several values get the same key, entries will be lost.

    LinkedList.of(1,2,3).toMap(x=>[x.toString(), x])
    => HashMap.of(["1",1], ["2",2], ["3",3])
    

    Type parameters

    • K

    • V

    Parameters

    Returns HashMap<K, V>

toSet

  • toSet<K>(converter: function): HashSet<K>
  • Convert this collection to a set. Since the elements of the Seq may not support equality, you must pass a function returning a value supporting equality.

    LinkedList.of(1,2,3,3,4).toSet(x=>x)
    => HashSet.of(1,2,3,4)
    

    Type parameters

    • K

    Parameters

    Returns HashSet<K>

toString

  • toString(): string

toVector

transform

  • transform<U>(converter: function): U
  • Transform this value to another value type. Enables fluent-style programming by chaining calls.

    Type parameters

    • U

    Parameters

    Returns U

zip

  • Combine this collection with the collection you give in parameter to produce a new collection which combines both, in pairs. For instance:

    Vector.of(1,2,3).zip(["a","b","c"])
    => Vector.of([1,"a"], [2,"b"], [3,"c"])
    

    The result collection will have the length of the shorter of both collections. Extra elements will be discarded.

    Also see LinkedListStatic.zip (static version which can more than two iterables)

    Type parameters

    • U

    Parameters

    • other: Iterable<U>

    Returns LinkedList<[T, U]>

zipWithIndex

  • Combine this collection with the index of the elements in it. Handy if you need the index when you map on the collection for instance:

    LinkedList.of("a","b").zipWithIndex().map(([v,idx]) => v+idx);
    => LinkedList.of("a0", "b1")
    

    Returns LinkedList<[T, number]>

Generated using TypeDoc