(
impl: Omit<
FileSystem,
| typeof TypeId
| "exists"
| "readFileString"
| "stream"
| "sink"
| "writeFileString"
>
): FileSystemCreates a FileSystem implementation from a partial implementation.
When to use
Use to build a concrete FileSystem service from platform-specific core
operations while deriving the convenience methods that can be implemented
from them.
Details
This function takes a partial FileSystem implementation and automatically provides
default implementations for exists, readFileString, stream, sink, and
writeFileString methods based on the provided core methods.
export const const make: (
impl: Omit<
FileSystem,
| typeof TypeId
| "exists"
| "readFileString"
| "stream"
| "sink"
| "writeFileString"
>
) => FileSystem
Creates a FileSystem implementation from a partial implementation.
When to use
Use to build a concrete FileSystem service from platform-specific core
operations while deriving the convenience methods that can be implemented
from them.
Details
This function takes a partial FileSystem implementation and automatically provides
default implementations for exists, readFileString, stream, sink, and
writeFileString methods based on the provided core methods.
make = (
impl: Omit<
FileSystem,
| typeof TypeId
| "exists"
| "readFileString"
| "stream"
| "sink"
| "writeFileString"
>
impl: type Omit<T, K extends keyof any> = {
[P in Exclude<keyof T, K>]: T[P]
}
Construct a type with the properties of T except for those in type K.
Omit<FileSystem, typeof const TypeId: "~effect/platform/FileSystem"TypeId | "exists" | "readFileString" | "stream" | "sink" | "writeFileString">
): FileSystem =>
const FileSystem: Context.Service<
FileSystem,
FileSystem
>
const FileSystem: {
key: string;
Service: {
access: (path: string, options?: { readonly ok?: boolean | undefined; readonly readable?: boolean | undefined; readonly writable?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
copy: (fromPath: string, toPath: string, options?: { readonly overwrite?: boolean | undefined; readonly preserveTimestamps?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
copyFile: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
chmod: (path: string, mode: number) => Effect.Effect<void, PlatformError>;
chown: (path: string, uid: number, gid: number) => Effect.Effect<void, PlatformError>;
glob: (pattern: string, options?: { readonly root?: string | undefined; readonly exclude?: ReadonlyArray<string> | undefined }) => Effect.Effect<Array<string>, PlatformError>;
exists: (path: string) => Effect.Effect<boolean, PlatformError>;
link: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
makeDirectory: (path: string, options?: { readonly recursive?: boolean | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
makeTempDirectory: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined }) => Effect.Effect<string, PlatformError>;
makeTempDirectoryScoped: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined }) => Effect.Effect<string, PlatformError, Scope>;
makeTempFile: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined; readonly suffix?: string | undefined }) => Effect.Effect<string, PlatformError>;
makeTempFileScoped: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined; readonly suffix?: string | undefined }) => Effect.Effect<string, PlatformError, Scope>;
open: (path: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<File, PlatformError, Scope>;
readDirectory: (path: string, options?: { readonly recursive?: boolean | undefined }) => Effect.Effect<Array<string>, PlatformError>;
readFile: (path: string) => Effect.Effect<Uint8Array, PlatformError>;
readFileString: (path: string, encoding?: string) => Effect.Effect<string, PlatformError>;
readLink: (path: string) => Effect.Effect<string, PlatformError>;
realPath: (path: string) => Effect.Effect<string, PlatformError>;
remove: (path: string, options?: { readonly recursive?: boolean | undefined; readonly force?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
rename: (oldPath: string, newPath: string) => Effect.Effect<void, PlatformError>;
sink: (path: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Sink.Sink<void, Uint8Array, never, PlatformError>;
stat: (path: string) => Effect.Effect<File.Info, PlatformError>;
stream: (path: string, options?: { readonly bytesToRead?: SizeInput | undefined; readonly chunkSize?: SizeInput | undefined; readonly offset?: SizeInput | undefined }) => Stream.Stream<Uint8Array, PlatformError>;
symlink: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
truncate: (path: string, length?: SizeInput) => Effect.Effect<void, PlatformError>;
utimes: (path: string, atime: Date | number, mtime: Date | number) => Effect.Effect<void, PlatformError>;
watch: (path: string) => Stream.Stream<WatchEvent, PlatformError>;
writeFile: (path: string, data: Uint8Array, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
writeFileString: (path: string, data: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
};
of: (this: void, self: FileSystem) => FileSystem;
context: (self: FileSystem) => Context.Context<FileSystem>;
use: (f: (service: FileSystem) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, FileSystem | R>;
useSync: (f: (service: FileSystem) => A) => Effect.Effect<A, never, FileSystem>;
Identifier: Identifier;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
Core interface for file system operations in Effect.
Details
The FileSystem interface provides a comprehensive set of file and directory operations
that work cross-platform. All operations return Effect values that can be composed,
transformed, and executed safely with proper error handling.
Example (Accessing file system operations)
import { Console, Effect, FileSystem } from "effect"
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
// Basic file operations
const exists = yield* fs.exists("./config.json")
if (!exists) {
yield* fs.writeFileString("./config.json", "{\"env\": \"development\"}")
}
// Directory operations
yield* fs.makeDirectory("./logs", { recursive: true })
// File information
const stats = yield* fs.stat("./config.json")
yield* Console.log(`File size: ${stats.size} bytes`)
// Streaming operations
const content = yield* fs.readFileString("./config.json")
yield* Console.log("Config:", content)
})
Service tag for platform file-system operations.
When to use
Use to access or provide operations for files, directories, permissions,
streams, and sinks through the Effect context.
Details
This key is used to provide and access the FileSystem service in the Effect context.
Example (Accessing and providing FileSystem)
import { Effect, FileSystem } from "effect"
// Access the FileSystem service
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
const exists = yield* fs.exists("./data.txt")
if (exists) {
const content = yield* fs.readFileString("./data.txt")
yield* Effect.log("File content:", content)
}
})
// Provide a custom FileSystem implementation
declare const platformImpl: Omit<
FileSystem.FileSystem,
"exists" | "readFileString" | "stream" | "sink" | "writeFileString"
>
const customFs = FileSystem.make(platformImpl)
const withCustomFs = Effect.provideService(
program,
FileSystem.FileSystem,
customFs
)
FileSystem.Service<FileSystem, FileSystem>.of(this: void, self: FileSystem): FileSystemof({
...impl: Omit<
FileSystem,
| typeof TypeId
| "exists"
| "readFileString"
| "stream"
| "sink"
| "writeFileString"
>
impl,
[const TypeId: "~effect/platform/FileSystem"TypeId]: const TypeId: "~effect/platform/FileSystem"TypeId,
FileSystem.exists: (path: string) => Effect.Effect<boolean, PlatformError>Checks whether a path exists.
exists: (path: stringpath) =>
pipe<Effect.Effect<void, PlatformError, never>, Effect.Effect<boolean, PlatformError, never>, Effect.Effect<boolean, PlatformError, never>>(a: Effect.Effect<void, PlatformError, never>, ab: (a: Effect.Effect<void, PlatformError, never>) => Effect.Effect<boolean, PlatformError, never>, bc: (b: Effect.Effect<boolean, PlatformError, never>) => Effect.Effect<boolean, PlatformError, never>): Effect.Effect<...> (+19 overloads)Pipes the value of an expression through a left-to-right sequence of
functions.
When to use
Use when you need to compose data-last functions into readable
transformation pipelines instead of method-style chains.
Details
Takes an initial value, passes it to the first function, then passes each
result to the next function in order. The final function result is returned.
Gotchas
Each function passed after the initial value must accept a single argument,
because pipe calls each step with only the previous result.
Example (Piping values through functions)
In this example, 1 is passed to the first function, and each result becomes
the input for the next function.
import { pipe } from "effect"
const result = pipe(
1,
(n) => n + 1,
(n) => n * 2,
(n) => `result: ${n}`
)
console.log(result) // "result: 4"
Example (Chaining methods before conversion)
const numbers = [1, 2, 3, 4]
const double = (n: number) => n * 2
const greaterThanFour = (n: number) => n > 4
const result = numbers.map(double).filter(greaterThanFour)
console.log(result) // [6, 8]
Example (Rewriting method chains with pipe)
The same transformation can be written with data-last functions.
import { Array, pipe } from "effect"
const numbers = [1, 2, 3, 4]
const double = (n: number) => n * 2
const greaterThanFour = (n: number) => n > 4
const result = pipe(
numbers,
Array.map(double),
Array.filter(greaterThanFour)
)
console.log(result) // [6, 8]
Example (Chaining arithmetic operations)
import { pipe } from "effect"
// Define simple arithmetic operations
const increment = (x: number) => x + 1
const double = (x: number) => x * 2
const subtractTen = (x: number) => x - 10
// Sequentially apply these operations using `pipe`
const result = pipe(5, increment, double, subtractTen)
console.log(result)
// Output: 2
Example (Building a simple transformation pipeline)
import { pipe } from "effect"
// Simple transformation pipeline
const result = pipe(
5,
(x) => x * 2, // 10
(x) => x + 1, // 11
(x) => x.toString() // "11"
)
console.log(result) // "11"
pipe(
impl: Omit<
FileSystem,
| typeof TypeId
| "exists"
| "readFileString"
| "stream"
| "sink"
| "writeFileString"
>
impl.access: (
path: string,
options?: {
readonly ok?: boolean | undefined
readonly readable?: boolean | undefined
readonly writable?: boolean | undefined
}
) => Effect.Effect<void, PlatformError>
Checks whether a file can be accessed.
You can optionally specify the level of access to check for.
access(path: stringpath),
import EffectEffect.const as: {
<B>(value: B): <A, E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
value: B
): Effect<B, E, R>
}
as(true),
import EffectEffect.const catchTag: {
<
K extends
| Tags<E>
| Arr.NonEmptyReadonlyArray<Tags<E>>,
E,
A1,
E1,
R1,
A2 = unassigned,
E2 = never,
R2 = never
>(
k: K,
f: (
e: ExtractTag<
NoInfer<E>,
K extends Arr.NonEmptyReadonlyArray<string>
? K[number]
: K
>
) => Effect<A1, E1, R1>,
orElse?:
| ((
e: ExcludeTag<
E,
K extends Arr.NonEmptyReadonlyArray<string>
? K[number]
: K
>
) => Effect<A2, E2, R2>)
| undefined
): <A, R>(
self: Effect<A, E, R>
) => Effect<
A | A1 | Exclude<A2, unassigned>,
| E1
| E2
| (A2 extends unassigned
? ExcludeTag<
E,
K extends Arr.NonEmptyReadonlyArray<string>
? K[number]
: K
>
: never),
R | R1 | R2
>
<
A,
E,
R,
K extends
| Tags<E>
| Arr.NonEmptyReadonlyArray<Tags<E>>,
R1,
E1,
A1,
A2 = unassigned,
E2 = never,
R2 = never
>(
self: Effect<A, E, R>,
k: K,
f: (
e: ExtractTag<
E,
K extends Arr.NonEmptyReadonlyArray<string>
? K[number]
: K
>
) => Effect<A1, E1, R1>,
orElse?:
| ((
e: ExcludeTag<
E,
K extends Arr.NonEmptyReadonlyArray<string>
? K[number]
: K
>
) => Effect<A2, E2, R2>)
| undefined
): Effect<
A | A1 | Exclude<A2, unassigned>,
| E1
| E2
| (A2 extends unassigned
? ExcludeTag<
E,
K extends Arr.NonEmptyReadonlyArray<string>
? K[number]
: K
>
: never),
R | R1 | R2
>
}
catchTag(
"PlatformError",
(e: PlatformError(parameter) e: {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: BadArgument | SystemError;
}
e) => e: PlatformError(parameter) e: {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: BadArgument | SystemError;
}
e.reason: BadArgument | SystemErrorreason._tag: SystemErrorTag | "BadArgument"_tag === "NotFound" ? import EffectEffect.const succeed: <A>(value: A) => Effect<A>Creates an Effect that always succeeds with a given value.
When to use
Use when an effect should complete successfully with a specific value without any errors
or external dependencies.
Example (Creating a successful effect)
import { Effect } from "effect"
// Creating an effect that represents a successful scenario
//
// ┌─── Effect<number, never, never>
// ▼
const success = Effect.succeed(42)
succeed(false) : import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(e: PlatformError(parameter) e: {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: BadArgument | SystemError;
}
e)
)
),
FileSystem.readFileString: (path: string, encoding?: string) => Effect.Effect<string, PlatformError>Read the contents of a file.
readFileString: (path: stringpath, encoding: string | undefinedencoding) =>
import EffectEffect.const flatMap: {
<A, B, E1, R1>(
f: (a: A) => Effect<B, E1, R1>
): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E1 | E, R1 | R>
<A, E, R, B, E1, R1>(
self: Effect<A, E, R>,
f: (a: A) => Effect<B, E1, R1>
): Effect<B, E | E1, R | R1>
}
flatMap(impl: Omit<
FileSystem,
| typeof TypeId
| "exists"
| "readFileString"
| "stream"
| "sink"
| "writeFileString"
>
impl.readFile: (
path: string
) => Effect.Effect<Uint8Array, PlatformError>
Read the contents of a file.
readFile(path: stringpath), (_: Uint8Array<ArrayBufferLike>_) =>
import EffectEffect.try<A, E = Cause.UnknownError>(options: { readonly try: LazyArg<A>; readonly catch: (error: unknown) => E } | LazyArg<A>): Effect<A, E>Creates an Effect from a synchronous computation that may throw, mapping
thrown values into the error channel.
When to use
Use when you need to perform synchronous operations that might throw, such
as parsing JSON, and want thrown exceptions captured as Effect errors.
Details
The thunk is evaluated when the effect runs. If it returns normally, the
returned value becomes the success value. If it throws, the thrown value is
mapped into the error channel.
Passing the thunk directly maps failures to
Cause.UnknownError
.
Passing { try, catch } uses catch to map failures to an error of type
E.
Gotchas
If catch throws while mapping the error, that thrown value is treated as
a defect. Return the error value you want in the error channel instead of
throwing it.
Example (Parsing JSON)
import { Effect } from "effect"
const parseJSON = (input: string) =>
Effect.try(() => JSON.parse(input))
// Success case
Effect.runPromise(parseJSON("{\"name\": \"Alice\"}")).then(console.log)
// Output: { name: "Alice" }
// Failure case maps the thrown value to UnknownError
Effect.runPromiseExit(parseJSON("invalid json")).then(console.log)
Example (Mapping exceptions to a tagged error)
import { Data, Effect } from "effect"
class JsonParsingError extends Data.TaggedError("JsonParsingError")<{ readonly cause: unknown }> {}
const parseJSON = (input: string) =>
Effect.try({
try: () => JSON.parse(input),
catch: (cause) => new JsonParsingError({ cause })
})
Effect.runPromiseExit(parseJSON("invalid json")).then(console.log)
// Output: Exit.failure with custom Error message
try({
try: LazyArg<string>try: () => new var TextDecoder: new (
label?: string,
options?: TextDecoderOptions
) => TextDecoder
The TextDecoder interface represents a decoder for a specific text encoding, such as UTF-8, ISO-8859-2, KOI8-R, GBK, etc.
TextDecoder(encoding: string | undefinedencoding).TextDecoder.decode(input?: AllowSharedBufferSource, options?: TextDecodeOptions): stringThe TextDecoder.decode() method returns a string containing text decoded from the buffer passed as a parameter.
decode(_: Uint8Array<ArrayBufferLike>_),
catch: (error: unknown) => PlatformErrorcatch: (cause: unknowncause) =>
function badArgument(options: { readonly module: string; readonly method: string; readonly description?: string | undefined; readonly cause?: unknown }): PlatformErrorCreates a PlatformError whose reason is a BadArgument.
When to use
Use to report a platform API rejecting caller input before performing the
underlying operation.
badArgument({
module: stringmodule: "FileSystem",
method: stringmethod: "readFileString",
description?: string | undefineddescription: "invalid encoding",
cause?: unknowncause
})
})),
FileSystem.stream: (path: string, options: { readonly bytesToRead?: SizeInput | undefined; readonly chunkSize?: SizeInput | undefined; readonly offset?: SizeInput | undefined } | undefined) => Stream.Stream<Uint8Array<ArrayBufferLike>, PlatformError, never>Create a readable Stream for the specified path.
Details
Changing the bufferSize option will change the internal buffer size of
the stream. It defaults to 4.
The chunkSize option will change the size of the chunks emitted by the
stream. It defaults to 64kb.
Changing offset and bytesToRead will change the offset and the number
of bytes to read from the file.
stream: import EffectEffect.const fnUntraced: <Effect.Effect<File, PlatformError, Scope> | Effect.Effect<void, never, never>, Stream.Stream<Uint8Array<ArrayBufferLike>, PlatformError, never>, [path: string, options: {
readonly bytesToRead?: SizeInput | undefined;
readonly chunkSize?: SizeInput | undefined;
readonly offset?: SizeInput | undefined;
} | undefined], Stream.Stream<Uint8Array<ArrayBufferLike>, PlatformError, never>>(body: (this: unassigned, path: string, options: {
readonly bytesToRead?: SizeInput | undefined;
readonly chunkSize?: SizeInput | undefined;
readonly offset?: SizeInput | undefined;
} | undefined) => Generator<...>, a: (_: Effect.Effect<...>, path: string, options: {
readonly bytesToRead?: SizeInput | undefined;
readonly chunkSize?: SizeInput | undefined;
readonly offset?: SizeInput | undefined;
} | undefined) => Stream.Stream<...>) => (path: string, options: {
readonly bytesToRead?: SizeInput | undefined;
readonly chunkSize?: SizeInput | undefined;
readonly offset?: SizeInput | undefined;
} | undefined) => Stream.Stream<...> (+41 overloads)
fnUntraced(function*(path: stringpath, options: | {
readonly bytesToRead?: SizeInput | undefined
readonly chunkSize?: SizeInput | undefined
readonly offset?: SizeInput | undefined
}
| undefined
options) {
const const file: Fileconst file: {
fd: File.Descriptor;
stat: Effect.Effect<File.Info, PlatformError>;
seek: (offset: SizeInput, from: SeekMode) => Effect.Effect<void>;
sync: Effect.Effect<void, PlatformError>;
read: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError>;
readAlloc: (size: SizeInput) => Effect.Effect<Option.Option<Uint8Array>, PlatformError>;
truncate: (length?: SizeInput) => Effect.Effect<void, PlatformError>;
write: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError>;
writeAll: (buffer: Uint8Array) => Effect.Effect<void, PlatformError>;
}
file = yield* impl: Omit<
FileSystem,
| typeof TypeId
| "exists"
| "readFileString"
| "stream"
| "sink"
| "writeFileString"
>
impl.open: (
path: string,
options?: {
readonly flag?: OpenFlag | undefined
readonly mode?: number | undefined
}
) => Effect.Effect<File, PlatformError, Scope>
Open a file at path with the specified options.
Details
The file handle will be automatically closed when the scope is closed.
open(path: stringpath, { flag?: OpenFlag | undefinedflag: "r" })
if (options: | {
readonly bytesToRead?: SizeInput | undefined
readonly chunkSize?: SizeInput | undefined
readonly offset?: SizeInput | undefined
}
| undefined
options?.offset?: SizeInput | undefinedoffset) {
yield* const file: Fileconst file: {
fd: File.Descriptor;
stat: Effect.Effect<File.Info, PlatformError>;
seek: (offset: SizeInput, from: SeekMode) => Effect.Effect<void>;
sync: Effect.Effect<void, PlatformError>;
read: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError>;
readAlloc: (size: SizeInput) => Effect.Effect<Option.Option<Uint8Array>, PlatformError>;
truncate: (length?: SizeInput) => Effect.Effect<void, PlatformError>;
write: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError>;
writeAll: (buffer: Uint8Array) => Effect.Effect<void, PlatformError>;
}
file.File.seek: (offset: SizeInput, from: SeekMode) => Effect.Effect<void>seek(options: {
readonly bytesToRead?: SizeInput | undefined
readonly chunkSize?: SizeInput | undefined
readonly offset?: SizeInput | undefined
}
options.offset?: SizeInput | undefinedoffset, "start")
}
const const bytesToRead: Size | undefinedbytesToRead = options: | {
readonly bytesToRead?: SizeInput | undefined
readonly chunkSize?: SizeInput | undefined
readonly offset?: SizeInput | undefined
}
| undefined
options?.bytesToRead?: SizeInput | undefinedbytesToRead !== var undefinedundefined ? const Size: (bytes: SizeInput) => SizeCreates a Size from various numeric input types.
Details
Converts numbers, bigints, or existing Size values into a properly
branded Size type. This function handles the conversion and ensures
type safety for file size operations.
Example (Converting size inputs)
import { Effect, FileSystem } from "effect"
// From number
const size1 = FileSystem.Size(1024)
console.log(typeof size1) // "bigint"
// From bigint
const size2 = FileSystem.Size(BigInt(2048))
// From existing Size (identity)
const size3 = FileSystem.Size(size1)
// Use in file operations
const readChunk = (path: string, chunkSize: number) =>
Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
return fs.stream(path, {
chunkSize: FileSystem.Size(chunkSize)
})
})
Size(options: {
readonly bytesToRead?: SizeInput | undefined
readonly chunkSize?: SizeInput | undefined
readonly offset?: SizeInput | undefined
}
options.bytesToRead?: SizeInput | undefinedbytesToRead) : var undefinedundefined
let let totalBytesRead: biginttotalBytesRead = var BigInt: BigIntConstructor
;(value: bigint | boolean | number | string) =>
bigint
BigInt(0)
const const chunkSize: SizechunkSize = const Size: (bytes: SizeInput) => SizeCreates a Size from various numeric input types.
Details
Converts numbers, bigints, or existing Size values into a properly
branded Size type. This function handles the conversion and ensures
type safety for file size operations.
Example (Converting size inputs)
import { Effect, FileSystem } from "effect"
// From number
const size1 = FileSystem.Size(1024)
console.log(typeof size1) // "bigint"
// From bigint
const size2 = FileSystem.Size(BigInt(2048))
// From existing Size (identity)
const size3 = FileSystem.Size(size1)
// Use in file operations
const readChunk = (path: string, chunkSize: number) =>
Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
return fs.stream(path, {
chunkSize: FileSystem.Size(chunkSize)
})
})
Size(options: | {
readonly bytesToRead?: SizeInput | undefined
readonly chunkSize?: SizeInput | undefined
readonly offset?: SizeInput | undefined
}
| undefined
options?.chunkSize?: SizeInput | undefinedchunkSize ?? 64 * 1024)
const const readChunk: Effect.Effect<
Option.Option<Uint8Array<ArrayBufferLike>>,
PlatformError,
never
>
const readChunk: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
readChunk = const file: Fileconst file: {
fd: File.Descriptor;
stat: Effect.Effect<File.Info, PlatformError>;
seek: (offset: SizeInput, from: SeekMode) => Effect.Effect<void>;
sync: Effect.Effect<void, PlatformError>;
read: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError>;
readAlloc: (size: SizeInput) => Effect.Effect<Option.Option<Uint8Array>, PlatformError>;
truncate: (length?: SizeInput) => Effect.Effect<void, PlatformError>;
write: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError>;
writeAll: (buffer: Uint8Array) => Effect.Effect<void, PlatformError>;
}
file.File.readAlloc: (size: SizeInput) => Effect.Effect<Option.Option<Uint8Array>, PlatformError>readAlloc(const chunkSize: SizechunkSize)
return import StreamStream.const fromPull: <A, E, R, EX, RX>(
pull: Effect.Effect<
Pull.Pull<
Arr.NonEmptyReadonlyArray<A>,
E,
void,
R
>,
EX,
RX
>
) => Stream<A, Pull.ExcludeDone<E> | EX, R | RX>
Creates a stream from a pull effect, such as one produced by Stream.toPull.
Details
A pull effect yields chunks on demand and completes when the upstream stream ends.
See Stream.toPull for a matching producer.
Example (Creating a stream from a pull effect)
import { Console, Effect, Stream } from "effect"
const program = Effect.scoped(
Effect.gen(function*() {
const source = Stream.make(1, 2, 3)
const pull = yield* Stream.toPull(source)
const stream = Stream.fromPull(Effect.succeed(pull))
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
})
)
Effect.runPromise(program)
// Output: [1, 2, 3]
fromPull(import EffectEffect.const succeed: <A>(value: A) => Effect<A>Creates an Effect that always succeeds with a given value.
When to use
Use when an effect should complete successfully with a specific value without any errors
or external dependencies.
Example (Creating a successful effect)
import { Effect } from "effect"
// Creating an effect that represents a successful scenario
//
// ┌─── Effect<number, never, never>
// ▼
const success = Effect.succeed(42)
succeed(
import EffectEffect.const flatMap: {
<A, B, E1, R1>(
f: (a: A) => Effect<B, E1, R1>
): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E1 | E, R1 | R>
<A, E, R, B, E1, R1>(
self: Effect<A, E, R>,
f: (a: A) => Effect<B, E1, R1>
): Effect<B, E | E1, R | R1>
}
flatMap(
import EffectEffect.const suspend: <A, E, R>(
effect: LazyArg<Effect<A, E, R>>
) => Effect<A, E, R>
Creates an Effect lazily, delaying construction until it is needed.
When to use
Use when you need to defer the evaluation of an effect until it is required.
Details
suspend takes a thunk that represents an effect and delays creating it
until the suspended effect is evaluated. This is useful for optimizing
expensive computations, managing circular dependencies such as recursive
functions, and helping TypeScript unify return types when branches construct
different effects. Any side effects or scoped captures inside the thunk are
re-executed on each invocation.
Example (Lazily evaluating side effects)
import { Effect } from "effect"
let i = 0
const bad = Effect.succeed(i++)
const good = Effect.suspend(() => Effect.succeed(i++))
console.log(Effect.runSync(bad)) // Output: 0
console.log(Effect.runSync(bad)) // Output: 0
console.log(Effect.runSync(good)) // Output: 1
console.log(Effect.runSync(good)) // Output: 2
Example (Suspending recursive Fibonacci evaluation)
import { Effect } from "effect"
const blowsUp = (n: number): Effect.Effect<number> =>
n < 2
? Effect.succeed(1)
: Effect.zipWith(blowsUp(n - 1), blowsUp(n - 2), (a, b) => a + b)
// console.log(Effect.runSync(blowsUp(32)))
// crash: JavaScript heap out of memory
const allGood = (n: number): Effect.Effect<number> =>
n < 2
? Effect.succeed(1)
: Effect.zipWith(
Effect.suspend(() => allGood(n - 1)),
Effect.suspend(() => allGood(n - 2)),
(a, b) => a + b
)
console.log(Effect.runSync(allGood(32)))
// Output: 3524578
Example (Helping TypeScript infer recursive effect types)
import { Effect } from "effect"
// Without suspend, TypeScript may struggle with type inference.
// Inferred type:
// (a: number, b: number) =>
// Effect<never, Error, never> | Effect<number, never, never>
const withoutSuspend = (a: number, b: number) =>
b === 0
? Effect.fail(new Error("Cannot divide by zero"))
: Effect.succeed(a / b)
// Using suspend to unify return types.
// Inferred type:
// (a: number, b: number) => Effect<number, Error, never>
const withSuspend = (a: number, b: number) =>
Effect.suspend(() =>
b === 0
? Effect.fail(new Error("Cannot divide by zero"))
: Effect.succeed(a / b)
)
suspend((): import PullPull.interface Pull<out A, out E = never, out Done = void, out R = never>An effectful pull step that either produces a value, fails with E, or
signals completion with Cause.Done<Done>.
When to use
Use to model one low-level pull step when a consumer repeatedly evaluates an
effect that may emit a value, fail normally, or signal normal completion
through Cause.Done.
Details
Pull represents completion in the error channel so low-level stream
consumers can distinguish ordinary failures from end-of-input and carry a
leftover value when needed.
Pull<import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the
requested number of bytes could not be allocated an exception is raised.
Uint8Array>, class PlatformErrorclass PlatformError {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: BadArgument | SystemError;
}
Tagged error used by platform APIs to report either invalid arguments or
system-level failures.
When to use
Use as the shared error type for platform APIs that expose invalid arguments
and host or operating-system failures through a single Effect error
channel.
Details
The reason field contains the underlying BadArgument or SystemError.
When that reason has a cause, the cause is preserved on the wrapper.
PlatformError> => {
if (const bytesToRead: Size | undefinedbytesToRead !== var undefinedundefined && const bytesToRead: SizebytesToRead <= let totalBytesRead: biginttotalBytesRead) {
return import CauseCause.const done: <A = void>(
value?: A
) => Effect.Effect<never, Done<A>>
Creates an Effect that fails with a Done error. Shorthand for
Effect.fail(Cause.Done(value)).
When to use
Use when you model stream or queue completion through the error channel.
Example (Failing with Done)
import { Cause, Effect } from "effect"
const program = Cause.done("finished")
Effect.runPromiseExit(program).then((exit) => {
console.log(exit._tag) // "Failure"
})
done()
}
return const bytesToRead: Size | undefinedbytesToRead !== var undefinedundefined && (const bytesToRead: SizebytesToRead - let totalBytesRead: biginttotalBytesRead) < const chunkSize: SizechunkSize
? const file: Fileconst file: {
fd: File.Descriptor;
stat: Effect.Effect<File.Info, PlatformError>;
seek: (offset: SizeInput, from: SeekMode) => Effect.Effect<void>;
sync: Effect.Effect<void, PlatformError>;
read: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError>;
readAlloc: (size: SizeInput) => Effect.Effect<Option.Option<Uint8Array>, PlatformError>;
truncate: (length?: SizeInput) => Effect.Effect<void, PlatformError>;
write: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError>;
writeAll: (buffer: Uint8Array) => Effect.Effect<void, PlatformError>;
}
file.File.readAlloc: (size: SizeInput) => Effect.Effect<Option.Option<Uint8Array>, PlatformError>readAlloc(const bytesToRead: SizebytesToRead - let totalBytesRead: biginttotalBytesRead)
: const readChunk: Effect.Effect<
Option.Option<Uint8Array<ArrayBufferLike>>,
PlatformError,
never
>
const readChunk: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
readChunk
}),
import OptionOption.const match: {
<B, A, C = B>(options: {
readonly onNone: LazyArg<B>
readonly onSome: (a: A) => C
}): (self: Option<A>) => B | C
<A, B, C = B>(
self: Option<A>,
options: {
readonly onNone: LazyArg<B>
readonly onSome: (a: A) => C
}
): B | C
}
match({
onNone: LazyArg<
Effect.Effect<never, Cause.Done<void>, never>
>
onNone: () => import CauseCause.const done: <A = void>(
value?: A
) => Effect.Effect<never, Done<A>>
Creates an Effect that fails with a Done error. Shorthand for
Effect.fail(Cause.Done(value)).
When to use
Use when you model stream or queue completion through the error channel.
Example (Failing with Done)
import { Cause, Effect } from "effect"
const program = Cause.done("finished")
Effect.runPromiseExit(program).then((exit) => {
console.log(exit._tag) // "Failure"
})
done(),
onSome: (
a: Uint8Array<ArrayBufferLike>
) => Effect.Effect<
[
Uint8Array<ArrayBufferLike>,
...Uint8Array<ArrayBufferLike>[]
],
never,
never
>
onSome: (buf: Uint8Array<ArrayBufferLike>buf) => {
let totalBytesRead: biginttotalBytesRead += var BigInt: BigIntConstructor
;(value: bigint | boolean | number | string) =>
bigint
BigInt(buf: Uint8Array<ArrayBufferLike>buf.Uint8Array<ArrayBufferLike>.length: numberThe length of the array.
length)
return import EffectEffect.const succeed: <A>(value: A) => Effect<A>Creates an Effect that always succeeds with a given value.
When to use
Use when an effect should complete successfully with a specific value without any errors
or external dependencies.
Example (Creating a successful effect)
import { Effect } from "effect"
// Creating an effect that represents a successful scenario
//
// ┌─── Effect<number, never, never>
// ▼
const success = Effect.succeed(42)
succeed(import ArrArr.const of: <A>(a: A) => NonEmptyArray<A>Wraps a single value in a NonEmptyArray.
Example (Creating a single-element array)
import { Array } from "effect"
console.log(Array.of(1)) // [1]
of(buf: Uint8Array<ArrayBufferLike>buf))
}
})
)
))
}, import StreamStream.const unwrap: <A, E2, R2, E, R>(
effect: Effect.Effect<Stream<A, E2, R2>, E, R>
) => Stream<
A,
E | E2,
R2 | Exclude<R, Scope.Scope>
>
Creates a stream produced from an Effect.
Example (Unwrapping a stream effect)
import { Console, Effect, Stream } from "effect"
const effect = Effect.succeed(Stream.make(1, 2, 3))
const stream = Stream.unwrap(effect)
const program = Effect.gen(function*() {
const chunk = yield* Stream.runCollect(stream)
yield* Console.log(chunk)
})
// [1, 2, 3]
unwrap),
FileSystem.sink: (path: string, options: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined } | undefined) => Sink.Sink<void, Uint8Array<ArrayBufferLike>, never, PlatformError, never>Create a writable Sink for the specified path.
sink: (path: stringpath, options: | {
readonly flag?: OpenFlag | undefined
readonly mode?: number | undefined
}
| undefined
options) =>
pipe<Effect.Effect<File, PlatformError, Scope>, Effect.Effect<Sink.Sink<void, Uint8Array<ArrayBufferLike>, never, PlatformError, never>, PlatformError, Scope>, Sink.Sink<void, Uint8Array<ArrayBufferLike>, never, PlatformError, never>>(a: Effect.Effect<File, PlatformError, Scope>, ab: (a: Effect.Effect<File, PlatformError, Scope>) => Effect.Effect<...>, bc: (b: Effect.Effect<...>) => Sink.Sink<...>): Sink.Sink<...> (+19 overloads)Pipes the value of an expression through a left-to-right sequence of
functions.
When to use
Use when you need to compose data-last functions into readable
transformation pipelines instead of method-style chains.
Details
Takes an initial value, passes it to the first function, then passes each
result to the next function in order. The final function result is returned.
Gotchas
Each function passed after the initial value must accept a single argument,
because pipe calls each step with only the previous result.
Example (Piping values through functions)
In this example, 1 is passed to the first function, and each result becomes
the input for the next function.
import { pipe } from "effect"
const result = pipe(
1,
(n) => n + 1,
(n) => n * 2,
(n) => `result: ${n}`
)
console.log(result) // "result: 4"
Example (Chaining methods before conversion)
const numbers = [1, 2, 3, 4]
const double = (n: number) => n * 2
const greaterThanFour = (n: number) => n > 4
const result = numbers.map(double).filter(greaterThanFour)
console.log(result) // [6, 8]
Example (Rewriting method chains with pipe)
The same transformation can be written with data-last functions.
import { Array, pipe } from "effect"
const numbers = [1, 2, 3, 4]
const double = (n: number) => n * 2
const greaterThanFour = (n: number) => n > 4
const result = pipe(
numbers,
Array.map(double),
Array.filter(greaterThanFour)
)
console.log(result) // [6, 8]
Example (Chaining arithmetic operations)
import { pipe } from "effect"
// Define simple arithmetic operations
const increment = (x: number) => x + 1
const double = (x: number) => x * 2
const subtractTen = (x: number) => x - 10
// Sequentially apply these operations using `pipe`
const result = pipe(5, increment, double, subtractTen)
console.log(result)
// Output: 2
Example (Building a simple transformation pipeline)
import { pipe } from "effect"
// Simple transformation pipeline
const result = pipe(
5,
(x) => x * 2, // 10
(x) => x + 1, // 11
(x) => x.toString() // "11"
)
console.log(result) // "11"
pipe(
impl: Omit<
FileSystem,
| typeof TypeId
| "exists"
| "readFileString"
| "stream"
| "sink"
| "writeFileString"
>
impl.open: (
path: string,
options?: {
readonly flag?: OpenFlag | undefined
readonly mode?: number | undefined
}
) => Effect.Effect<File, PlatformError, Scope>
Open a file at path with the specified options.
Details
The file handle will be automatically closed when the scope is closed.
open(path: stringpath, { flag?: OpenFlag | undefinedflag: "w", ...options: | {
readonly flag?: OpenFlag | undefined
readonly mode?: number | undefined
}
| undefined
options }),
import EffectEffect.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
f: (a: A) => B
): Effect<B, E, R>
}
map((file: File(parameter) file: {
fd: File.Descriptor;
stat: Effect.Effect<File.Info, PlatformError>;
seek: (offset: SizeInput, from: SeekMode) => Effect.Effect<void>;
sync: Effect.Effect<void, PlatformError>;
read: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError>;
readAlloc: (size: SizeInput) => Effect.Effect<Option.Option<Uint8Array>, PlatformError>;
truncate: (length?: SizeInput) => Effect.Effect<void, PlatformError>;
write: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError>;
writeAll: (buffer: Uint8Array) => Effect.Effect<void, PlatformError>;
}
file) => import SinkSink.const forEach: <In, X, E, R>(
f: (input: In) => Effect.Effect<X, E, R>
) => Sink<void, In, never, E, R>
A sink that executes the provided effectful function for every item fed
to it.
Example (Running effects for each item)
import { Console, Effect, Sink, Stream } from "effect"
// Create a sink that logs each item
const sink = Sink.forEach((item: number) => Console.log(`Processing: ${item}`))
// Use it with a stream
const stream = Stream.make(1, 2, 3)
const program = Stream.run(stream, sink)
Effect.runPromise(program)
// Output:
// Processing: 1
// Processing: 2
// Processing: 3
forEach((_: Uint8Array<ArrayBufferLike>_: interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the
requested number of bytes could not be allocated an exception is raised.
Uint8Array) => file: File(parameter) file: {
fd: File.Descriptor;
stat: Effect.Effect<File.Info, PlatformError>;
seek: (offset: SizeInput, from: SeekMode) => Effect.Effect<void>;
sync: Effect.Effect<void, PlatformError>;
read: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError>;
readAlloc: (size: SizeInput) => Effect.Effect<Option.Option<Uint8Array>, PlatformError>;
truncate: (length?: SizeInput) => Effect.Effect<void, PlatformError>;
write: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError>;
writeAll: (buffer: Uint8Array) => Effect.Effect<void, PlatformError>;
}
file.File.writeAll: (buffer: Uint8Array) => Effect.Effect<void, PlatformError>writeAll(_: Uint8Array<ArrayBufferLike>_))),
import SinkSink.const unwrap: <A, In, L, E, R, R2>(
effect: Effect.Effect<
Sink<A, In, L, E, R2>,
E,
R
>
) => Sink<
A,
In,
L,
E,
Exclude<R, Scope.Scope> | R2
>
Creates a sink produced from a scoped effect.
Example (Unwrapping a sink effect)
import { Console, Effect, Sink, Stream } from "effect"
// Create a sink from an effect that produces a sink
const sinkEffect = Effect.succeed(
Sink.forEach((item: number) => Console.log(`Item: ${item}`))
)
const sink = Sink.unwrap(sinkEffect)
// Use it with a stream
const stream = Stream.make(1, 2, 3)
const program = Stream.run(stream, sink)
Effect.runPromise(program)
// Output:
// Item: 1
// Item: 2
// Item: 3
unwrap
),
FileSystem.writeFileString: (path: string, data: string, options: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined } | undefined) => Effect.Effect<void, PlatformError, never>Write a string to a file at path.
writeFileString: (path: stringpath, data: stringdata, options: | {
readonly flag?: OpenFlag | undefined
readonly mode?: number | undefined
}
| undefined
options) =>
import EffectEffect.const flatMap: {
<A, B, E1, R1>(
f: (a: A) => Effect<B, E1, R1>
): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E1 | E, R1 | R>
<A, E, R, B, E1, R1>(
self: Effect<A, E, R>,
f: (a: A) => Effect<B, E1, R1>
): Effect<B, E | E1, R | R1>
}
flatMap(
import EffectEffect.try<A, E = Cause.UnknownError>(options: { readonly try: LazyArg<A>; readonly catch: (error: unknown) => E } | LazyArg<A>): Effect<A, E>Creates an Effect from a synchronous computation that may throw, mapping
thrown values into the error channel.
When to use
Use when you need to perform synchronous operations that might throw, such
as parsing JSON, and want thrown exceptions captured as Effect errors.
Details
The thunk is evaluated when the effect runs. If it returns normally, the
returned value becomes the success value. If it throws, the thrown value is
mapped into the error channel.
Passing the thunk directly maps failures to
Cause.UnknownError
.
Passing { try, catch } uses catch to map failures to an error of type
E.
Gotchas
If catch throws while mapping the error, that thrown value is treated as
a defect. Return the error value you want in the error channel instead of
throwing it.
Example (Parsing JSON)
import { Effect } from "effect"
const parseJSON = (input: string) =>
Effect.try(() => JSON.parse(input))
// Success case
Effect.runPromise(parseJSON("{\"name\": \"Alice\"}")).then(console.log)
// Output: { name: "Alice" }
// Failure case maps the thrown value to UnknownError
Effect.runPromiseExit(parseJSON("invalid json")).then(console.log)
Example (Mapping exceptions to a tagged error)
import { Data, Effect } from "effect"
class JsonParsingError extends Data.TaggedError("JsonParsingError")<{ readonly cause: unknown }> {}
const parseJSON = (input: string) =>
Effect.try({
try: () => JSON.parse(input),
catch: (cause) => new JsonParsingError({ cause })
})
Effect.runPromiseExit(parseJSON("invalid json")).then(console.log)
// Output: Exit.failure with custom Error message
try({
try: LazyArg<Uint8Array<ArrayBuffer>>try: () => new var TextEncoder: new () => TextEncoderThe TextEncoder interface takes a stream of code points as input and emits a stream of UTF-8 bytes.
TextEncoder().TextEncoder.encode(input?: string): Uint8Array<ArrayBuffer>The TextEncoder.encode() method takes a string as input, and returns a Global_Objects/Uint8Array containing the text given in parameters encoded with the specific method for that TextEncoder object.
encode(data: stringdata),
catch: (error: unknown) => PlatformErrorcatch: (cause: unknowncause) =>
function badArgument(options: { readonly module: string; readonly method: string; readonly description?: string | undefined; readonly cause?: unknown }): PlatformErrorCreates a PlatformError whose reason is a BadArgument.
When to use
Use to report a platform API rejecting caller input before performing the
underlying operation.
badArgument({
module: stringmodule: "FileSystem",
method: stringmethod: "writeFileString",
description?: string | undefineddescription: "could not encode string",
cause?: unknowncause
})
}),
(_: Uint8Array<ArrayBuffer>_) => impl: Omit<
FileSystem,
| typeof TypeId
| "exists"
| "readFileString"
| "stream"
| "sink"
| "writeFileString"
>
impl.writeFile: (
path: string,
data: Uint8Array,
options?: {
readonly flag?: OpenFlag | undefined
readonly mode?: number | undefined
}
) => Effect.Effect<void, PlatformError>
Write data to a file at path.
writeFile(path: stringpath, _: Uint8Array<ArrayBuffer>_, options: | {
readonly flag?: OpenFlag | undefined
readonly mode?: number | undefined
}
| undefined
options)
)
})