/*
   Copyright 2010 Aaron J. Radke

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
package cc.drx

final class DrxBoolean(val a:Boolean) extends AnyVal{
  def ?[A](yes: => A):Option[A]       = if(a) Some(yes) else None //TODO switch this to a question mark..
  def option[A](yes: => A):Option[A]  = ?(yes)

  def toStringOnOff = if(a) "on" else "off"

  2017-07-30("this notation is too magical, use bool.getOrElse(yesValue,noValue)..","v0.2.15") //TODO use a different name
  def apply[A](yes: => A, no: => A):A  = if(a) yes else no
  def getOrElse[A](yes: => A, no: => A):A  = if(a) yes else no
  2017-07-30("this notation is too magical, use the explcit bool.option{yesValue} instead","v0.2.15") //TODO use a different name
  def apply[A](yes: => A):Option[A] = ?(yes)

  def not             = !a   //toggle
  def and(b:Boolean)  = a && b  //both true
  def or(b:Boolean)   = a || b  //either are true
  def nand(b:Boolean) = !(a && b)  //none or one are true
  def xnor(b:Boolean) = a == b    //both are the same
  def nor(b:Boolean)  = !(a || b)   //only if a and b are false
  def bothFalse(b:Boolean) = this nor b //a nor b

  def xor(b:Boolean)       = a != b  //same as (a != b)
  def +(b:Boolean)         = a != b
  def toggle(b:Boolean)    = a != b
}