[Question]
  [
The goal is, having taken a string as input, duplicate each latin letter and "toggle" its case (i.e. uppercase becomes lowercase and vice-versa).
Example inputs & outputs:
```
Input      Output
bad        bBaAdD
Nice       NniIcCeE
T e S t    Tt eE Ss tT
s E t      sS Ee tT
1!1!1st!   1!1!1sStT!
n00b       nN00bB     
(e.g.)     (eE.gG.)
H3l|@!     Hh3lL|@!
```
The input consists of printable ASCII symbols.
*You shouldn't duplicate non-latin letters, numbers, special chars.*
  
[Answer]
# Python, ~~56~~ 54 bytes
```
lambda s:''.join(c+c.swapcase()*c.isalpha()for c in s)
```
Test it on [Ideone](http://ideone.com/fj1Ge9).
[Answer]
# JavaScript ES6, ~~70~~ ~~68~~ ~~66~~ 64 bytes
*Saved 2 bytes thanks to [@Kevin Lau - not Kenny](https://codegolf.stackexchange.com/users/52194/kevin-lau-not-kenny)*
*Saved 2 bytes thanks to [@Cᴏɴᴏʀ O'Bʀɪᴇɴ](https://codegolf.stackexchange.com/users/31957/c%E1%B4%8F%C9%B4%E1%B4%8F%CA%80-ob%CA%80%C9%AA%E1%B4%87%C9%B4)*
```
s=>s.replace(/[A-Z]/gi,l=>l+l[`to${l<"a"?"Low":"Upp"}erCase`]())
```
## Explanation
This uses a really hacky:
```
l[`to${l<"a"?"Low":"Upp"}erCase`]()
```
which ungolfed is:
```
l[`to${
   l < "a" ?
   "Low" : 
   "Upp"
}erCase`]()
```
Basically `l < "a"` checks if the code point of the letter is less then the code point of `a` (therefore being an uppercase letter). If it is it'll do `to + Low + erCase` which becomed `l['toLowerCase']()` and makes the character lowercase. ``` quotes allow string formatting so essentially you can think of:
```
`to${l < "a" ?"Low" : "Upp"}erCase`
```
as: `"to" + (l<"a" ? "Low" : "Upp") + "erCase"` which generates the function to call (make the string upper or lower case). We put this in square brackets `[ ... ]` which lets us access a property given its name as a string. This returns the appropriate function and then we just call it.
[Answer]
# Jelly, 5 bytes
```
żŒsQ€
```
[Try it online!](http://jelly.tryitonline.net/#code=xbzFknNR4oKs&input=&args=J1QgZSBTIHQn)
### How it works
```
żŒsQ€  Main link. Argument: s (string)
 Œs    Yield s with swapped case.
ż      Zip s with the result.
   Q€  Unique each; deduplicate each pair of characters.
```
[Answer]
# Ruby, ~~37~~ 33 (30 +  `-p` flag) bytes
`swapcase` to the rescue! Sort of. -4 bytes from @Lynn.
```
gsub(/[a-z]/i){$&+$&.swapcase}
```
[Answer]
# C, ~~63~~ 60 bytes
```
f(char*s){for(;*s;s++)isalpha(putchar(*s))&&putchar(32^*s);}
```
Uses the fact that `'a' XOR 32 == 'A'`, etc.
Three bytes saved thanks to FryAmTheEggman.
[Answer]
## CJam, 11 bytes
```
l_el_eu.+.|
```
[Test it here.](http://cjam.aditsu.net/#code=l_el_eu.%2B.%7C&input=Ba%20d1!zzz)
### Explanation
```
l      e# Read input.
_el    e# Duplicate, convert to lower case.
_eu    e# Duplicate, convert to upper case.
.+     e# Concatenate the two characters in matching positions from those two
       e# strings. E.g. "ab!" "AB!" would give ["aA" "bB" "!!"].
       e# For each character from the original string and the corresponding 
.|     e# string from this list, take the set union (which eliminates duplicates
       e# and keeps the order the values appear in from left to right, so that
       e# the original case of each letter comes first).
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 7 bytes
```
sm{+dr2
```
[Test suite](http://pyth.herokuapp.com/?code=sm%7B%2Bdr2&test_suite=1&test_suite_input=%22bad%22%0A%22Nice%22%0A%22T+e+S+t%22%0A%22s+E+t%22&debug=0).
```
sm{+dr2    input: Q
sm{+dr2dQ  implicit arguments
        Q  input
 m         for each character as d:
     r2d       swapcase
   +d          prepend d
  {            deduplicate
s          join as string
```
[Answer]
# Python 3.5, ~~60~~ 56 bytes:
```
for i in input():print(end=i+i.swapcase()[:i.isalpha()])
```
A full program. Will try to golf more. 
[Try It Online! (Ideone)](http://ideone.com/5j1h7y)
[Answer]
# Haskell, 73 bytes
```
l=['a'..'z']
u=['A'..]
(>>= \c->c:maybe""pure(lookup c$zip l u++zip u l))
```
[Answer]
# [Cheddar](http://cheddar.vihan.org), ~~118~~ 104 bytes
```
(s)->s.chars.map((i)->{if String.letters has i.lower{if i<"a"{i+i.lower}else{i+i.upper}}else{i}}).join()
```
First real Cheddar answer!!! This is a lot less climactic than I thought it would be... ;\_;
Works with release [1.0.0-beta.9](https://github.com/cheddar-lang/Cheddar/releases/tag/v1.0.0-beta.9), non-competing.
---
As you can tell I didn't design cheddar to be golfy :/
Ungolfed:
```
(str) -> str.chars.map(
    (i) -> {
        if String.letters has i {
            if i < "a" { // Check char code, meaning it's upper case if true
                i+i.lower
            }
            else {
                i+i.upper
            }
        } else {
            i
        }
    }
).join()
```
Usage:
```
var doThing = <code here>;
doThing("input...");
```
---
**Update:** 7/14/16 I've finished ternaries making this come down to 84 bytes
## Cheddar, 84 bytes
```
(s)->s.chars.map((i)->String.letters has i.lower?i<"a"?i+i.lower:i+i.upper:i).join()
```
works as of version [v1.0.0-beta.14](https://github.com/cheddar-lang/Cheddar/releases/tag/v1.0.0-beta.14)
[Answer]
# Retina, ~~28~~ ~~27~~ 21 bytes
Those are tabs, not spaces.
```
.
$&  $&
T`lL    p`Ll_`  .
```
[**Try it online**](http://retina.tryitonline.net/#code=LgokJgkkJgpUYGxMCXBgTGxfYAku&input=YmFkCk5pY2UKVCBlIFMgdApzIEUgdAoxITEhMXN0IQpuMDBiIAooZS5nLikKSDNsfEAh)
Thanks for the suggestions everyone.
[Answer]
# C, ~~87~~ 80
Pass a string as input to `f()` and the output is written to STDOUT. The string is not modified.
```
f(char*v){for(;*v;++v)putchar(*v),isalpha(*v)?putchar(*v-32+64*!islower(*v)):0;}
```
[Answer]
# sed, 30 bytes
29 bytes code + 1 byte parameter `-r`
```
s/([a-z])|([A-Z])/&\u\1\l\2/g
```
Usage:
```
echo -e 'bad\nNice\nT e S t\ns E t\n1!1!1st!\nn00b\n(e.g.)\nH3l|@!' |\
sed -r 's/([a-z])|([A-Z])/&\u\1\l\2/g'
```
[Answer]
# J, ~~31~~ 29 bytes
```
[:;]<@~."1@,.tolower,.toupper
```
## Explanation
```
[:;]<@~."1@,.tolower,.toupper  Input: s
                      toupper  Convert s to all uppercase
             tolower           Convert s to all lowercase
                    ,.         Join them as columns in a 2d array
   ]                           Identity function, get s
           ,.                  Prepend s as a column to the 2d array
      ~."1@                    Take the unique chars on each row
    <@                         Box them
[:;                            Unbox the list of boxes and join their contents and return
```
[Answer]
# Haskell, ~~121, 101, 85,~~ 82
```
import Data.Char
g n|isLower n=toUpper n|1<2=toLower n
(>>= \x->x:[g x|isAlpha x])
```
[Answer]
## Perl, 36 bytes (35 + `-n` flag)
```
s/[a-z]/$&.(ord$&<97?lc$&:uc$&)/ige
```
(`-p` tag needed)
(-2 bytes thanks to @Dom Hasting)
Short explanation:  
`ord` returns the numeric value of a char. `ord(any lower case) >= 97`, and `ord(any upper case) <= 90)`.
Run with :
```
perl -pe 's/[a-z]/$&.(ord$&<97?lc$&:uc$&)/ige'
```
[Answer]
# Ruby, ~~31+1=32~~ 30+1=31 bytes
With the `-p` flag, run
```
gsub(/(?<=(.))/){$1.swapcase!}
```
Takes advantage of the fact that `swapcase!` will return `nil` on anything but an ASCII letter, which translates to an empty string when returned out of the `gsub` block. @Jordan saved a byte by capturing the previous character in a look-behind.
[Answer]
# R, 191 187 ~~168~~ ~~156~~ ~~98~~ 99 bytes
99 bytes due to improvements fro [Giuseppe](https://codegolf.stackexchange.com/users/67312/giuseppe) and [MickyT](https://codegolf.stackexchange.com/users/31347/mickyt).
```
paste0(x<-unlist(strsplit(readline(),"")),gsub("[^A-Za-z]","",chartr("a-zA-Z","A-Za-z",x)),collapse="")
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 7 bytes
Code:
```
vyyš«Ù?
```
Explanation:
```
v       # For each in input.
 yyš    # Push y and y swapcased.
    «Ù  # Concatentate and uniquify.
      ? # Print without a newline.
```
Uses the **CP-1252** encoding. [Try it online!](http://05ab1e.tryitonline.net/#code=dnl5xaHCq8OZPw&input=TiBpIEMgZQ)
[Answer]
## Pyke, ~~8~~ 6 bytes
```
FDl4+}
```
[Try it here!](http://pyke.catbus.co.uk/?code=FDl4%2B%7D&input=%28e.g.%29)
[Answer]
# [V](https://github.com/DJMcMayhem/V), 21 bytes
[Try it online!](http://v.tryitonline.net/#code=w5MuL8Kww7IKw43DoS_CsMKwCsOObGd-bMOOSMOyZ0o&input=SDNsfEAh)
Too many bytes...
```
Ó./°ò
Íá/°°
Îlg~lÎHògJ
```
[Answer]
## Actually, 8 bytes
```
`;Öo╔`MΣ
```
[Try it online!](http://actually.tryitonline.net/#code=YDvDlm_ilZRgTc6j&input=IkgzbHxAISI)
Explanation:
```
`;Öo╔`MΣ
`;Öo╔`M   for each character in input:
 ;          duplicate the character
  Ö         swap case
   o        append to original character
    ╔       remove duplicated characters
       Σ  concatenate
```
[Answer]
# MATL, ~~11~~ 9 bytes
```
tYov"@uv!
```
[**Try it Online**](http://matl.tryitonline.net/#code=dFlvdiJAdXYh&input=J0gzbHxAISc)
**Explanation**
```
        % Implicitly grab input as string
t       % Duplicate the input
Yo      % Swap case of all characters
v       % Vertically concatenate the original and swap-cased versions
"       % For each column (letter in the original)
  @u    % Compute the unique values (without sorting)
  v!    % Vertically concatenate with the existing output and transpose
        % Implicit end of for loop and implicit display
```
[Answer]
## Common Lisp (Lispworks), 262 bytes
```
(defun f(s)(let((b""))(dotimes(i(length s))(if(lower-case-p(elt s i))(progn #1=(setf b(concatenate 'string b(string #2=(elt s i))))(setf b(concatenate 'string b(string(char-upcase #2#)))))(progn #1#(setf b(concatenate 'string b(string(char-downcase #2#)))))))b))
```
ungolfed:
```
(defun f (s)
  (let ((b ""))
    (dotimes (i (length s))
      (if (lower-case-p (elt s i))
          (progn
           #1=(setf b (concatenate 'string b (string #2=(elt s i))))
           (setf b (concatenate 'string b (string (char-upcase #2#)))))
        (progn
          #1#
          (setf b (concatenate 'string b (string (char-downcase #2#)))))))
    b))
```
Usage:
```
CL-USER 1 > (f "abc")
"aAbBcC"
CL-USER 2 > (f "bad")
"bBaAdD"
```
[Answer]
## Perl, ~~28~~ ~~22~~ 21 bytes (20 + `-p` flag)
```
s/[a-z]/$&.$&^$"/ige
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), ~~7~~ 6 bytes
Thanks to @recursive for a byte saved!
```
┤§ÆP♦■
```
[Run and debug it at staxlang.xyz!](https://staxlang.xyz/#c=c%3A~%5C%7Bum&i=%22bad%22%0A%0A%22Nice%22%0A%0A%22T+e+S+t%22%0A%0A%22s+E+t%22%0A%0A%221%211%211st%21%22%0A%0A%22n00b+%22+%0A++%0A%22%28e.g.%29%22%0A%0A%22H3l%7C%40%21%22%0A%0A%22123%22%0A&a=1&m=1) (link is to unpacked version)
### Unpacked (7 bytes):
```
c:~\{um
```
### Explanation:
```
c:~\{um
c          Copy the top element of the stack (the input, in this case).
 :~        Switch case of each letter in the copy.
   \       Zip. This produces an array of two-character strings.
    { m    Map a block over this array of two-character strings.
     u       Get all unique elements.
           Implicit concatenate and print.
```
[Answer]
## Python, 59 bytes
```
lambda s:''.join((x,x+x.swapcase())[x.isalpha()]for x in s)
```
Edited to fix repeating non-alphabetic characters
[Answer]
# Julia, 40 bytes
```
!s=[print(c,isalpha(c)?c$' ':"")for c=s]
```
[Try it online!](http://julia.tryitonline.net/#code=IXM9W3ByaW50KGMsaXNhbHBoYShjKT9jJCcgJzoiIilmb3IgYz1zXQoKZm9yIHMgaW4gKCJiYWQiLCAiTmljZSIsICJUIGUgUyB0IiwgInMgRSB0IiwgIjEhMSExc3QhIiwgIm4wMGIiLCAiKGUuZy4pIiwgIkgzbHxAISIpCiAgICBAcHJpbnRmKCIlLTExcyIscykKICAgICFzCiAgICBwcmludGxuKCkKZW5k&input=)
[Answer]
# PHP 4.1, 57 bytes
This code assumes access through a web server (Apache, for example), using the default configuration.
You can pass the string by sending the key `S` by any means (`POST`, `GET`, `COOKIE`, `SESSION`...).
```
<?for($i=0;$c=$S[$i++];)echo$c,ctype_alpha($c)?$c^' ':'';
```
[Answer]
# C#, ~~82~~ 71 bytes
```
s=>string.Concat(s.Select(c=>c+(char.IsLetter(c)?(char)(c^32)+"":"")));
```
C# lambda where the input and the output are `string`. [Try it online](https://dotnetfiddle.net/Gti6h7).
11 bytes thanks to @Lynn trick.
]