-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gears: added package with set of gears for kotlin
- Loading branch information
Showing
5 changed files
with
93 additions
and
0 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,8 @@ | ||
## Unreleased | ||
|
||
### Changed | ||
|
||
- Create gears:kotlin | ||
added: | ||
- `Modifier.applyIf` - Applies the given block of modifications to the Modifier if the condition is true | ||
- `Modifier.applyChoice` - Chooses between two blocks of modifications based on a condition and returns the resulting Modifier |
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,45 @@ | ||
# compose-ktx <GitHub path="RedMadRobot/redmadrobot-android-ktx/tree/main/compose-ktx"/> | ||
[![Version](https://img.shields.io/maven-central/v/com.redmadrobot.extensions/compose-ktx?style=flat-square)][mavenCentral] | ||
[![License](https://img.shields.io/github/license/RedMadRobot/redmadrobot-android-ktx?style=flat-square)][license] | ||
|
||
--- | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
|
||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Contributing](#contributing) | ||
|
||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
||
A set of gears for kotlin. | ||
|
||
## Installation | ||
|
||
Add the dependency: | ||
```groovy | ||
repositories { | ||
mavenCentral() | ||
google() | ||
} | ||
dependencies { | ||
implementation("com.redmadrobot.gears:kotlin:<version>") | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
| Gear | Description | | ||
|:-----------------------|:---------------------------------------------------------------------------------------------| | ||
| `Modifier.applyIf` | Applies the given block of modifications to the T if the condition is true | | ||
| `Modifier.applyIfElse` | Chooses between two blocks of modifications based on a condition and returns the resulting T | | ||
|
||
## Contributing | ||
|
||
Merge requests are welcome. | ||
For major changes, please open an issue first to discuss what you would like to change. | ||
|
||
|
||
[mavenCentral]: https://search.maven.org/artifact/com.redmadrobot.extensions/compose-ktx | ||
[license]: ../LICENSE |
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,12 @@ | ||
plugins { | ||
id("com.redmadrobot.kotlin-library") | ||
convention.publishing | ||
convention.detekt | ||
} | ||
|
||
version = "1.9.23-0" | ||
description = "A set of gears for kotlin" | ||
|
||
dependencies { | ||
api(kotlin("stdlib")) | ||
} |
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,27 @@ | ||
package com.redmadrobot.gears.kotlin | ||
|
||
/** | ||
* Applies the given block of modifications to the T if the condition is true. | ||
* | ||
* @param condition condition to determine if the block should be applied. | ||
* @param block Lambda function that modifies the T. | ||
* @return Modified T based on the condition. | ||
*/ | ||
public inline fun <T> T.applyIf( | ||
condition: Boolean, | ||
block: T.() -> T, | ||
): T = applyIfElse(condition = condition, trueBlock = block, falseBlock = { this }) | ||
|
||
/** | ||
* Chooses between two blocks of modifications based on a condition and returns the resulting T. | ||
* | ||
* @param condition Boolean condition to determine which block to apply. | ||
* @param trueBlock Lambda function to modify the T if the condition is true. | ||
* @param falseBlock Lambda function to modify the T if the condition is false. | ||
* @return Modified T based on the condition. | ||
*/ | ||
public inline fun <T> T.applyIfElse( | ||
condition: Boolean, | ||
trueBlock: T.() -> T, | ||
falseBlock: T.() -> T, | ||
): T = if (condition) trueBlock() else falseBlock() |
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 |
---|---|---|
|
@@ -35,4 +35,5 @@ include( | |
":ktx:resources-ktx", | ||
":ktx:viewbinding-ktx", | ||
":gears:compose", | ||
":gears:kotlin", | ||
) |