How can I refactor out the required else clause?

后端 未结 6 439
春和景丽
春和景丽 2021-01-12 09:13

I have a C# method that looks a bit like this:

bool Eval() {
  // do some work
  if (conditionA) {
     // do some work
     if (conditionB) {
       // do s         


        
6条回答
  •  北海茫月
    2021-01-12 09:47

    Please don't be afraid to extract functions. This is key to controlling complex logic.

    let rec partA () =
      // do some work
      let aValue = makeA ()
      if conditionA 
      then partB aValue 
      else false
    and partB aValue =
      // do some work
      let bValue = makeB aValue
      if conditionB 
      then partC bValue
      else false
    and partC bValue =
      // do some work
      conditionC 
    

提交回复
热议问题