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.
The Doddle instance.
The error handler function.
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.
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.
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.
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.
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.
The action to perform.
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.
The action to perform.
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.
The action to perform.
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.
The action to perform.
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.
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.
The action to perform.
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.
// 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.
The function to apply to the pulled value.
// 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.
The function to apply to the pulled value.
// 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.
// 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.
// 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.
// 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.
A memoized function that pulls this and returns its result.
Returns a short description of the Doddle value and its state.
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.
The other Doddles to zip with.
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.