or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

concurrency-fibers.mdcontext-services.mddata-structures.mdeffect-core.mderror-observability.mdfunction-utilities.mdindex.mdlayer-system.mdschema-validation.mdstreaming.md
tile.json

data-structures.mddocs/

Data Structures

Comprehensive collection of immutable data structures including arrays, hash maps, sets, lists, and specialized structures optimized for functional programming patterns and efficient operations.

Capabilities

Array Operations

Enhanced array utilities with functional programming support and type safety.

declare namespace Array {
  /**
   * Creates an array from the provided elements
   */
  function make<A>(...elements: A[]): A[];
  
  /**
   * Creates an array from an iterable
   */
  function fromIterable<A>(iterable: Iterable<A>): A[];
  
  /**
   * Transforms each element of an array
   */
  function map<A, B>(f: (a: A, i: number) => B): (self: ReadonlyArray<A>) => B[];
  
  /**
   * Filters elements based on a predicate
   */
  function filter<A>(predicate: (a: A, i: number) => boolean): (self: ReadonlyArray<A>) => A[];
  
  /**
   * Reduces an array to a single value
   */
  function reduce<A, B>(b: B, f: (b: B, a: A, i: number) => B): (self: ReadonlyArray<A>) => B;
  
  /**
   * Gets an element at a specific index
   */
  function get(index: number): <A>(self: ReadonlyArray<A>) => Option<A>;
  
  /**
   * Gets the first element
   */
  function head<A>(self: ReadonlyArray<A>): Option<A>;
  
  /**
   * Gets all elements except the first
   */
  function tail<A>(self: ReadonlyArray<A>): Option<ReadonlyArray<A>>;
  
  /**
   * Appends an element to the end
   */
  function append<A>(element: A): (self: ReadonlyArray<A>) => ReadonlyArray<A>;
  
  /**
   * Prepends an element to the beginning
   */
  function prepend<A>(element: A): (self: ReadonlyArray<A>) => ReadonlyArray<A>;
}

Usage Examples:

import { Array, pipe } from "effect";

// Basic array operations
const numbers = Array.make(1, 2, 3, 4, 5);

const doubled = pipe(
  numbers,
  Array.map(x => x * 2)
); // [2, 4, 6, 8, 10]

const evens = pipe(
  numbers,
  Array.filter(x => x % 2 === 0)
); // [2, 4]

// Reduction
const sum = pipe(
  numbers,
  Array.reduce(0, (acc, curr) => acc + curr)
); // 15

// Safe access
const first = pipe(numbers, Array.head); // Some(1)
const empty = pipe([], Array.head); // None

HashMap Operations

Immutable hash map with efficient key-value operations and functional utilities.

interface HashMap<K, V> extends Iterable<[K, V]> {}

declare namespace HashMap {
  /**
   * Creates an empty HashMap
   */
  function empty<K, V>(): HashMap<K, V>;
  
  /**
   * Creates a HashMap from key-value pairs
   */
  function make<K, V>(...entries: readonly (readonly [K, V])[]): HashMap<K, V>;
  
  /**
   * Creates a HashMap from an iterable of entries
   */
  function fromIterable<K, V>(iterable: Iterable<readonly [K, V]>): HashMap<K, V>;
  
  /**
   * Sets a key-value pair
   */
  function set<K, V>(key: K, value: V): (self: HashMap<K, V>) => HashMap<K, V>;
  
  /**
   * Gets a value by key
   */
  function get<K>(key: K): <V>(self: HashMap<K, V>) => Option<V>;
  
  /**
   * Checks if a key exists
   */
  function has<K>(key: K): <V>(self: HashMap<K, V>) => boolean;
  
  /**
   * Removes a key-value pair
   */
  function remove<K>(key: K): <V>(self: HashMap<K, V>) => HashMap<K, V>;
  
  /**
   * Gets the size of the HashMap
   */
  function size<K, V>(self: HashMap<K, V>): number;
  
  /**
   * Maps over values
   */
  function map<A, B>(f: (value: A, key: K) => B): <K>(self: HashMap<K, A>) => HashMap<K, B>;
  
  /**
   * Filters entries based on predicate
   */
  function filter<K, A>(predicate: (value: A, key: K) => boolean): (self: HashMap<K, A>) => HashMap<K, A>;
}

