A Functional Joke

My friends told me to start with a joke.
  #!/usr/bin/env swift

  // The Joke

  let joke = knockKnock(withName: "Xiaoxing") >>- curry(endWith)("Yes!")
  print(joke)

  // Infrastructure

  func knockKnock(withName name: String) -> Result<String> {
      return .success("Knock knock! Who's there? \(name)! \(name) Hu?")
  }

  func endWith(joke: String, all: String) -> Result<String> {
      return .success(all + " \(joke)")
  }

  public enum Result<T> {
      case success(T)
      case failure(Error)
  }

  extension Result {
      public func flatMap<U>(f: (T)->Result<U>) -> Result<U> {
          switch self {
          case .success(let t): return f(t)
          case .failure(let err): return .failure(err)
          }
      }

      public var value: T? {
          switch self {
          case .success(let v): return v
          case .failure: return nil
          }
      }
  }
  precedencegroup MonadicPrecedenceLeft {
      associativity: left
      lowerThan: LogicalDisjunctionPrecedence
      higherThan: AssignmentPrecedence
  }

  infix operator >>- : MonadicPrecedenceLeft

  public func >>- <T, U>(a: Result<T>, f: (T) -> Result<U>) -> Result<U> {
      return a.flatMap(f: f)
  }

  public func curry<A, B, C>(_ f: @escaping (A, B) -> C) -> (A) -> (B) -> C {
      return { a in
          { b in
              f(a, b) } }
  }
Output of above code snippet.
success("Knock knock! Who's there? Xiaoxing! Xiaoxing Hu? Yes!")