Options
All
  • Public
  • Public/Protected
  • All
Menu

File Comparison

Index

Type aliases

HasEquals

HasEquals: object

A type with semantic equality relationships

Type declaration

ToOrderable

ToOrderable: function | function | function

Sorting function for type T: function to convert this type to a type which is natively sortable in javascript, that is string, number or boolean. ((v:T)=>number) | ((v:T)=>string) | ((v:T)=>boolean

TypeGuard

TypeGuard: function

Typescript doesn't infer typeguards for lambdas; it only sees predicates. This type allows you to cast a predicate to a type guard in a handy manner.

It comes in handy for discriminated unions with a 'kind' discriminator, for instance:

.filter(<TypeGuard<InBoard|OutBoard,InBoard>>(p => p.kind === "in_board"))

Also see typeGuard, instanceOf and typeOf.

Type declaration

    • (x: T): boolean
    • Parameters

      • x: T

      Returns boolean

WithEquality

WithEquality: string | number | boolean | null | HasEquals

List of types which provide equality semantics: some builtin JS types, for which === provides proper semantics, and then types providing HasEquals. The reason I use all over the place T&WithEquality instead of saying earlier in the declaration is: https://stackoverflow.com/a/45903143/516188

Functions

areEqual

  • areEqual(obj: any | null, obj2: any | null): boolean
  • Equality function which tries semantic equality (using .equals()) if possible, degrades to === if not available, and is also null-safe.

    Parameters

    • obj: any | null
    • obj2: any | null

    Returns boolean

fieldsHashCode

  • fieldsHashCode(...fields: any[]): number
  • Helper function for your objects so you can compute a hashcode. You can pass to this function all the fields of your object that should be taken into account for the hash, and the function will return a reasonable hash code.

    Parameters

    • Rest ...fields: any[]

      the fields of your object to take into account for the hashcode

    Returns number

getHashCode

  • getHashCode(obj: any | null): number
  • Hashing function which tries to call hashCode() and uses the object itself for numbers, then degrades for stringHashCode of the string representation if not available.

    Parameters

    • obj: any | null

    Returns number

hasEquals

  • Type guard for HasEquals: find out for a type with semantic equality, whether you should call .equals or ===

    Parameters

    Returns boolean

instanceOf

  • instanceOf<T>(ctor: object): TypeGuard<any, T>
  • Curried function returning a type guard telling us if a value is of a specific instance. Can be used when filtering to filter for the type and at the same time change the type of the generics on the container.

    Vector.of<any>("bad", new Date('04 Dec 1995 00:12:00 GMT')).filter(instanceOf(Date))
    => Vector.of<Date>(new Date('04 Dec 1995 00:12:00 GMT'))
    
    Option.of<any>("test").filter(instanceOf(Date))
    => Option.none<Date>()
    
    Option.of<any>(new Date('04 Dec 1995 00:12:00 GMT')).filter(instanceOf(Date))
    => Option.of<Date>(new Date('04 Dec 1995 00:12:00 GMT'))
    

    Also see typeGuard and typeOf.

    Type parameters

    • T

    Parameters

    • ctor: object

    Returns TypeGuard<any, T>

stringHashCode

  • stringHashCode(str: string): number
  • Helper function to compute a reasonable hashcode for strings.

    Parameters

    • str: string

    Returns number

typeGuard

  • typeGuard<T, U>(predicate: function, typeWitness?: U): TypeGuard<T, U>
  • Typescript doesn't infer typeguards for lambdas; it only sees predicates. This type allows you to cast a predicate to a type guard in a handy manner.

    It comes in handy for discriminated unions with a 'kind' discriminator, for instance:

    .filter(typeGuard(p => p.kind === "in_board", {} as InBoard))

    Normally you'd have to give both type parameters, but you can use the type witness parameter as shown in that example to skip the first type parameter.

    Also see typeGuard, instanceOf and typeOf.

    Type parameters

    • T

    • U: T

    Parameters

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

          • x: T

          Returns boolean

    • Optional typeWitness: U

    Returns TypeGuard<T, U>

typeOf

  • typeOf(typ: "string"): TypeGuard<any, string>
  • typeOf(typ: "number"): TypeGuard<any, number>
  • typeOf(typ: "boolean"): TypeGuard<any, boolean>
  • typeOf(typ: "symbol"): TypeGuard<any, symbol>
  • Curried function returning a type guard telling us if a value is of a specific type. Can be used when filtering to filter for the type and at the same time change the type of the generics on the container.

    Vector.of<any>(1,"a",2,3,"b").filter(typeOf("number"))
    => Vector.of<number>(1,2,3)
    
    Option.of<any>(1).filter(typeOf("string"))
    => Option.none<string>()
    
    Option.of<any>("str").filter(typeOf("string"))
    => Option.of<string>("str")
    

    Also see instanceOf and typeGuard.

    Parameters

    • typ: "string"

    Returns TypeGuard<any, string>

  • Parameters

    • typ: "number"

    Returns TypeGuard<any, number>

  • Parameters

    • typ: "boolean"

    Returns TypeGuard<any, boolean>

  • Parameters

    • typ: "symbol"

    Returns TypeGuard<any, symbol>

Generated using TypeDoc