import { FileSystem } from "@effect/platform";
import { NodeContext } from "@effect/platform-node";
import { Brand, Effect, pipe } from "effect";
type FilePath = string & Brand.Brand<"FilePath">;
const FilePath = Brand.refined<FilePath>(
(fp) =>
pipe(
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
return yield* fs.exists(fp);
}),
Effect.orElseFail(() => false),
Effect.provide(NodeContext.layer),
Effect.runSync,
),
(fp) => Brand.error(`The provided path ${fp} doesn't exist`),
);
import { FileSystem } from "@effect/platform";
import { NodeContext } from "@effect/platform-node";
import { Brand, Effect, pipe } from "effect";
type FilePath = string & Brand.Brand<"FilePath">;
const FilePath = Brand.refined<FilePath>(
(fp) =>
pipe(
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
return yield* fs.exists(fp);
}),
Effect.orElseFail(() => false),
Effect.provide(NodeContext.layer),
Effect.runSync,
),
(fp) => Brand.error(`The provided path ${fp} doesn't exist`),
);