Skip to content

Commit

Permalink
fix: refactor functions (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmichalina authored Nov 5, 2022
1 parent 0e267d6 commit ecf09b8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
9 changes: 3 additions & 6 deletions src/maybe/transformers/maybe-to-observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IMaybe } from '../maybe.interface'
* If the Maybe is empty, the observable will immediately complete without emitting a value, otherwise it will emit
* the value contained and complete.
*
* @requires rxjs@^6.0
* @requires rxjs@^7.0
* @example
* of(maybe(5)).pipe(
* flatMap(maybeToObservable)
Expand All @@ -20,9 +20,6 @@ import { IMaybe } from '../maybe.interface'
* ).subscribe(a => console.log(a))
* // immediately completes with no emitted value
*/
export const maybeToObservable = <A>(m: IMaybe<A>): Observable<A> => {
return m.isNone()
? EMPTY
: of(m.valueOrThrow('isNone returned false for empty IMaybe.'))
.pipe(take(1))
export function maybeToObservable<A>(m: IMaybe<A>): Observable<A> {
return m.isNone() ? EMPTY : of(m.valueOrThrow('isNone returned false for empty IMaybe.')).pipe(take(1))
}
12 changes: 7 additions & 5 deletions src/maybe/transformers/maybe-to-promise.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { IMaybe } from '../maybe.interface'

export const maybeToPromise =
<TReject>(catchResponse?: TReject) =>
<TResolve>(maybe: IMaybe<TResolve>): Promise<TResolve> => maybe.isSome()
? Promise.resolve(maybe.valueOrUndefined() as TResolve)
: Promise.reject(catchResponse as TReject)
export function maybeToPromise<TResolve, TReject>(catchResponse?: TReject) {
return function maybeToPromise(maybe: IMaybe<TResolve>): Promise<TResolve> {
return maybe.isSome()
? Promise.resolve(maybe.valueOrThrow())
: Promise.reject(catchResponse)
}
}
9 changes: 5 additions & 4 deletions src/result/transformers/result-to-promise.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IResult } from '../result.interface'

export const resultToPromise =
<TOk, TFail>(result: IResult<TOk, TFail>): Promise<TOk> => result.isOk()
? Promise.resolve(result.unwrap() as TOk)
: Promise.reject(result.unwrapFail() as TFail)
export function resultToPromise<TOk, TFail>(result: IResult<TOk, TFail>): Promise<TOk> {
return result.isOk()
? Promise.resolve(result.unwrap())
: Promise.reject(result.unwrapFail())
}

0 comments on commit ecf09b8

Please sign in to comment.