-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Elifarley Cruz
committed
Jan 2, 2020
1 parent
3b7bd28
commit 19db5ec
Showing
4 changed files
with
60 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package klib.base | ||
|
||
/** | ||
* Created by elifarley on 22/11/16. | ||
*/ | ||
|
||
inline fun Any?.nullIf(nullValue: Any) = this.takeUnless { this == nullValue } | ||
|
||
/** | ||
* Calls the specified function [block] with no argument and always returns `Unit`. | ||
*/ | ||
inline fun unit(block: () -> Any?) { | ||
block() | ||
} | ||
|
||
/** | ||
* Calls the specified function [block] with `this` value as its argument and always returns `Unit`. | ||
*/ | ||
inline fun <T> T.unit(block: (T) -> Any?) { | ||
block(this) | ||
} | ||
|
||
/** | ||
* Can be used to transform a `when` receiver into an expression, making it **exhaustive**. | ||
* @return `Unit` | ||
*/ | ||
val Any?.unit inline get() = Unit | ||
|
||
inline operator fun <T> Boolean?.rem(block: () -> T): T? = this?.let { if (this) block() else null } | ||
|
||
inline infix operator fun <A, B, C> ((A) -> B).rem(crossinline other: (B) -> C): (A) -> C = | ||
{ other(this(it)) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters