Skip to content

Commit

Permalink
return Effect from get.result
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed May 9, 2024
1 parent 66bc5c8 commit a6af10b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-vans-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-rx/rx": minor
---

return Effect from get.result
8 changes: 7 additions & 1 deletion docs/rx/Registry.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ Added in v1.0.0

```ts
export declare const make: (
options?: { readonly initialValues: Iterable<readonly [Rx.Rx<any>, any]> } | undefined
options?:
| {
readonly initialValues?: Iterable<readonly [Rx.Rx<any>, any]> | undefined
readonly scheduleTask?: ((f: () => void) => void) | undefined
readonly timeoutResolution?: number | undefined
}
| undefined
) => Registry
```
Expand Down
4 changes: 2 additions & 2 deletions docs/rx/Rx.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ Added in v1.0.0
export interface Context {
<A>(rx: Rx<A>): A
readonly get: <A>(rx: Rx<A>) => A
readonly result: <A, E>(rx: Rx<Result.Result<A, E>>) => Exit.Exit<A, E | NoSuchElementException>
readonly result: <A, E>(rx: Rx<Result.Result<A, E>>) => Effect.Effect<A, E>
readonly once: <A>(rx: Rx<A>) => A
readonly addFinalizer: (f: () => void) => void
readonly mount: <A>(rx: Rx<A>) => void
Expand Down Expand Up @@ -513,7 +513,7 @@ Added in v1.0.0
**Signature**
```ts
export type GetResult = <A, E>(rx: Rx<Result.Result<A, E>>) => Exit.Exit<A, E | NoSuchElementException>
export type GetResult = <A, E>(rx: Rx<Result.Result<A, E>>) => Effect.Effect<A, E>
```
Added in v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions packages/rx/src/Rx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export declare namespace Rx {
* @since 1.0.0
* @category models
*/
export type GetResult = <A, E>(rx: Rx<Result.Result<A, E>>) => Exit.Exit<A, E | NoSuchElementException>
export type GetResult = <A, E>(rx: Rx<Result.Result<A, E>>) => Effect.Effect<A, E>

/**
* @since 1.0.0
Expand Down Expand Up @@ -196,7 +196,7 @@ export interface Writable<R, W> extends Rx<R> {
export interface Context {
<A>(rx: Rx<A>): A
readonly get: <A>(rx: Rx<A>) => A
readonly result: <A, E>(rx: Rx<Result.Result<A, E>>) => Exit.Exit<A, E | NoSuchElementException>
readonly result: <A, E>(rx: Rx<Result.Result<A, E>>) => Effect.Effect<A, E>
readonly once: <A>(rx: Rx<A>) => A
readonly addFinalizer: (f: () => void) => void
readonly mount: <A>(rx: Rx<A>) => void
Expand Down
18 changes: 14 additions & 4 deletions packages/rx/src/internal/registry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { NoSuchElementException } from "effect/Cause"
import * as Effect from "effect/Effect"
import * as Equal from "effect/Equal"
import type { Exit } from "effect/Exit"
import * as Exit from "effect/Exit"
import { pipe } from "effect/Function"
import { globalValue } from "effect/GlobalValue"
import * as Option from "effect/Option"
Expand Down Expand Up @@ -426,11 +425,22 @@ const LifetimeProto: Omit<Lifetime<any>, "node" | "finalizers" | "disposed"> = {
return parent.value()
},

result<A, E>(this: Lifetime<any>, rx: Rx.Rx<Result.Result<A, E>>): Exit<A, E | NoSuchElementException> {
result<A, E>(this: Lifetime<any>, rx: Rx.Rx<Result.Result<A, E>>): Effect.Effect<A, E> {
if (this.disposed) {
throw disposedError(this.node.rx)
}
return Result.toExit(this.get(rx))
const result = this.get(rx)
switch (result._tag) {
case "Initial": {
return Effect.never
}
case "Failure": {
return Exit.failCause(result.cause)
}
case "Success": {
return Effect.succeed(result.value)
}
}
},

once<A>(this: Lifetime<any>, rx: Rx.Rx<A>): A {
Expand Down

0 comments on commit a6af10b

Please sign in to comment.