Update nightly.yml
Sugar for working and using Bool type in Swift.
To streamline writing and reading code so it will resemble the English language.
isTrue
Sugar for checking if Bool has value true. Streamlines conditionals statements by removing explicit checks with ==.
Bool
true
==
if canDrinkBeer.isTrue { ...
isFalse
Sugar for checking if Bool has value false. Streamlines conditionals statements by removing explicit checks with ==.
false
if canDrinkBeer.isFalse { ...
negated
New instance with negated value.
whenTrue
Operator for running a closure when self is true. Use this operator to create pipelines that will trigger actions.
canDrinkBeer .whenTrue { openBeer() } .whenFalse { closeBeer() }
whenFalse
Operator for running a closure when self is false. Use this operator to create pipelines that will trigger actions.
biTransform(yes:no:)
Transforms bool to some type of T. Use this in longer pipelines where sticking normal operators would break the flow:
T
manager .boolProperty .biTransform(yes: "was true", no: "was false") .count // working with String now
and
Sugar for &&. Writing more complex if statements sometimes is messy. With operators you can write them:
&&
if canDrinkBeer .and( isHealthy ) .and( hasMoney ) .or( isFriend ) { ...
or
Sugar for ||. Writing more complex if statements sometimes is messy. With operators you can write them:
||
toInt
Converts to Int. When true returns positive value and for false returns 0. Do not assume any particular integer value for true.
Int
0
init(fromInt:)
Creates Bool instance from Int. When value is 0 returns false and true for all other cases.
value
always
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 )
Library for handling predicates as types.
Working on a design and on documentation. You are more than welcome to take a look and play around with it.
This project is part of the 🐇🕳 Rabbit Hole Packages Collection
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
SweetBool
Sugar for working and using Bool type in Swift.
Why?
To streamline writing and reading code so it will resemble the English language.
Operators
isTrueSugar for checking if
Boolhas valuetrue. Streamlines conditionals statements by removing explicit checks with==.isFalseSugar for checking if
Boolhas valuefalse. Streamlines conditionals statements by removing explicit checks with==.negatedNew instance with negated value.
whenTrueOperator for running a closure when self is
true. Use this operator to create pipelines that will trigger actions.whenFalseOperator for running a closure when self is
false. Use this operator to create pipelines that will trigger actions.biTransform(yes:no:)Transforms bool to some type of
T. Use this in longer pipelines where sticking normal operators would break the flow:andSugar for
&&. Writing more complex if statements sometimes is messy. With operators you can write them:orSugar for
||. Writing more complex if statements sometimes is messy. With operators you can write them:toIntConverts to
Int. Whentruereturns positive value and forfalsereturns0. Do not assume any particular integer value fortrue.init(fromInt:)Creates
Boolinstance fromInt. Whenvalueis0returnsfalseandtruefor all other cases.Predicates
alwaysWhen you need a predicate that is always
trueor alwaysfalseyou can use a global function like so:SweetPredicate
Library for handling predicates as types.
WiP
Working on a design and on documentation. You are more than welcome to take a look and play around with it.
🐇🕳 Rabbit Hole
This project is part of the 🐇🕳 Rabbit Hole Packages Collection