   guard let components = request.url.flatMap({ URLComponents(url: $0, resolvingAgainstBaseURL: false) })
   else { return (method, [], [:]) }
 
-  let path = components.path
-    .components(separatedBy: "/")
-    .flatMap { $0.isEmpty ? nil : $0 } // bad flatMap, bad
+  let path = components.path.components(separatedBy: "/")
+    |> mapOptional { $0.isEmpty ? nil : $0 }
 
   var query: [String: String] = [:]
   components.queryItems?.forEach { query[$0.name] = $0.value ?? "" }

    return pa.map(a2b)
  }

  public static func <¢ (a: A, p: Parser<()>) -> Parser {
    return const(a) <¢> p
  }
}

extension Parser { // : Alt
  public static func <|> (lhs: Parser, rhs: Parser) -> Parser { // : Alt
    return Parser<A> { route in
      lhs.parse(route) ?? rhs.parse(route)
    }
  }
}

extension Parser { // : Apply
  public static func <*> <B>(pa2b: Parser<(A) -> B>, pa: Parser) -> Parser<B> { // : Apply
    return Parser<B> { route in
      guard let (more, a2b) = pa2b.parse(route) else { return nil }
      guard let (rest, a) = pa.parse(more) else { return nil }

  }
}

// MARK: - Applicative

public func pure<A>(_ a: A) -> Parser<A> {
  return Parser<A> { route in
    (route, a)
  }
}

// MARK: - Alt

extension Parser {
  public static func <|> (lhs: Parser, rhs: Parser) -> Parser {
    return Parser<A> { route in
      lhs.parse(route) ?? rhs.parse(route)
    }
  }
}

// MARK: - Plus

extension Parser {
  public static var empty: Parser {
    return Parser { _ in nil }
  }
}

// MARL: - Combinators

public let end = Parser<()> { route in
  guard route.path.isEmpty else { return nil }
