Let's say I designed a machine that can fold any type of clothing and hypothetically, this mechanical solution does not exist anywhere else. If that same mechanism was also applicable in say the pastry machine market, would I still be able to protect the design of that mechanism even though its kind of serving a different function?
Let me preface this by saying I am not a patent attorney. I do however have a fair number of patents. Assuming the mechanism is truly novel, at the very least, you should be able to obtain two different patents, one for clothes and another for pastry. Whether you could get a patent on a generic "folding mechanism" is more of a question. If you could get such a claim then it is the best of all worlds since you keep someone from using your mechanism on applications outside the fields of clothes and foods.
However patent strategy is complex and really needs the consultation of a qualified patent attorney or agent. I think that trying to do it yourself based only on information coming from the internet is more than likely to result in either a rejected application or weak patent(s). Remember, even if one of the patent attorneys here can't answer authoritatively on your actual invention because you can't disclose that publicly.