This file contains hidden or 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 const hasDefinedKey = | |
<K extends PropertyKey>(key: K) => | |
<T extends Partial<Record<K, unknown>>>( | |
obj: T, | |
): obj is T & Record<K, Exclude<T[K], undefined>> => | |
key in obj && obj[key] !== undefined; |
This file contains hidden or 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 Split< | |
V extends string, | |
S extends string, | |
> = V extends `${infer Head}${S}${infer Rest}` | |
? [Head, ...Split<Rest, S>] | |
: Array<V>; | |
const split = <V extends string, S extends string>( | |
value: V, | |
separator: S, |
This file contains hidden or 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 { Model } from '@effect/sql'; | |
import { PgClient } from '@effect/sql-pg'; | |
import { layer } from '@effect/vitest'; | |
import { | |
Array, | |
Config, | |
Effect, | |
Exit, | |
Fiber, | |
flow, |
This file contains hidden or 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 type { Schema } from '@effect/schema'; | |
import { AST } from '@effect/schema'; | |
import { effectTsResolver } from '@hookform/resolvers/effect-ts'; | |
import { Button } from '@inato/ui'; | |
import { Match, Option } from 'effect'; | |
import type { | |
FieldValues, | |
SubmitErrorHandler, | |
SubmitHandler, | |
} from 'react-hook-form'; |
This file contains hidden or 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 { ArrayFormatter, Schema } from '@effect/schema'; | |
import { Effect, Either, flow, Record } from 'effect'; | |
import { Suspense, use, useActionState } from 'react'; | |
const updateName = async (name: string) => { | |
await Effect.runPromise(Effect.sleep(2000)); | |
return name; | |
}; | |
type State<T> = |
This file contains hidden or 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
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | |
import { API, FileInfo, JSCodeshift } from 'jscodeshift'; | |
const transform = (fileInfo: FileInfo, api: API) => { | |
const j: JSCodeshift = api.jscodeshift; | |
const root = j(fileInfo.source); | |
const replaceFpTsFunctionImportByEffectImport = (name: string) => { | |
const imports = root.find(j.ImportDeclaration); | |
const getFpTsFunctionImport = (name: string) => |
This file contains hidden or 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 { HttpClient } from '@effect/platform'; | |
import { Schema } from '@effect/schema'; | |
import { Failure, utils } from '@inato/shared-kernel'; | |
import { Effect, Layer, flow } from 'effect'; | |
import { UrlShorteningService } from '~/application/services/UrlShorteningService'; | |
class Response extends Schema.Class<Response>('Response')({ | |
data: Schema.Struct({ tiny_url: utils.CustomSchemas.URL }), | |
}) { |
This file contains hidden or 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 { Effect, Queue, pipe } from 'effect'; | |
import type { LazyArg } from 'effect/Function'; | |
class PQueue { | |
private boundedQueue; | |
constructor({ concurrency }: { concurrency: number }) { | |
this.boundedQueue = Effect.runSync(Queue.bounded<any>(concurrency)); | |
} | |
private queueTask<T>(task: Effect.Effect<never, never, T>) { |
This file contains hidden or 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 { Context, Effect, pipe } from 'effect'; | |
import { either } from 'fp-ts'; | |
import { ReaderTaskEither } from 'fp-ts/ReaderTaskEither'; | |
import { TaskEither } from 'fp-ts/TaskEither'; | |
export const effectFromEither = either.matchW(Effect.fail, Effect.succeed); | |
export const effectFromTaskEither = <E, A>( | |
program: TaskEither<E, A>, | |
): Effect.Effect<never, E, A> => |
This file contains hidden or 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
const binomialCoefficient = (n: number, k: number): number => { | |
if (k < 0 || k > n) { | |
return 0; | |
} | |
if (k === 0 || k === n) { | |
return 1; | |
} | |
if (k === 1 || k === n - 1) { | |
return n; | |
} |
NewerOlder