Skip to content

Instantly share code, notes, and snippets.

@danielctull
Last active June 1, 2022 08:58
Show Gist options
  • Select an option

  • Save danielctull/40e4fcc5fc3f70980ea582a1cced4e7d to your computer and use it in GitHub Desktop.

Select an option

Save danielctull/40e4fcc5fc3f70980ea582a1cced4e7d to your computer and use it in GitHub Desktop.

Revisions

  1. danielctull revised this gist Dec 3, 2020. No changes.
  2. danielctull created this gist Dec 3, 2020.
    34 changes: 34 additions & 0 deletions Really.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@

    // EXAMPLE

    let string: String? = "Hello World" // String?
    let unwrappedString = string.really.srsly.itsfine.honestly.aaarggh // String
    print(unwrappedString)

    // IMPLEMENTATION

    extension Optional {
    var really: Really<Wrapped> {
    Really(srsly: Srsly(itsfine: ItsFine(honestly: Honestly(aaarggh: { self! }))))
    }
    }

    struct Really<Value> {
    let srsly: Srsly<Value>
    }

    struct Srsly<Value> {
    let itsfine: ItsFine<Value>
    }

    struct ItsFine<Value> {
    let honestly: Honestly<Value>
    }

    struct Honestly<Value> {
    var aaarggh: Value { getAaarggh() }
    private let getAaarggh: () -> Value
    init(aaarggh: @escaping () -> Value) {
    getAaarggh = aaarggh
    }
    }