Usage Examples:

import { HashMap, pipe } from "effect";

// Create and populate HashMap
const users = pipe(
  HashMap.empty<string, { name: string; age: number }>(),
  HashMap.set("alice", { name: "Alice", age: 30 }),
  HashMap.set("bob", { name: "Bob", age: 25 })
);

// Access values
const alice = pipe(users, HashMap.get("alice")); // Some({ name: "Alice", age: 30 })

// Transform values
const usersWithUppercaseNames = pipe(
  users,
  HashMap.map(user => ({ ...user, name: user.name.toUpperCase() }))
);

// Filter entries
const adults = pipe(
  users,
  HashMap.filter(user => user.age >= 18)
);

HashSet Operations

Immutable hash set for storing unique values with set operations.

interface HashSet<A> extends Iterable<A> {}

declare namespace HashSet {
  /**
   * Creates an empty HashSet
   */
  function empty<A>(): HashSet<A>;
  
  /**
   * Creates a HashSet from values
   */
  function make<A>(...values: A[]): HashSet<A>;
  
  /**
   * Creates a HashSet from an iterable
   */
  function fromIterable<A>(iterable: Iterable<A>): HashSet<A>;
  
  /**
   * Adds a value to the set
   */
  function add<A>(value: A): (self: HashSet<A>) => HashSet<A>;
  
  /**
   * Removes a value from the set
   */
  function remove<A>(value: A): (self: HashSet<A>) => HashSet<A>;
  
  /**
   * Checks if a value exists in the set
   */
  function has<A>(value: A): (self: HashSet<A>) => boolean;
  
  /**
   * Gets the size of the set
   */
  function size<A>(self: HashSet<A>): number;
  
  /**
   * Union of two sets
   */
  function union<A>(that: HashSet<A>): (self: HashSet<A>) => HashSet<A>;
  
  /**
   * Intersection of two sets
   */
  function intersection<A>(that: HashSet<A>): (self: HashSet<A>) => HashSet<A>;
  
  /**
   * Difference between two sets
   */
  function difference<A>(that: HashSet<A>): (self: HashSet<A>) => HashSet<A>;
}

List Operations

Immutable linked list optimized for prepend operations and functional patterns.

interface List<A> extends Iterable<A> {}

declare namespace List {
  /**
   * Creates an empty List
   */
  function empty<A>(): List<A>;
  
  /**
   * Creates a List from values
   */
  function make<A>(...values: A[]): List<A>;
  
  /**
   * Prepends a value (cons operation)
   */
  function prepend<A>(value: A): (self: List<A>) => List<A>;
  
  /**
   * Gets the first element
   */
  function head<A>(self: List<A>): Option<A>;
  
  /**
   * Gets all elements except the first
   */
  function tail<A>(self: List<A>): Option<List<A>>;
  
  /**
   * Maps over list elements
   */
  function map<A, B>(f: (a: A) => B): (self: List<A>) => List<B>;
  
  /**
   * Filters list elements
   */
  function filter<A>(predicate: (a: A) => boolean): (self: List<A>) => List<A>;
  
  /**
   * Reverses the list
   */
  function reverse<A>(self: List<A>): List<A>;
  
  /**
   * Converts to array
   */
  function toArray<A>(self: List<A>): A[];
}

Chunk Operations

Efficient array-like structure optimized for appending and immutable operations.

interface Chunk<A> extends Iterable<A> {}

declare namespace Chunk {
  /**
   * Creates an empty Chunk
   */
  function empty<A>(): Chunk<A>;
  
  /**
   * Creates a Chunk from values
   */
  function make<A>(...values: A[]): Chunk<A>;
  
  /**
   * Creates a Chunk from an array
   */
  function fromIterable<A>(iterable: Iterable<A>): Chunk<A>;
  
  /**
   * Appends a value
   */
  function append<A>(value: A): (self: Chunk<A>) => Chunk<A>;
  
  /**
   * Prepends a value
   */
  function prepend<A>(value: A): (self: Chunk<A>) => Chunk<A>;
  
  /**
   * Concatenates two chunks
   */
  function concat<A>(that: Chunk<A>): (self: Chunk<A>) => Chunk<A>;
  
