import Result from './result.js' ; import Maybe from './maybe.js' ; import { curry1 } from './-private/utils.js' ; param result export function transposeResult < T , E > ( result ) { return result . match ( { Ok : ( maybe ) => maybe . match ( { Just : ( v ) => Maybe . just ( Result . ok ( v ) ) , Nothing : ( ) => Maybe . nothing ( ) , } ) , Err : ( e ) => Maybe . just ( Result . err < T , E > ( e ) ) , } ) ; } param result returns export function toMaybe < T > ( result ) { return result . isOk ? Maybe . just ( result . value ) : Maybe . nothing ( ) ; } param errValue param maybe export function fromMaybe < T , E > ( errValue , maybe ) ; export function fromMaybe < T , E > ( errValue ) ; export function fromMaybe < T , E > ( errValue , maybe ? ) { const op = ( m ) => ( m . isJust ? Result . ok < T , E > ( m . value ) : Result . err < T , E > ( errValue ) ) ; return curry1 ( op , maybe ) ; } param maybe export function transposeMaybe < T , E > ( maybe ) { return maybe . match ( { Just : ( result ) => result . match ( { Ok : ( v ) => Result . ok ( Maybe . just ( v ) ) , Err : ( e ) => Result . err ( e ) , } ) , Nothing : ( ) => Result . ok ( Maybe . nothing ( ) ) , } ) as Result < Maybe < T > , E > ; } typeparam typeparam param error param maybe returns export function toOkOrErr < T , E > ( error , maybe ) ; export function toOkOrErr < T , E > ( error ) ; export function toOkOrErr < T , E > ( error , maybe ? ) { const op = ( m ) => ( m . isJust ? Result . ok < T , E > ( m . value ) : Result . err < T , E > ( error ) ) ; return maybe !== undefined ? op ( maybe ) : op ; } typeparam typeparam param elseFn param maybe returns export function toOkOrElseErr < T , E > ( elseFn , maybe ) ; export function toOkOrElseErr < T , E > ( elseFn ) ; export function toOkOrElseErr < T , E > ( elseFn , maybe ? ) { const op = ( m ) => ( m . isJust ? Result . ok < T , E > ( m . value ) : Result . err < T , E > ( elseFn ( ) ) ) ; return curry1 ( op , maybe ) ; } typeparam param result returns export function fromResult < T > ( result ) { return result . isOk ? Maybe . just ( result . value ) : Maybe . nothing < T > ( ) ; }