All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.varmateo.yawg.util.Results Maven / Gradle / Ivy

/**************************************************************************
 *
 * Copyright (c) 2019-2020 Yawg project contributors.
 *
 **************************************************************************/

package com.varmateo.yawg.util;

import io.vavr.control.Try;

import com.varmateo.yawg.api.Result;
import com.varmateo.yawg.api.YawgException;


/**
 *
 */
public final class Results {

    private Results() {
        // Nothing to do.
    }


    /**
     *
     */
    public static  Result fromTry(final Try tryResult) {

        return tryResult
                .map(Result::success)
                .recover(YawgException.class, Result::failure)
                .get();
    }


    /**
     *
     */
    public static  Try toTry(final Result value) {

        final Try result;

        if (value.isSuccess()) {
            result = Try.success(value.get());
        } else {
            result = Try.failure(value.failureCause());
        }

        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy