Sugar for working and using Bool type in Swift.
To streamline writing and reading code so it will resemble the English language.
Sugar for checking if Bool
has value true
. Streamlines conditionals statements by removing explicit checks with ==
.
if canDrinkBeer.isTrue {
...
Sugar for checking if Bool
has value false
. Streamlines conditionals statements by removing explicit checks with ==
.
if canDrinkBeer.isFalse {
...
New instance with negated value.
Operator for running a closure when self is true
. Use this operator to create pipelines that will trigger actions.
canDrinkBeer
.whenTrue { openBeer() }
.whenFalse { closeBeer() }
Operator for running a closure when self is false
. Use this operator to create pipelines that will trigger actions.
canDrinkBeer
.whenTrue { openBeer() }
.whenFalse { closeBeer() }
Transforms bool to some type of T
. Use this in longer pipelines where sticking normal operators would break the flow:
manager
.boolProperty
.biTransform(yes: "was true", no: "was false")
.count // working with String now
Sugar for &&
. Writing more complex if statements sometimes is messy. With operators you can write them:
if canDrinkBeer
.and( isHealthy )
.and( hasMoney )
.or( isFriend ) {
...
Sugar for ||
. Writing more complex if statements sometimes is messy. With operators you can write them:
if canDrinkBeer
.and( isHealthy )
.and( hasMoney )
.or( isFriend ) {
...
Converts to Int
. When true
returns positive value and for false
returns 0
. Do not assume any particular integer value for true
.
Creates Bool
instance from Int
. When value
is 0
returns false
and true
for all other cases.
When you need a predicate that is always true
or always false
you can use a global function like so:
func takesPredicate<A>(_ p: (A) -> Bool) {... }
// Before
takesPredicate( { _ in true } )
// now
takesPredicate( always(true) )
takesPredicate( true.always )
This project is part of the 🐇🕳 Rabbit Hole Packages Collection