What you're thinking of with the idea of "folding" the wings is the
swing-wing mechanism. The idea is to get both sides of an aerodynamic trade-off in one plane. If your wings stick out straight, you catch more air, which allows you to produce more lift at slower speeds and to make sharper turns, but increases drag and thus keeps your speed and fuel efficiency down. If they're swept back, you catch less air, which means you have less drag and can cut through the air more cleanly, so your fuel efficiency at any speed is higher and your top speed is higher, but you lose some maneuverability and can't generate as much lift at low speeds.
(Lift is upward pressure created by the plane's forward movement. More lift means you can carry more weight, or your stall speed, the speed below which you would just fall to the ground instead of flying, is lower.)
So normally, wings that stick straight out are on planes that won't be going very fast, or on planes that just need to carry lots of weight, while swept-back wings are on planes that need as much speed as they can get, or on planes that need high fuel efficiency for a given cruise speed. Swing-wings let you switch back and forth between the two options in flight. The main example of them is the American navy's F-14, a long-range interceptor/fighter. It would launch, land, dogfight, and do other low-speed or maneuvering-intensive functions such as reconnaisance and ground-target-bombing with its wings out, but cover the distance to and from a mission site with its wings back.
The closest thing to it in the civilian world is the Concorde-type passenger jet. Its wings didn't move, but its nose did. It needed to be long and pointy for supersonic flight, and its high drag when in the drooping position wasn't very important or useful for aerodynamics, so why didn't they just make it permanently pointing forward? Because then it would obstruct the pilots' view during launches and landings.
Since the F-14's decommissioning by the U.S. Navy last year, there are very few swing-wing planes left flying. It didn't catch on very widely because most planes don't need such a combination of speed, maneuverability, and low stall speed, or they could meet their needs with other more modern wing types, and the swing-wing's structural reinforcements, joints, and machinery just added more weight, complication, and expense.
In modern planes with similar performance requirements to the F-14 (in other words, fighter planes that have been designed since then), a single fixed shape is used, combining some traits of both the sticking-out wing and the swept-back wing. Essentialy, these days they all have a front edge that sweeps back fairly steeply and a back edge that either sticks straight out sideways or even sweeps forward... which means the "base" of the wing (where it attaches to the body of the plane) is now much longer in fighter planes than than in non-fighters and older designs. Also, tail fins on these planes now stick out farther back behind the jet exhaust openings than they have before, where they can apply more leverage and make sharper turns even in a very fast plane at high speeds.
I'm attaching a file that I happened to have made recently for another purpose. I wasn't into this stuff before but started learning it because of the American political issue over the F-22. I ran into comparisons among the F-22 and other planes (and the distinction between light fighters and heavy fighters), so I gathered the numbers for length and width, found some diagrams I could scale and turn into silhouettes, and made this thing so I could SEE the planes together beside each other.
These are all American jets that are designed to shoot at enemy targets: Air Force in the top row, Navy below. In each row, their noses are all lined up exactly, for size comparison.
Left to right, Air Force: A-10, F-15, F-16, F-22, F-35
Left to right, Navy: F-14, F-18A-D, F-18E-F, F-35 (aircraft carrier version)
The numbers they have for names, which you might notice increasing in each row from left to right, also correspond to the planes' ages; the A-10 is older than the fighters, and the fighters' numbers, which start at 14, are sequential.
The A-10 is the only "attack" plane here. Attack planes are for clobbering targets on the ground to support your side's infantry and cavalry in land battles against other infantry/cavalry. They have to fly slowly in order to stay on the scene for a decent length of time instead of just zipping by, and they expect to get hit so they're very heavy with armor and designed to keep flying even if parts of the wings and/or tail get perforated or even blown off. All of that means they need lots of lift. Notice that the A-10's wings just stick straight out and don't look sleek and swept and pointy like the fighters' wings; the A-10's aerodynamic design sacrifices efficiency and speed for lift and low stall speed.
Below it is the F-14, the only other plane on here with the old-school wing shape: mostly narrow and not very tapered because the base is narrow and the choices are whether to stick them out or sweep them back. It's shown in its spread-out mode, even though the wings are still slightly swept; in its swept mode, it would almost be just a black triangle in the image. It was designed in a time when wing shapes were always very similar and the only thing they changed for speed was to slant them back instead of sticking them out.
Next to the A-10 in the top row is the F-15, in which you can see a change in wing shapes for pretty much the first time in filght history. The base of the wing is elongated, taking up much more of the plane's length from front to back, and the angle between the front and back edges is steeper, essentially making the wing both swept back (along the front edge) and stuck out (along the back edge) at the same time without any need to move parts back and forth.
To the right of the 14 and 15 are the 16 (top row) and 18 (bottom row). These planes are what happened when the USA noticed that its fighters were getting big, heavy, and expensive, and decided to balance them with lighter, cheaper little brothers, although the second 18 in the picture shows a slightly enlarged ("mid-sized") version the Navy started getting when they found out they couldn't keep their 14s mouch longer. The 16 has the first wing with a back edge that isn't swept back at all, not even for part of its length like the 15, and the 18 has the first wing with a back edge that's actually swept forward.
But the most modern planes in the American armed forces (last two in top row and last one in bottom row) have moved beyond that to a serious forward sweep of the wings' back edges. Also notice how far back in the back their tail fins hang out now. This seems to give the best combination of lift, maneuverability, speed, and such with the least sacrificing of any one of them for another or getting other penalties like excessive stall speed. But even between them, you can still see a bit of a difference. Although they all have wings swept back in the front and forward in the back, it's the most drastic in the 22 (fourth in top row), which is the fastest of them all, while the 35s (at the right in both rows), have their wings swept just a bit less and sticking out just a bit more, and aren't as fast but get more maneuverability from their wings & fins. (The 22 might be about as maneuverable or even more, but I don't know, and if so, it's only because they can also pivot their engine exhausts instead of using flaps alone.) Also, as you can see in the two versions I've shown of the 35, the Navy asked for bigger wings and fins because they're a bit more interested in control at low speeds and the Air Force is a bit more interested in high speed.
So, although they've found a wing form that gives a better combination of performance traits than in the old days and rendered swing-wing systems unnecessary, they can still tweek the new modern wing shape a bit to emphasize one purpose or another. It's just that the modern wing type makes the performance trade-offs much smaller now instead of being such major sacrifices like they used to be with older wing shapes.