doddle
    Preparing search index...

    Class Doddle<T>

    A TypeScript-first doddle evaluation primitive. An object that will only evaluate its initializer function when the pull method is called.

    The initializer can return another Doddle, which will be chained like a promise.

    Type Parameters

    • T
    Index

    Accessors

    Methods

    Accessors

    Methods

    • Returns a new Doddle based on this one. When pulled, it will pull this and yield the same value. If an error occurs, the handler will be called with the error. The doddle then yields whatever the handler returns.

      You can pass an async handler only if this is async too.

      Type Parameters

      • T
      • R

      Parameters

      Returns DoddleAsync<T | Awaited<R>>

      const d = doddle(() => {
      throw new Error("Oops")
      })
      const handled = d.catch(error => {
      console.error(error)
      return 42
      })
      const pulled = handled.pull()
      console.log(pulled) // 42

      // async Doddles allow an async handler:
      const d = doddle(async () => {
      throw new Error("Oops")
      })
      const handled = d.catch(async error => {
      console.error(error)
      return 42
      })
      const pulled = await handled.pull()
      console.log(pulled) // 42

      // @ts-expect-error but passing an async handler for a sync doddle isn't allowed.
      const d = doddle(() => 1).catch(async () => 2)
    • Returns a new Doddle based on this one. When pulled, it will pull this and yield the same value. If an error occurs, the handler will be called with the error. The doddle then yields whatever the handler returns.

      You can pass an async handler only if this is async too.

      Type Parameters

      • T
      • R

      Parameters

      Returns DoddleAsync<T | Awaited<R>>

      const d = doddle(() => {
      throw new Error("Oops")
      })
      const handled = d.catch(error => {
      console.error(error)
      return 42
      })
      const pulled = handled.pull()
      console.log(pulled) // 42

      // async Doddles allow an async handler:
      const d = doddle(async () => {
      throw new Error("Oops")
      })
      const handled = d.catch(async error => {
      console.error(error)
      return 42
      })
      const pulled = await handled.pull()
      console.log(pulled) // 42

      // @ts-expect-error but passing an async handler for a sync doddle isn't allowed.
      const d = doddle(() => 1).catch(async () => 2)
    • Returns a new Doddle based on this one. When pulled, it will pull this and yield the same value. If an error occurs, the handler will be called with the error. The doddle then yields whatever the handler returns.

      You can pass an async handler only if this is async too.

      Type Parameters

      • T
      • R

      Parameters

      • this: Matches_Mixed_Value<T>

        The Doddle instance.

      • handler: (error: any) => SomeAsync<R>

        The error handler function.

      Returns Doddle<T | Promise<R>>

      const d = doddle(() => {
      throw new Error("Oops")
      })
      const handled = d.catch(error => {
      console.error(error)
      return 42
      })
      const pulled = handled.pull()
      console.log(pulled) // 42

      // async Doddles allow an async handler:
      const d = doddle(async () => {
      throw new Error("Oops")
      })
      const handled = d.catch(async error => {
      console.error(error)
      return 42
      })
      const pulled = await handled.pull()
      console.log(pulled) // 42

      // @ts-expect-error but passing an async handler for a sync doddle isn't allowed.
      const d = doddle(() => 1).catch(async () => 2)
    • Returns a new Doddle based on this one. When pulled, it will pull this and yield the same value. If an error occurs, the handler will be called with the error. The doddle then yields whatever the handler returns.

      You can pass an async handler only if this is async too.

      Type Parameters

      • T
      • R

      Parameters

      • this: Matches_Mixed_Value<T>

        The Doddle instance.

      • handler: (error: any) => R | Doddle<R>

        The error handler function.

      Returns Doddle<T | R>

      const d = doddle(() => {
      throw new Error("Oops")
      })
      const handled = d.catch(error => {
      console.error(error)
      return 42
      })
      const pulled = handled.pull()
      console.log(pulled) // 42

      // async Doddles allow an async handler:
      const d = doddle(async () => {
      throw new Error("Oops")
      })
      const handled = d.catch(async error => {
      console.error(error)
      return 42
      })
      const pulled = await handled.pull()
      console.log(pulled) // 42

      // @ts-expect-error but passing an async handler for a sync doddle isn't allowed.
      const d = doddle(() => 1).catch(async () => 2)
    • Returns a new Doddle based on this one. When pulled, it will pull this and yield the same value. If an error occurs, the handler will be called with the error. The doddle then yields whatever the handler returns.

      You can pass an async handler only if this is async too.

      Type Parameters

      • R

      Parameters

      • handler: R extends PromiseLike<any> ? never : (error: any) => R | Doddle<R>

        The error handler function.

      Returns Doddle<T | R>

      const d = doddle(() => {
      throw new Error("Oops")
      })
      const handled = d.catch(error => {
      console.error(error)
      return 42
      })
      const pulled = handled.pull()
      console.log(pulled) // 42

      // async Doddles allow an async handler:
      const d = doddle(async () => {
      throw new Error("Oops")
      })
      const handled = d.catch(async error => {
      console.error(error)
      return 42
      })
      const pulled = await handled.pull()
      console.log(pulled) // 42

      // @ts-expect-error but passing an async handler for a sync doddle isn't allowed.
      const d = doddle(() => 1).catch(async () => 2)
    • Returns a new Doddle based on this one. When pulled, it will pull this and invoke the given action function as a side-effect. It will then yield whatever this did.

      If the action returns a Promise, it will be awaited before yielding the result, making the returned Doddle async.

      Type Parameters

      • T

      Parameters

      Returns DoddleAsync<Awaited<T>>

    • Returns a new Doddle based on this one. When pulled, it will pull this and invoke the given action function as a side-effect. It will then yield whatever this did.

      If the action returns a Promise, it will be awaited before yielding the result, making the returned Doddle async.

      Type Parameters

      • T

      Parameters

      Returns DoddleAsync<T>

    • Returns a new Doddle based on this one. When pulled, it will pull this and invoke the given action function as a side-effect. It will then yield whatever this did.

      If the action returns a Promise, it will be awaited before yielding the result, making the returned Doddle async.

      Type Parameters

      • T

      Parameters

      Returns Doddle<T>

    • Returns a new Doddle based on this one. When pulled, it will pull this and invoke the given action function as a side-effect. It will then yield whatever this did.

      If the action returns a Promise, it will be awaited before yielding the result, making the returned Doddle async.

      Type Parameters

      • T

      Parameters

      Returns DoddleAsync<T>

    • Returns a new Doddle based on this one. When pulled, it will pull this and invoke the given action function as a side-effect. It will then yield whatever this did.

      If the action returns a Promise, it will be awaited before yielding the result, making the returned Doddle async.

      Type Parameters

      • T
      • R

      Parameters

      Returns Doddle<T | Promise<T>>

    • Returns a new Doddle based on this one. When pulled, it will pull this and invoke the given action function as a side-effect. It will then yield whatever this did.

      If the action returns a Promise, it will be awaited before yielding the result, making the returned Doddle async.

      Type Parameters

      • T

      Parameters

      Returns Doddle<T>

    • Creates a new Doddle based on this. When pulled, it will pull this and project the result using the given function.

      When this is async, the projection will be passed the awaited value, and the function will return an async Doddle. It also happens if you pass an async projection.

      Type Parameters

      • T
      • R

      Parameters

      Returns DoddleAsync<R>

      // Sync inputs:
      const d = doddle(() => 42)
      const mapped = d.map(x => x + 1)
      const pulled = mapped.pull()
      console.log(pulled) // 43

      // async inputs:
      const d = doddle(async () => 42)
      const mapped = d.map(x => x + 1) // note that the awaited value is used
      const pulled = await mapped.pull()
      console.log(pulled) // 43

      // async projection:
      const d = doddle(() => 42)
      const mapped = d.map(async x => x + 1)
      const pulled = await mapped.pull()
      console.log(pulled) // 43
    • Creates a new Doddle based on this. When pulled, it will pull this and project the result using the given function.

      When this is async, the projection will be passed the awaited value, and the function will return an async Doddle. It also happens if you pass an async projection.

      Type Parameters

      • T
      • R

      Parameters

      Returns DoddleAsync<Awaited<R>>

      // Sync inputs:
      const d = doddle(() => 42)
      const mapped = d.map(x => x + 1)
      const pulled = mapped.pull()
      console.log(pulled) // 43

      // async inputs:
      const d = doddle(async () => 42)
      const mapped = d.map(x => x + 1) // note that the awaited value is used
      const pulled = await mapped.pull()
      console.log(pulled) // 43

      // async projection:
      const d = doddle(() => 42)
      const mapped = d.map(async x => x + 1)
      const pulled = await mapped.pull()
      console.log(pulled) // 43
    • Creates a new Doddle based on this. When pulled, it will pull this and project the result using the given function.

      When this is async, the projection will be passed the awaited value, and the function will return an async Doddle. It also happens if you pass an async projection.

      Type Parameters

      • T
      • R

      Parameters

      Returns DoddleAsync<R>

      // Sync inputs:
      const d = doddle(() => 42)
      const mapped = d.map(x => x + 1)
      const pulled = mapped.pull()
      console.log(pulled) // 43

      // async inputs:
      const d = doddle(async () => 42)
      const mapped = d.map(x => x + 1) // note that the awaited value is used
      const pulled = await mapped.pull()
      console.log(pulled) // 43

      // async projection:
      const d = doddle(() => 42)
      const mapped = d.map(async x => x + 1)
      const pulled = await mapped.pull()
      console.log(pulled) // 43
    • Creates a new Doddle based on this. When pulled, it will pull this and project the result using the given function.

      When this is async, the projection will be passed the awaited value, and the function will return an async Doddle. It also happens if you pass an async projection.

      Type Parameters

      • T
      • R

      Parameters

      Returns Doddle<R>

      // Sync inputs:
      const d = doddle(() => 42)
      const mapped = d.map(x => x + 1)
      const pulled = mapped.pull()
      console.log(pulled) // 43

      // async inputs:
      const d = doddle(async () => 42)
      const mapped = d.map(x => x + 1) // note that the awaited value is used
      const pulled = await mapped.pull()
      console.log(pulled) // 43

      // async projection:
      const d = doddle(() => 42)
      const mapped = d.map(async x => x + 1)
      const pulled = await mapped.pull()
      console.log(pulled) // 43
    • Creates a new Doddle based on this. When pulled, it will pull this and project the result using the given function.

      When this is async, the projection will be passed the awaited value, and the function will return an async Doddle. It also happens if you pass an async projection.

      Type Parameters

      • T
      • R

      Parameters

      • this: Matches_Mixed_Value<T>
      • projection: (value: PulledAwaited<T>) => R | Doddle<R>

        The function to apply to the pulled value.

      Returns Doddle<R | Promise<R>>

      // Sync inputs:
      const d = doddle(() => 42)
      const mapped = d.map(x => x + 1)
      const pulled = mapped.pull()
      console.log(pulled) // 43

      // async inputs:
      const d = doddle(async () => 42)
      const mapped = d.map(x => x + 1) // note that the awaited value is used
      const pulled = await mapped.pull()
      console.log(pulled) // 43

      // async projection:
      const d = doddle(() => 42)
      const mapped = d.map(async x => x + 1)
      const pulled = await mapped.pull()
      console.log(pulled) // 43
    • Creates a new Doddle based on this. When pulled, it will pull this and project the result using the given function.

      When this is async, the projection will be passed the awaited value, and the function will return an async Doddle. It also happens if you pass an async projection.

      Type Parameters

      • T
      • R

      Parameters

      Returns Doddle<R>

      // Sync inputs:
      const d = doddle(() => 42)
      const mapped = d.map(x => x + 1)
      const pulled = mapped.pull()
      console.log(pulled) // 43

      // async inputs:
      const d = doddle(async () => 42)
      const mapped = d.map(x => x + 1) // note that the awaited value is used
      const pulled = await mapped.pull()
      console.log(pulled) // 43

      // async projection:
      const d = doddle(() => 42)
      const mapped = d.map(async x => x + 1)
      const pulled = await mapped.pull()
      console.log(pulled) // 43
    • Returns a memoized function, which acts like this Doddle while hiding its type.

      Returns () => T

      A memoized function that pulls this and returns its result.

    • Returns a short description of the Doddle value and its state.

      Returns string

    • Returns a new Doddle based on this one, together with the input Doddles. When pulled, it will pull this and all others, yielding their results in an array.

      If either this or any of others is async, the resulting Doddle will also be async.

      Type Parameters

      Parameters

      • ...others: Others

        The other Doddles to zip with.

      Returns Is_Any_Pure_Async<
          [Doddle<T>, ...Others[]],
          DoddleAsync<
              [
                  PulledAwaited<T>,
                  ...{ [K in string | number | symbol]: PulledAwaited<Others[K<K>]> }[],
              ],
          >,
          Is_Any_Mixed<
              [Doddle<T>, ...Others[]],
              Doddle<
                  MaybePromise<
                      [
                          PulledAwaited<T>,
                          ...{ [K in string | number | symbol]: PulledAwaited<Others[K<K>]> }[],
                      ],
                  >,
              >,
              Doddle<
                  [
                      Pulled<T>,
                      ...{ [K in string | number | symbol]: Pulled<Others[K<K>]> }[],
                  ],
              >,
          >,
      >