Is it possible to shape magnetic fields? Is it possible to shape or focus magnetic fields like an optical lens does with light?

 A: To some extent, you can- but not in the same sense that light can be focused. Here's how:
If you give a magnetic field the choice between propagating through empty space or through a piece of iron, it will choose the iron. This means that if you have a magnet sitting alone by itself, the magnetic field lines emanate from one end, loop around, and re-enter the magnet at its opposite end. Then if you butt up a short piece of iron rod against one end of that magnet, the field lines pull into the piece of iron, follow it to its end, and then emanate into space, loop around, etc.
So: a piece of iron can be used to guide the field lines of a magnet to some point where you want them to emanate. Such a chunk of iron is called a pole piece and is used in electric motors, loudspeakers, microphones and the like to steer and concentrate the field of a magnet into that part of the device where the field needs to be.
But this effect is not like a lens focusing light, which is ruled by completely different physics.
A: Yes, you can shape field lines much like how you can shape light rays. But it's important to remember that a static magnetic field is not a wave, and therefore it does not reflect or refract.
A magnetic field in motion propagates as an electromagnetic wave, that is to say, light. So, the propagation front of a moving magnetic field, which is the part with wave nature, does all the usual wave things, like refracting and reflecting. However, the magnetic field that is left behind is not a wave.
Because a static magnetic field does not have wave nature, it does not refract or reflect or do other wave things.
The field lines of a static magnetic field can, however, be shaped in a way very similar to that of light.
In optics, lens effects are a result of the index of refraction $n$ of the lens differing from the index of refraction of free space (or air, which is similar, or whatever else is on the outside of the lens).
The analogous material property in magnetostatics is magnetic permeability, $\mu$ (mu), which determines how susceptible a material is to being magnetized. Where $\mu_0$ is the permeability of vacuum, materials with $\mu/\mu_0$ close to 1, like wood, aluminum, and concrete, do not become magnetized when they're close to a magnet, while materials with $\mu/mu_0>>1$, like iron, become strongly magnetized with polarity opposite the magnet (lining up north to south, the same way bar magnets would if you stuck them together). Rare materials, with $0<\mu/mu_0 < 1$, like superconductors, become magnetized but in the same direction as the magnet (lining up south to south, or north to north).
In wave refraction (optical lensing), waves are refracted according to
$sin(\theta_2)/sin(\theta_1) = n_1/n_2$
Analogously, magnetic field lines bend at an interface according to
$sin(\theta_2)/sin(\theta_1) = \mu_1/\mu_2$
Unlike a lens, however, a magnetizable material also changes the shape of the field lines outside of it. A magnetic material like iron will bend field lines towards itself (like a bar magnet lined up naturally in the magnetic field), while a diamagnetic material like a superconductor will diverge field lines away from itself (like a bar magnet held against its natural orientation in a magnetic field).

image source