  /**
   * Maps over chunk elements
   */
  function map<A, B>(f: (a: A) => B): (self: Chunk<A>) => Chunk<B>;
  
  /**
   * Gets chunk size
   */
  function size<A>(self: Chunk<A>): number;
  
  /**
   * Converts to array
   */
  function toArray<A>(self: Chunk<A>): A[];
}

Option Type

Maybe/Optional type for handling nullable values safely.

type Option<A> = None | Some<A>;

interface None {
  readonly _tag: "None";
}

interface Some<A> {
  readonly _tag: "Some";  
  readonly value: A;
}

declare namespace Option {
  /**
   * Creates a Some value
   */
  function some<A>(value: A): Option<A>;
  
  /**
   * Creates a None value
   */
  function none(): Option<never>;
  
  /**
   * Creates Option from nullable value
   */
  function fromNullable<A>(value: A | null | undefined): Option<A>;
  
  /**
   * Maps over Option value
   */
  function map<A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>;
  
  /**
   * FlatMaps over Option value
   */
  function flatMap<A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>;
  
  /**
   * Gets value or default
   */
  function getOrElse<B>(onNone: LazyArg<B>): <A>(self: Option<A>) => A | B;
  
  /**
   * Checks if Option is Some
   */
  function isSome<A>(self: Option<A>): self is Some<A>;
  
  /**
   * Checks if Option is None
   */
  function isNone<A>(self: Option<A>): self is None;
}

Either Type

Error/success type for representing computations that may fail.

type Either<E, A> = Left<E> | Right<A>;

interface Left<E> {
  readonly _tag: "Left";
  readonly left: E;
}

interface Right<A> {
  readonly _tag: "Right";
  readonly right: A;
}

declare namespace Either {
  /**
   * Creates a Left (error) value
   */
  function left<E>(value: E): Either<E, never>;
  
  /**
   * Creates a Right (success) value
   */
  function right<A>(value: A): Either<never, A>;
  
  /**
   * Maps over Right value
   */
  function map<A, B>(f: (a: A) => B): <E>(self: Either<E, A>) => Either<E, B>;
  
  /**
   * Maps over Left value
   */
  function mapLeft<E, E2>(f: (e: E) => E2): <A>(self: Either<E, A>) => Either<E2, A>;
  
  /**
   * FlatMaps over Right value
   */
  function flatMap<A, E2, B>(f: (a: A) => Either<E2, B>): <E1>(self: Either<E1, A>) => Either<E1 | E2, B>;
  
  /**
   * Pattern matches on Either
   */
  function match<E, A, B, C>(options: {
    readonly onLeft: (e: E) => B;
    readonly onRight: (a: A) => C;
  }): (self: Either<E, A>) => B | C;
  
  /**
   * Checks if Either is Right
   */
  function isRight<E, A>(self: Either<E, A>): self is Right<A>;
  
  /**
   * Checks if Either is Left
   */
  function isLeft<E, A>(self: Either<E, A>): self is Left<E>;
}

Usage Examples:

import { Option, Either, pipe } from "effect";

// Option usage
const parseAge = (input: string): Option<number> => {
  const parsed = parseInt(input, 10);
  return isNaN(parsed) ? Option.none() : Option.some(parsed);
};

const result = pipe(
  parseAge("25"),
  Option.map(age => age * 2),
  Option.getOrElse(() => 0)
); // 50

// Either usage
const divide = (a: number, b: number): Either<string, number> => {
  return b === 0 ? Either.left("Division by zero") : Either.right(a / b);
};

const calculation = pipe(
  divide(10, 2),
  Either.flatMap(result => divide(result, 2)),
  Either.match({
    onLeft: error => `Error: ${error}`,
    onRight: value => `Result: ${value}`
  })
); // "Result: 2.5"

Types

// Non-empty array types
type NonEmptyReadonlyArray<A> = readonly [A, ...ReadonlyArray<A>];
type NonEmptyArray<A> = [A, ...Array<A>];

// Lazy argument for deferred computation
type LazyArg<A> = () => A;

// Pipeable interface for method chaining
interface Pipeable {
  pipe<Self, Args extends ReadonlyArray<any>, Return>(
    this: Self,
    ...args: Args
  ): Return;
}