Skip to content

Latest commit

 

History

History
50 lines (29 loc) · 1.45 KB

File metadata and controls

50 lines (29 loc) · 1.45 KB

StringError Interface and Implementation

Overview

The StringError interface and its implementation provide a structure for handling error messages as strings within Kotlin applications. This can be particularly useful in scenarios where error messages need to be encapsulated within objects instead of just plain strings.

StringError Interface

Definition

The StringError interface extends the generic Error interface and provides a property for the error message.

Properties

  • val message: String: Represents the error message.

StringErrorImpl Class

Definition

The StringErrorImpl class is an open class that implements the StringError interface. It provides concrete implementations for the methods defined in StringError.

Properties

  • val message: String: Represents the error message passed through the constructor.

Result Extension Function

Failure Function

An extension function for the Result class is provided to streamline the creation of failure results containing StringError messages.

fun <D> Result.Companion.Failure(message: String): Result<D, StringError>

Parameters

  • message: String: The error message to be encapsulated in the StringErrorImpl object.

Usage

This extension function simplifies creating a failure result with a string error message, ensuring consistency and reducing boilerplate code.

val result = Result.Failure<String>("Some fail")