Skip to content

Commit

Permalink
Merge development into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sbertix committed Apr 17, 2021
2 parents 84ddaa5 + b473eea commit be234e0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Sources/ComposableRequest/Wrapper/Wrappable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ import CoreGraphics
#endif

/// A `protocol` allowing to `init` `Wrapper`s.
public protocol Wrappable {
public protocol Wrappable: CustomStringConvertible {
/// Wrap `self` into a `Wrapper`.
var wrapped: Wrapper { get }
}

public extension Wrappable {
/// The description.
///
/// - note: Override this for custom behavior.
var description: String { wrapped.description }
}

extension Bool: Wrappable {
/// Wrap `self` into a `Wrapper`.
public var wrapped: Wrapper { .init(booleanLiteral: self) }
Expand Down Expand Up @@ -47,6 +54,13 @@ extension NSNull: Wrappable {
public var wrapped: Wrapper { .empty }
}

extension Optional: CustomStringConvertible where Wrapped: Wrappable {
/// The description.
///
/// - note: Override this for custom behavior.
public var description: String { self?.description ?? "<empty>" }
}

extension Optional: Wrappable where Wrapped: Wrappable {
/// Wrap `self` into a `Wrapper`.
public var wrapped: Wrapper { flatMap { $0.wrapped } ?? .empty }
Expand Down

0 comments on commit be234e0

Please sign in to comment.