Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GiftBox<U>

Type parameters

  • U

Hierarchy

  • Box<U>
    • GiftBox

Implements

Index

Constructors

constructor

  • new GiftBox(entity: any): GiftBox

Properties

Protected entity

entity: any

Methods

apply

  • apply<U>(fn: (t: U) => U): Box<U>
  • Pass subject to function, yielding result.

    example
      // apply square
      cyan.wrap(2+2).apply((x) => x*x).unwrap() // 16

    Type parameters

    • U

    Parameters

    • fn: (t: U) => U

      Function to invoke

        • (t: U): U
        • Parameters

          • t: U

          Returns U

    Returns Box<U>

each

  • each<T, U>(fn: (t: T) => U): Box<U[]>
  • Pass elements of (array-like) subject to function, yielding result.

    example
      // apply square
      cyan.wrap([1,2,3]).each((x) => x*x).unwrap() // [2,4,6]

    Type parameters

    • T

    • U

    Parameters

    • fn: (t: T) => U

      Function to invoke

        • (t: T): U
        • Parameters

          • t: T

          Returns U

    Returns Box<U[]>

expect

filter

  • filter<T>(fn: (t: T) => boolean): Box<T[]>
  • Filter elements of (array-like) subject by predicate, yielding result.

    example
      // apply square
      cyan.wrap([1,2,3]).map((x) => x>2).unwrap() // [3]

    Type parameters

    • T

    Parameters

    • fn: (t: T) => boolean

      Function to invoke

        • (t: T): boolean
        • Parameters

          • t: T

          Returns boolean

    Returns Box<T[]>

glom

  • glom<T, P1>(prop1: P1): Box<A<T>[P1]>
  • glom<T, P1, P2>(prop1: P1, prop2: P2): Box<A<A<T>[P1]>[P2]>
  • glom<T, P1, P2, P3>(prop1: P1, prop2: P2, prop3: P3): Box<A<A<A<T>[P1]>[P2]>[P3]>
  • glom(...path: string[]): Box<any>
  • Yield a nested property on the subject.

    example
     // Yield my.value
     cyan.wrap({ my: { value: 'here' }})
         .glom('my', 'value')
         .unwrap() // => 'here'
    
     // Yield by path
     cyan.wrap({ my: { value: 'here' }})
         .glom('my.value')
         .unwrap() // => 'here'

    Type parameters

    • T: U

    • P1: keyof A<T>

    Parameters

    • prop1: P1

    Returns Box<A<T>[P1]>

  • Type parameters

    • T: U

    • P1: keyof A<T>

    • P2: keyof A<A<T>[P1]>

    Parameters

    • prop1: P1
    • prop2: P2

    Returns Box<A<A<T>[P1]>[P2]>

  • Type parameters

    • T: U

    • P1: keyof A<T>

    • P2: keyof A<A<T>[P1]>

    • P3: keyof A<A<A<T>[P1]>[P2]>

    Parameters

    • prop1: P1
    • prop2: P2
    • prop3: P3

    Returns Box<A<A<A<T>[P1]>[P2]>[P3]>

  • Parameters

    • Rest ...path: string[]

    Returns Box<any>

invokes

  • invokes<K, F, R>(key: K, ...args: any[]): Box<R>
  • Yield the result of calling a named method on the subject.

    arg

    key {string} the method name

    Type parameters

    • K: keyof U

    • F: Method<U, K>

    • R

    Parameters

    • key: K
    • Rest ...args: any[]

    Returns Box<R>

its

  • its<K>(key: K): Box<U[K]>
  • Yield a named property on the subject.

    example
      // Pluck `my.value` from the wrapped subject
      cyan.wrap({ my: { value: 'here' }}).its('my').its('value').unwrap() // => 'here'

    Type parameters

    Parameters

    • key: K

      Method name

    Returns Box<U[K]>

map

  • map<T, U>(fn: (t: T) => U): Box<U[]>
  • Pass elements of (array-like) subject to function, yielding result.

    example
      // apply square
      cyan.wrap([1,2,3]).map((x) => x*x).unwrap() // [2,4,6]

    Type parameters

    • T

    • U

    Parameters

    • fn: (t: T) => U

      Function to invoke

        • (t: T): U
        • Parameters

          • t: T

          Returns U

    Returns Box<U[]>

unwrap

  • unwrap(): U
  • unwrap<Subject>(): never

wrap

  • wrap<T>(it: T): Box<T>
  • Yield an arbitrary subject.

    example
      // Open and shut
      cyan.wrap(2+2).unwrap() // => 4

    Type parameters

    • T

    Parameters

    • it: T

    Returns Box<T>

Static empty

  • empty(): Box<{}>
  • Build an empty box. Throw an error on yield if opened without wrapping anything else.

    Returns Box<{}>

Static with

  • with<U>(entity: U): Box<U>
  • with<U>(entity: Promise<U>): GiftBox<U>
  • Assemble a new box, yielding the provided entity.

    Type parameters

    • U

    Parameters

    • entity: U

      the value to yield to the link

    Returns Box<U>

  • Type parameters

    • U

    Parameters

    • entity: Promise<U>

    Returns GiftBox<U>

Generated using TypeDoc