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
abstract class EnumConverter<T : Enum<T>, V>( | |
private val entries: EnumEntries<T>, | |
private val dumpValue: (T) -> V | |
) : AttributeConverter<T, V> { | |
override fun convertToDatabaseColumn(enumValue: T?): V? { | |
return enumValue?.let { dumpValue(it) } | |
} | |
override fun convertToEntityAttribute(dbValue: V?): T? { | |
return dbValue?.let { value -> |
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
/** | |
* Gets a set of duplicates in the given iterable. | |
*/ | |
fun <T> Iterable<T>.duplicates(): Set<T> = duplicatesBy { it } | |
/** | |
* Gets a set of duplicates in the given iterable using the specified selector. | |
*/ | |
fun <T, K> Iterable<T>.duplicatesBy(selector: (T) -> K): Set<K> = | |
groupingBy(selector).eachCount().filterValues { it > 1 }.keys.toSet() |
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
defmodule Observable do | |
@moduledoc """ | |
A module that provides creating an observible value that emits the values to | |
a stream. | |
""" | |
alias Observable.Server | |
defstruct [:producer, :consumer] |
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
import kotlinx.coroutines.flow.flow | |
inline fun <T> Flow<T>.dedupBy(crossinline predicate: suspend (T, T) -> Boolean): Flow<T> = | |
let { source -> | |
var prevValue: T? = null | |
flow { | |
source.collect { value -> | |
if (prevValue == null || !predicate(prevValue!!, value)) { | |
prevValue = value | |
emit(value) |
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
type AllowedFieldsWithType<TObj, TKey> = { | |
[K in keyof TObj]: TObj[K] extends TKey ? K : never; | |
}; | |
export type FieldsOfType<T, K> = AllowedFieldsWithType<T, K>[keyof T]; | |
// Usage Example: | |
// | |
// const obj = { | |
// foo: 'bar', |
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
/** | |
* Creates a deep clone of an object. | |
* | |
* Internally uses `structuredClone` when available and | |
* `JSON.parse(JSON.stringify(obj))` as fallback. | |
* | |
* @param obj - The object to be cloned. | |
* @return The deep clone of the object. | |
*/ | |
export default function cloneDeep<T>(value: T): T { |
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
import { RefObject, useCallback, useEffect, useState } from 'react'; | |
export interface ScrollToOptions { | |
x?: number; | |
y?: number; | |
behavior?: ScrollBehavior; | |
} | |
export interface UseScrollOptions { | |
disabled?: boolean; |
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
import { getContext, setContext } from "svelte"; | |
/** | |
* The context object. | |
*/ | |
export interface Context<T> { | |
get: () => T; | |
set: (ctx: T) => T; | |
} |
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
import findValue, { FindValueFilterMapper } from './findValue'; | |
describe('findValue(value, predicate)', () => { | |
const FILTER_MAPPER: FindValueFilterMapper<number, string> = (v) => { | |
if (v < 0) { | |
return [true, 'negative']; | |
} | |
if (v % 2 === 1) { | |
return [false, 'odd']; | |
} |
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
export default function eventually(callback, timeout = 2000, pollInterval = 50) { | |
return new Promise((resolve, reject) => { | |
let intervalTimer; | |
let lastError; | |
const timeoutTimer = setTimeout(() => { | |
if (!intervalTimer) return; | |
clearTimeout(intervalTimer); | |
reject(lastError || new Error('eventually timed out')); |
NewerOlder