elite-se / elite-se.webpage

source code for the organisations main webpage
https://elite-se.xyz
MIT License
7 stars 0 forks source link

Feature/precondition decorator #17

Closed DominikHorn closed 4 years ago

DominikHorn commented 4 years ago

This decorator permits moving method preconditions into a designated spot, i.e., transforming

class Magician {
  doMagic(cardDeck) {
    if (cardDeck == null || cardDeck == undefined) {
      // Must have a card deck for trick
      return null;
    } 

    if (cardDeck.isShuffled()) {
      // Can not perform this trick if someone else shuffled the cards
      return null;
    }

   // Do magic
  }
}

into

class Magician {
  @Pre(cardDeck => !!cardDeck && !cardDeck.isShuffled())
  doMagic(cardDeck) {
    // Do magic
  }
}