mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-10-09 01:10:29 +00:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
bb9669f8fd | |||
bdac715d48 | |||
acf4971298 | |||
249bc83a8c | |||
0fbb92f03f | |||
ca27cb3f82 | |||
3a5771a0cc | |||
527a2a91ac | |||
6763e5c4c6 | |||
06918d8310 | |||
89ccaa1b57 |
11
CHANGELOG.md
11
CHANGELOG.md
@@ -1,5 +1,16 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.8.6
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* `Either` extensions `onFirst` and `onSecond` now accept not `crossinline` callbacks
|
||||||
|
* All `joinTo` now accept not `crossinline` callbacks
|
||||||
|
|
||||||
|
## 0.8.5
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* `repeatOnFailure`
|
||||||
|
|
||||||
## 0.8.4
|
## 0.8.4
|
||||||
|
|
||||||
* `Ktor`:
|
* `Ktor`:
|
||||||
|
@@ -129,7 +129,7 @@ inline fun <T1, T2> Either.Companion.second(t2: T2): Either<T1, T2> = EitherSeco
|
|||||||
/**
|
/**
|
||||||
* Will call [block] in case when [Either.t1] of [this] is not null
|
* Will call [block] in case when [Either.t1] of [this] is not null
|
||||||
*/
|
*/
|
||||||
inline fun <T1, T2, E : Either<T1, T2>> E.onFirst(crossinline block: (T1) -> Unit): E {
|
inline fun <T1, T2, E : Either<T1, T2>> E.onFirst(block: (T1) -> Unit): E {
|
||||||
val t1 = t1
|
val t1 = t1
|
||||||
t1 ?.let(block)
|
t1 ?.let(block)
|
||||||
return this
|
return this
|
||||||
@@ -138,7 +138,7 @@ inline fun <T1, T2, E : Either<T1, T2>> E.onFirst(crossinline block: (T1) -> Uni
|
|||||||
/**
|
/**
|
||||||
* Will call [block] in case when [Either.t2] of [this] is not null
|
* Will call [block] in case when [Either.t2] of [this] is not null
|
||||||
*/
|
*/
|
||||||
inline fun <T1, T2, E : Either<T1, T2>> E.onSecond(crossinline block: (T2) -> Unit): E {
|
inline fun <T1, T2, E : Either<T1, T2>> E.onSecond(block: (T2) -> Unit): E {
|
||||||
val t2 = t2
|
val t2 = t2
|
||||||
t2 ?.let(block)
|
t2 ?.let(block)
|
||||||
return this
|
return this
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
package dev.inmo.micro_utils.common
|
package dev.inmo.micro_utils.common
|
||||||
|
|
||||||
inline fun <I, R> Iterable<I>.joinTo(
|
inline fun <I, R> Iterable<I>.joinTo(
|
||||||
crossinline separatorFun: (I) -> R?,
|
separatorFun: (I) -> R?,
|
||||||
prefix: R? = null,
|
prefix: R? = null,
|
||||||
postfix: R? = null,
|
postfix: R? = null,
|
||||||
crossinline transform: (I) -> R?
|
transform: (I) -> R?
|
||||||
): List<R> {
|
): List<R> {
|
||||||
val result = mutableListOf<R>()
|
val result = mutableListOf<R>()
|
||||||
val iterator = iterator()
|
val iterator = iterator()
|
||||||
@@ -29,11 +29,11 @@ inline fun <I, R> Iterable<I>.joinTo(
|
|||||||
separator: R? = null,
|
separator: R? = null,
|
||||||
prefix: R? = null,
|
prefix: R? = null,
|
||||||
postfix: R? = null,
|
postfix: R? = null,
|
||||||
crossinline transform: (I) -> R?
|
transform: (I) -> R?
|
||||||
): List<R> = joinTo({ separator }, prefix, postfix, transform)
|
): List<R> = joinTo({ separator }, prefix, postfix, transform)
|
||||||
|
|
||||||
inline fun <I> Iterable<I>.joinTo(
|
inline fun <I> Iterable<I>.joinTo(
|
||||||
crossinline separatorFun: (I) -> I?,
|
separatorFun: (I) -> I?,
|
||||||
prefix: I? = null,
|
prefix: I? = null,
|
||||||
postfix: I? = null
|
postfix: I? = null
|
||||||
): List<I> = joinTo<I, I>(separatorFun, prefix, postfix) { it }
|
): List<I> = joinTo<I, I>(separatorFun, prefix, postfix) { it }
|
||||||
@@ -45,15 +45,15 @@ inline fun <I> Iterable<I>.joinTo(
|
|||||||
): List<I> = joinTo<I>({ separator }, prefix, postfix)
|
): List<I> = joinTo<I>({ separator }, prefix, postfix)
|
||||||
|
|
||||||
inline fun <I, reified R> Array<I>.joinTo(
|
inline fun <I, reified R> Array<I>.joinTo(
|
||||||
crossinline separatorFun: (I) -> R?,
|
separatorFun: (I) -> R?,
|
||||||
prefix: R? = null,
|
prefix: R? = null,
|
||||||
postfix: R? = null,
|
postfix: R? = null,
|
||||||
crossinline transform: (I) -> R?
|
transform: (I) -> R?
|
||||||
): Array<R> = asIterable().joinTo(separatorFun, prefix, postfix, transform).toTypedArray()
|
): Array<R> = asIterable().joinTo(separatorFun, prefix, postfix, transform).toTypedArray()
|
||||||
|
|
||||||
inline fun <I, reified R> Array<I>.joinTo(
|
inline fun <I, reified R> Array<I>.joinTo(
|
||||||
separator: R? = null,
|
separator: R? = null,
|
||||||
prefix: R? = null,
|
prefix: R? = null,
|
||||||
postfix: R? = null,
|
postfix: R? = null,
|
||||||
crossinline transform: (I) -> R?
|
transform: (I) -> R?
|
||||||
): Array<R> = asIterable().joinTo(separator, prefix, postfix, transform).toTypedArray()
|
): Array<R> = asIterable().joinTo(separator, prefix, postfix, transform).toTypedArray()
|
||||||
|
@@ -0,0 +1,21 @@
|
|||||||
|
package dev.inmo.micro_utils.common
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the given [action] until getting of successful result specified number of [times].
|
||||||
|
*
|
||||||
|
* A zero-based index of current iteration is passed as a parameter to [action].
|
||||||
|
*/
|
||||||
|
inline fun <R> repeatOnFailure(
|
||||||
|
times: Int,
|
||||||
|
onEachFailure: (Throwable) -> Unit = {},
|
||||||
|
action: (Int) -> R
|
||||||
|
): Optional<R> {
|
||||||
|
repeat(times) {
|
||||||
|
runCatching {
|
||||||
|
action(it)
|
||||||
|
}.onFailure(onEachFailure).onSuccess {
|
||||||
|
return Optional.presented(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Optional.absent()
|
||||||
|
}
|
@@ -45,5 +45,5 @@ dokka_version=1.5.31
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.8.4
|
version=0.8.6
|
||||||
android_code_version=84
|
android_code_version=86
|
||||||
|
52
mime_types/mimes_generator/mime_generator.py
Normal file
52
mime_types/mimes_generator/mime_generator.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import pandas as pd
|
||||||
|
import itertools
|
||||||
|
|
||||||
|
def fix_name(category, raw_name):
|
||||||
|
splitted = raw_name.replace('-', '+').replace('.', '+').replace(',', '+').split('+')
|
||||||
|
out1 = ""
|
||||||
|
for s in splitted:
|
||||||
|
out1 += s.capitalize()
|
||||||
|
|
||||||
|
result = ""
|
||||||
|
if out1[0].isdigit():
|
||||||
|
result += category[0].capitalize()
|
||||||
|
result += out1
|
||||||
|
else:
|
||||||
|
result += out1
|
||||||
|
return result
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
df = pd.read_html(open('table.html', 'r'))
|
||||||
|
mimes = []
|
||||||
|
for row in df[0].iterrows():
|
||||||
|
mime = row[1][1]
|
||||||
|
mime_category = mime.split('/', 1)[0]
|
||||||
|
mime_name = mime.split('/', 1)[1]
|
||||||
|
mimes.append({
|
||||||
|
'mime_category': mime_category,
|
||||||
|
'mime_name': mime_name,
|
||||||
|
})
|
||||||
|
|
||||||
|
# codegen
|
||||||
|
|
||||||
|
mimes.sort(key=lambda x: x['mime_category'])
|
||||||
|
grouped = itertools.groupby(mimes, lambda x: x['mime_category'])
|
||||||
|
code = ''
|
||||||
|
code2 = 'internal val knownMimeTypes: Set<MimeType> = setOf(\n'
|
||||||
|
code2 += ' KnownMimeTypes.Any,\n'
|
||||||
|
for key, group in grouped:
|
||||||
|
group_name = key.capitalize()
|
||||||
|
code += '@Serializable(MimeTypeSerializer::class)\nsealed class %s(raw: String) : MimeType, KnownMimeTypes(raw) {\n' % group_name
|
||||||
|
code += ' @Serializable(MimeTypeSerializer::class)\n object Any: %s ("%s/*")\n' % (group_name, key)
|
||||||
|
for mime in group:
|
||||||
|
name = fix_name(mime['mime_category'], mime['mime_name'])
|
||||||
|
code += ' @Serializable(MimeTypeSerializer::class)\n object %s: %s ("%s/%s")\n' % (name, group_name, mime['mime_category'], mime['mime_name'])
|
||||||
|
code2 += ' KnownMimeTypes.%s.%s,\n' % (group_name, name)
|
||||||
|
code += '}\n\n'
|
||||||
|
code2 += ')\n'
|
||||||
|
with open('out1.txt', 'w') as file:
|
||||||
|
file.write(code)
|
||||||
|
with open('out2.txt', 'w') as file:
|
||||||
|
file.write(code2)
|
Reference in New Issue
Block a user