Swiftpack.co - christopherweems/Resultto as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by christopherweems.
christopherweems/Resultto v0.1.2
A collection of handy result builders
⭐️ 0
🕓 2 years ago
.package(url: "https://github.com/christopherweems/Resultto.git", from: "v0.1.2")

Resultto

[Public Archive]

Now incorporated within the unstandard library.


A collection of handy result builders.

Foundation not required for most builder types. Requires Swift 5.4+

AllNil

Returns true if all elements are nil. Elements are not required to be homogenous.

struct Element {
    var title: String?
    var description: String?
    var child: Self?
    
    @AllNil var isEmpty: Bool {
        title
        description
        child
        
    }
    
}

Count

Total of true boolean values

struct FooBar {
    var foo: Int?
    var bar: Bool?
    
    @Count var nonOptionalCount: Int {
        foo != nil
        bar != nil
        
    }
    
}

SetResult

Avoid some punctuation while building Set properties.

struct FooBar {
    var foo: Int
    var bar: Int
    
    @SetResult var fooAndBar: Set<Int> {
        foo
        bar
        
    }
    
}

SingleResult

Returns a single element. Useful to avoid typing a few return keywords.

extension Bool {
    @SingleResult var enEspañol: String {
        switch self {
            case true: "Sí"
            case false: "No""
        }
    }
    
}

UUIDResult

Convienence formatter for specifying UUID properties. (Requires Foundation)

protocol UUIDIdentifiable: Identifiable where ID == UUID {
    @UUIDResult var id: UUID { get }
    
}

struct Element: UUIDIdentifiable {
    var id: UUID {
        (194, 210, 39, 207, 170, 13, 68, 151, 190, 189, 41, 237, 240, 95, 174, 248)
    }
    
}

URLResult

Convienence formatter to specify URLs by strings for urls you know to be valid. URL strings are unsafely unwrapped. (Requires Foundation)

protocol Website {
    @URLResult var url: URL
    
}

struct Wikipedia: Website {
    var url: URL {
        "https://wikipedia.org"
    }
    
}

GitHub

link
Stars: 0
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Resultto 0.2.2
2 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics