TITLE: Is the pasting lemma also true in case of uniform continuity?
QUESTION [8 upvotes]: Let $\left(X, d_X \right)$ and  $\left( Y, d_Y \right)$ be metric spaces; let $A$ and $B$ be (non-empty) closed subsets of $X$ such that $X = A \cup B$; let $f \colon A \to Y$ and $g \colon B \to Y$ be uniformly continuous functions such that $f(x) = g(x)$ for all $x \in A \cap B$; and, let the function $h \colon X \to Y$ be defined as follows:
$$ h(x) \colon= \begin{cases} f(x) \ & \mbox{ if } \ x \in A, \\ g(x) \ & \mbox{ if } \ x \in B. \end{cases} $$
Then is $h$ also uniformly continuous on $X$?  
I know that $h$ is continuous, even if both $f$ and $g$ were merely continuous, which is Theorem 18.3 (The Pasting Lemma) in the book Topology by James R. Munkres, 2nd edition. 
My Attempt: 

Let $\varepsilon > 0$ be given. We need to find a real number $\delta > 0$ such that $$ d_Y \left(  h \left( x \right) , h \left( x^\prime \right) \right)  < \varepsilon $$ 
  for every pair of points $x, x^\prime \in X$ for which 
  $$ d_X \left( x, x^\prime \right) < \delta. $$
Now if $x, x^\prime \in A$ or if $x, x^\prime \in B$, then this is of course possible. 

What if $x \in A \setminus B$ and $x^\prime \in B \setminus A$?

REPLY [6 votes]: The case $X = \mathbb{R}^n$ is true. More generally, whenever $X$ has the property that every ball is path connected, this Pasting Lemma holds. Indeed, given $\epsilon > 0$, there exists $\delta > 0$ such that
$$x, y \in A \ \ \text{and}\ \  d(x, y) < \delta \implies d(f(x), f(y)) < \frac{\epsilon}{2}\\
x, y \in B \ \ \text{and}\ \  d(x, y) < \delta \implies d(g(x), g(y)) < \frac{\epsilon}{2}$$
Then, if $x \in A$ and $y \in B$, with $d(x, y) < \delta/2$, we can choose a point $z \in B(x; \delta/2)$ that is in $A \cap B$ (consider the path connecting $x$ and $y$ inside the ball). We have
$$d(x, z) <\delta, \quad d(z, y) < \delta$$
Therefore
$$d(h(x), h(y)) \leq d(f(x), f(z)) + d(g(z), g(y)) < \frac{\epsilon}{2} + \frac{\epsilon}{2} = \epsilon$$
The uniform continuity follows.