# How to construct a function with multiple conditions, that returns a list?

GROUPS:
 Hello guys, I started learning Mathematica quite recently and I'm amazed by the possibilities of this software! Despite my genuine enthusiasm, I recently encountered a barrier (probably like most of users at the beginning). To most of You my problem surely will be trivial, but it is quite a headache for me. The case is a bit complicated so I will simplify it, so that I can just get an Idea how to get started and then I can develop the code without bothering You too much. Here it is - I would like to write a function that would process a list, with let's say 3 elements, and also return a list with the same number of elements. I guess the beginning should look like this:function1[{a_,b_,c_}]:= The next step should be to check which elements of the input list are numbers - if a and b are numbers and c is string (for instance a letter) the function returns {a,b,a+b+1}, if b and c are numbers, the function returns {b+c-1,b,c} and if a and c are numbers, the function returns {a,2*(a+c),c}. If there are less than 2 numbers in the list, the function should return the original list. I know it seems easy, but I have still just a little knowledge about Mathematica language. I assume that I should use If[] and NumberQ but don't know how to put them together. Sorry I don't enclose any code, but all my efforts ended with error messages or a disaster. I also couldn't find any similar example in any of the tutorials or books I read. Thanks for Your help and every piece of advise You are ready to share!
5 years ago
5 Replies
 f[{a_?NumberQ, b_?NumberQ, c_String] = {a, b, a + b + 1}etc.
5 years ago
 Thanks for the answer Frank. Surely it works, but I would have to write three such functions and then apply all of them to my list, which would result in one "proper" output and two "original" lists as outputs of those two functions with unmatched patterns. Is there a way to do it as one function, which would generate only one "desired" outcome?