Skip to main content
Module

x/fun/mod.ts>array.array

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
interface array.array
implements Kind
Re-export
import { type array } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { array } = array;

Specifies ReadonlyArray as a Higher Kinded Type, with covariant parameter A corresponding to the 0th index of any substitutions.

Properties

readonly
kind: ReadonlyArray<Out<this, 0>>
type alias array.array
Re-export
import { type array } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { array } = array;

This type can be used as a placeholder for an array of any type.

definition: ReadonlyArray<any>
definition: T extends ReadonlyArray<infer A> ? A : never
definition: readonly [A, ...A[]]
definition: NonEmptyArray<any>
variable array.array
Re-export
import { array } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { array } = array;

type

Applicable<KindArray>

type

Filterable<KindArray>

type

Flatmappable<KindArray>

type

Mappable<KindArray>

type

Foldable<KindArray>

type

Traversable<KindArray>

type

Wrappable<KindArray>
function array.array
Re-export
import { array } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { array } = array;

Create a NonEmptyArray from a variadic number of arguments.

Examples

Example 1

import * as A from "./array.ts";

const result = A.array(1, 2, 3, 4); // [1, 2, 3, 4]

Given a Predicate or Refinement, apply the predicate or refinement to every value in an array, removing (and refining) the elements that the predicate or refinement return false for.

Examples

Example 1

import * as A from "./array.ts";
import { pipe } from "./fn.ts";

const result = pipe(
  A.array(1, 2, 3, 4, 5, 6),
  A.filter(n => n % 2 === 0),
); // [2, 4, 6]

Type Parameters

A
B extends A

Parameters

refinement: (a: A, index: number) => a is B

Returns

(ua: ReadonlyArray<A>) => ReadonlyArray<B>

Parameters

predicate: (a: A, index: number) => boolean

Returns

(ua: ReadonlyArray<A>) => ReadonlyArray<A>

Partition a ReadonlyArray into two ReadonlyArrays using a predicate or refinement to do the sorting. If the predicate or refinement returns true for a value, the value is pushed into the first array in a Pair, otherwise it is pushed into the second array in a pair.

Examples

Example 1

import * as A from "./array.ts";
import { pipe } from "./fn.ts";

const result = pipe(
  A.range(10, 1), // [1, 2, 3, ..., 10]
  A.partition(n => n % 2 === 0),
); // Pair<[2, 4, 6, 8, 10], [1, 3, 5, 7, 9]>

Type Parameters

A
B extends A

Parameters

refinement: (a: A, index: number) => a is B

Returns

(ua: ReadonlyArray<A>) => Pair<ReadonlyArray<B>, ReadonlyArray<A>>

Parameters

predicate: (a: A, index: number) => boolean

Returns

(ua: ReadonlyArray<A>) => Pair<ReadonlyArray<A>, ReadonlyArray<A>>