I would like to accomplish this:
A variable named abc must be None, except if the result of complicated treatments is true. I wrote a beginning of and answer but it doesn't work:
def abc={
None
copie.getRoot().asInstanceOf[DefaultMutableTreeNode].children() foreach ({
site => <...more things after...>
}
In the <more things after> you can find the result e.g. Some(site)
But the compiler does not accept this order, I mean "None" followed by some conditions eventually finishing by Some(xxx). And if I put "None" after the conditions, the result will always be "None" of course, and it's not what is expected.
Can you tell me if it can work this way, and how? Or otherwise how can I proceed?
@Robin:you saw right : I thought like if was in java : the result should be either None or Some(xxx),but amazingly if I put "None" at the beginning of the block and after "None" the conditional statements, which EVENTIUALLY return Some(xxx), eclipse's compiler does not accept my code. so the first question could be : is this order (None followed by some conditionnal treatments returning eventually Some(xxx) right? example:
def abc():Option[DefaultMutableTreeNode]={
None
MyTree.getRoot().children() foreach{site=>
if (site.toBeImported()) Some(site)
else site.children() foreach {type=>
if (type.toBeImported()) Some(type)
}
}
}
here this function returns None, Some(site) if a site is "toBeImported" (if many are, the last one will be returned), or Some(type) if a type is "toBeImported" (again the last one). This is not what I have in my program but it summaries well the idea.