title | nav_order | parent |
---|---|---|
ReadonlyNonEmptyArray.ts |
71 |
Modules |
Data structure which represents non-empty arrays
Added in v2.5.0
- Alt
- Applicative
- Apply
- Extend
- Foldable
- FoldableWithIndex
- Functor
- FunctorWithIndex
- Monad
- combinators
- constructors
- destructors
- instances
- model
- utils
Identifies an associative operation on a type constructor. It is similar to Semigroup
, except that it applies to
types of kind * -> *
.
Signature
export declare const alt: <A>(
that: Lazy<ReadonlyNonEmptyArray<A>>
) => (fa: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<A>
Added in v2.6.2
Less strict version of alt
.
Signature
export declare const altW: <B>(
that: Lazy<ReadonlyNonEmptyArray<B>>
) => <A>(fa: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<B | A>
Added in v2.9.0
Wrap a value into the type constructor.
Signature
export declare const of: <A>(a: A) => ReadonlyNonEmptyArray<A>
Added in v2.5.0
Signature
export declare const ap: <A>(
fa: ReadonlyNonEmptyArray<A>
) => <B>(fab: ReadonlyNonEmptyArray<(a: A) => B>) => ReadonlyNonEmptyArray<B>
Added in v2.5.0
Signature
export declare const extend: <A, B>(
f: (fa: ReadonlyNonEmptyArray<A>) => B
) => (ma: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<B>
Added in v2.5.0
Signature
export declare const foldMap: <S>(S: Semigroup<S>) => <A>(f: (a: A) => S) => (fa: ReadonlyNonEmptyArray<A>) => S
Added in v2.5.0
Signature
export declare const reduce: <A, B>(b: B, f: (b: B, a: A) => B) => (fa: ReadonlyNonEmptyArray<A>) => B
Added in v2.5.0
Signature
export declare const reduceRight: <A, B>(b: B, f: (a: A, b: B) => B) => (fa: ReadonlyNonEmptyArray<A>) => B
Added in v2.5.0
Signature
export declare const foldMapWithIndex: <S>(
S: Semigroup<S>
) => <A>(f: (i: number, a: A) => S) => (fa: ReadonlyNonEmptyArray<A>) => S
Added in v2.5.0
Signature
export declare const reduceRightWithIndex: <A, B>(
b: B,
f: (i: number, a: A, b: B) => B
) => (fa: ReadonlyNonEmptyArray<A>) => B
Added in v2.5.0
Signature
export declare const reduceWithIndex: <A, B>(
b: B,
f: (i: number, b: B, a: A) => B
) => (fa: ReadonlyNonEmptyArray<A>) => B
Added in v2.5.0
map
can be used to turn functions (a: A) => B
into functions (fa: F<A>) => F<B>
whose argument and return types
use the type constructor F
to represent some computational context.
Signature
export declare const map: <A, B>(f: (a: A) => B) => (fa: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<B>
Added in v2.5.0
Signature
export declare const mapWithIndex: <A, B>(
f: (i: number, a: A) => B
) => (fa: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<B>
Added in v2.5.0
Composes computations in sequence, using the return value of one computation to determine the next computation.
Signature
export declare const chain: <A, B>(
f: (a: A) => ReadonlyNonEmptyArray<B>
) => (ma: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<B>
Added in v2.5.0
Combine two effectful actions, keeping only the result of the first.
Derivable from Apply
.
Signature
export declare const apFirst: <B>(
fb: ReadonlyNonEmptyArray<B>
) => <A>(fa: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<A>
Added in v2.5.0
Combine two effectful actions, keeping only the result of the second.
Derivable from Apply
.
Signature
export declare const apSecond: <B>(
fb: ReadonlyNonEmptyArray<B>
) => <A>(fa: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<B>
Added in v2.5.0
Composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.
Derivable from Monad
.
Signature
export declare const chainFirst: <A, B>(
f: (a: A) => ReadonlyNonEmptyArray<B>
) => (ma: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<A>
Added in v2.5.0
Derivable from Extend
.
Signature
export declare const duplicate: <A>(ma: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<ReadonlyNonEmptyArray<A>>
Added in v2.5.0
Derivable from Monad
.
Signature
export declare const flatten: <A>(mma: ReadonlyNonEmptyArray<ReadonlyNonEmptyArray<A>>) => ReadonlyNonEmptyArray<A>
Added in v2.5.0
Group equal, consecutive elements of an array into non empty arrays.
Signature
export declare function group<B>(
E: Eq<B>
): {
<A extends B>(as: ReadonlyNonEmptyArray<A>): ReadonlyNonEmptyArray<ReadonlyNonEmptyArray<A>>
<A extends B>(as: ReadonlyArray<A>): ReadonlyArray<ReadonlyNonEmptyArray<A>>
}
Example
import { cons, group } from 'fp-ts/ReadonlyNonEmptyArray'
import { ordNumber } from 'fp-ts/Ord'
assert.deepStrictEqual(group(ordNumber)([1, 2, 1, 1]), [cons(1, []), cons(2, []), cons(1, [1])])
Added in v2.5.0
Sort and then group the elements of an array into non empty arrays.
Signature
export declare function groupSort<B>(
O: Ord<B>
): {
<A extends B>(as: ReadonlyNonEmptyArray<A>): ReadonlyNonEmptyArray<ReadonlyNonEmptyArray<A>>
<A extends B>(as: ReadonlyArray<A>): ReadonlyArray<ReadonlyNonEmptyArray<A>>
}
Example
import { cons, groupSort } from 'fp-ts/ReadonlyNonEmptyArray'
import { ordNumber } from 'fp-ts/Ord'
assert.deepStrictEqual(groupSort(ordNumber)([1, 2, 1, 1]), [cons(1, [1, 1]), cons(2, [])])
Added in v2.5.0
Places an element in between members of an array
Signature
export declare const intersperse: <A>(e: A) => (as: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<A>
Example
import { cons, intersperse } from 'fp-ts/ReadonlyNonEmptyArray'
assert.deepStrictEqual(intersperse(9)(cons(1, [2, 3, 4])), cons(1, [9, 2, 9, 3, 9, 4]))
Added in v2.9.0
Prepend an element to every member of an array
Signature
export declare const prependToAll: <A>(e: A) => (xs: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<A>
Example
import { cons, prependToAll } from 'fp-ts/ReadonlyNonEmptyArray'
assert.deepStrictEqual(prependToAll(9)(cons(1, [2, 3, 4])), cons(9, [1, 9, 2, 9, 3, 9, 4]))
Added in v2.9.0
Signature
export declare const reverse: <A>(nea: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<A>
Added in v2.5.0
Signature
export declare function sort<B>(O: Ord<B>): <A extends B>(nea: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<A>
Added in v2.5.0
Signature
export declare const zip: {
<B>(bs: ReadonlyNonEmptyArray<B>): <A>(as: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<readonly [A, B]>
<A, B>(as: ReadonlyNonEmptyArray<A>, bs: ReadonlyNonEmptyArray<B>): ReadonlyNonEmptyArray<readonly [A, B]>
}
Added in v2.5.1
Signature
export declare const zipWith: <A, B, C>(
fa: ReadonlyNonEmptyArray<A>,
fb: ReadonlyNonEmptyArray<B>,
f: (a: A, b: B) => C
) => ReadonlyNonEmptyArray<C>
Added in v2.5.1
Signature
export declare function concat<A>(fx: ReadonlyArray<A>, fy: ReadonlyNonEmptyArray<A>): ReadonlyNonEmptyArray<A>
export declare function concat<A>(fx: ReadonlyNonEmptyArray<A>, fy: ReadonlyArray<A>): ReadonlyNonEmptyArray<A>
Added in v2.5.0
Append an element to the front of an array, creating a new non empty array
Signature
export declare const cons: <A>(head: A, tail: readonly A[]) => ReadonlyNonEmptyArray<A>
Example
import { cons } from 'fp-ts/ReadonlyNonEmptyArray'
assert.deepStrictEqual(cons(1, [2, 3, 4]), [1, 2, 3, 4])
Added in v2.5.0
Signature
export declare function fromArray<A>(as: Array<A>): Option<ReadonlyNonEmptyArray<A>>
Added in v2.5.0
Builds a ReadonlyNonEmptyArray
from an array returning none
if as
is an empty array
Signature
export declare function fromReadonlyArray<A>(as: ReadonlyArray<A>): Option<ReadonlyNonEmptyArray<A>>
Added in v2.5.0
Splits an array into sub-non-empty-arrays stored in an object, based on the result of calling a string
-returning
function on each element, and grouping the results according to values returned
Signature
export declare function groupBy<A>(
f: (a: A) => string
): (as: ReadonlyArray<A>) => ReadonlyRecord<string, ReadonlyNonEmptyArray<A>>
Example
import { cons, groupBy } from 'fp-ts/ReadonlyNonEmptyArray'
assert.deepStrictEqual(groupBy((s: string) => String(s.length))(['foo', 'bar', 'foobar']), {
'3': cons('foo', ['bar']),
'6': cons('foobar', []),
})
Added in v2.5.0
Append an element to the end of an array, creating a new non empty array
Signature
export declare const snoc: <A>(init: readonly A[], end: A) => ReadonlyNonEmptyArray<A>
Example
import { snoc } from 'fp-ts/ReadonlyNonEmptyArray'
assert.deepStrictEqual(snoc([1, 2, 3], 4), [1, 2, 3, 4])
Added in v2.5.0
Produces a couple of the first element of the array, and a new array of the remaining elements, if any
Signature
export declare function uncons<A>(nea: ReadonlyNonEmptyArray<A>): readonly [A, ReadonlyArray<A>]
Example
import { cons, uncons } from 'fp-ts/ReadonlyNonEmptyArray'
assert.deepStrictEqual(uncons(cons(1, [2, 3, 4])), [1, [2, 3, 4]])
Added in v2.9.0
Produces a couple of a copy of the array without its last element, and that last element
Signature
export declare function unsnoc<A>(nea: ReadonlyNonEmptyArray<A>): readonly [ReadonlyArray<A>, A]
Example
import { snoc, unsnoc } from 'fp-ts/ReadonlyNonEmptyArray'
assert.deepStrictEqual(unsnoc(snoc([1, 2, 3], 4)), [[1, 2, 3], 4])
Added in v2.9.0
Signature
export declare const Alt: Alt1<'ReadonlyNonEmptyArray'>
Added in v2.7.0
Signature
export declare const Applicative: Applicative1<'ReadonlyNonEmptyArray'>
Added in v2.7.0
Signature
export declare const Comonad: Comonad1<'ReadonlyNonEmptyArray'>
Added in v2.7.0
Signature
export declare const Foldable: Foldable1<'ReadonlyNonEmptyArray'>
Added in v2.7.0
Signature
export declare const FoldableWithIndex: FoldableWithIndex1<'ReadonlyNonEmptyArray', number>
Added in v2.7.0
Signature
export declare const Functor: Functor1<'ReadonlyNonEmptyArray'>
Added in v2.7.0
Signature
export declare const FunctorWithIndex: FunctorWithIndex1<'ReadonlyNonEmptyArray', number>
Added in v2.7.0
Signature
export declare const Monad: Monad1<'ReadonlyNonEmptyArray'>
Added in v2.7.0
Signature
export declare const Traversable: Traversable1<'ReadonlyNonEmptyArray'>
Added in v2.7.0
Signature
export declare const TraversableWithIndex: TraversableWithIndex1<'ReadonlyNonEmptyArray', number>
Added in v2.7.0
Signature
export declare const URI: 'ReadonlyNonEmptyArray'
Added in v2.5.0
Signature
export type URI = typeof URI
Added in v2.5.0
Signature
export declare const getEq: <A>(E: Eq<A>) => Eq<ReadonlyNonEmptyArray<A>>
Example
import { getEq, cons } from 'fp-ts/ReadonlyNonEmptyArray'
import { eqNumber } from 'fp-ts/Eq'
const E = getEq(eqNumber)
assert.strictEqual(E.equals(cons(1, [2]), [1, 2]), true)
assert.strictEqual(E.equals(cons(1, [2]), [1, 3]), false)
Added in v2.5.0
Builds a Semigroup
instance for ReadonlyNonEmptyArray
Signature
export declare function getSemigroup<A = never>(): Semigroup<ReadonlyNonEmptyArray<A>>
Added in v2.5.0
Signature
export declare const getShow: <A>(S: Show<A>) => Show<ReadonlyNonEmptyArray<A>>
Added in v2.5.0
Signature
export declare const readonlyNonEmptyArray: Monad1<'ReadonlyNonEmptyArray'> &
Comonad1<'ReadonlyNonEmptyArray'> &
TraversableWithIndex1<'ReadonlyNonEmptyArray', number> &
FunctorWithIndex1<'ReadonlyNonEmptyArray', number> &
FoldableWithIndex1<'ReadonlyNonEmptyArray', number> &
Alt1<'ReadonlyNonEmptyArray'>
Added in v2.5.0
Signature
export type ReadonlyNonEmptyArray<A> = ReadonlyArray<A> & {
readonly 0: A
}
Added in v2.5.0
Signature
export declare const Do: ReadonlyNonEmptyArray<{}>
Added in v2.9.0
Signature
export declare const apS: <A, N extends string, B>(
name: Exclude<N, keyof A>,
fb: ReadonlyNonEmptyArray<B>
) => (fa: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>
Added in v2.8.0
Signature
export declare const bind: <N extends string, A, B>(
name: Exclude<N, keyof A>,
f: (a: A) => ReadonlyNonEmptyArray<B>
) => (fa: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>
Added in v2.8.0
Signature
export declare const bindTo: <N extends string>(
name: N
) => <A>(fa: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<{ [K in N]: A }>
Added in v2.8.0
Signature
export declare const extract: <A>(wa: ReadonlyNonEmptyArray<A>) => A
Added in v2.6.3
Signature
export declare function filter<A, B extends A>(
refinement: Refinement<A, B>
): (nea: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<B>>
export declare function filter<A>(
predicate: Predicate<A>
): (nea: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<A>>
Added in v2.5.0
Signature
export declare function filterWithIndex<A>(
predicate: (i: number, a: A) => boolean
): (nea: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<A>>
Added in v2.5.0
Signature
export declare function fold<A>(S: Semigroup<A>): (fa: ReadonlyNonEmptyArray<A>) => A
Added in v2.5.0
Signature
export declare function head<A>(nea: ReadonlyNonEmptyArray<A>): A
Added in v2.5.0
Get all but the last element of a non empty array, creating a new array.
Signature
export declare function init<A>(nea: ReadonlyNonEmptyArray<A>): ReadonlyArray<A>
Example
import { init } from 'fp-ts/ReadonlyNonEmptyArray'
assert.deepStrictEqual(init([1, 2, 3]), [1, 2])
assert.deepStrictEqual(init([1]), [])
Added in v2.5.0
Signature
export declare function insertAt<A>(
i: number,
a: A
): (nea: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<A>>
Added in v2.5.0
Signature
export declare function last<A>(nea: ReadonlyNonEmptyArray<A>): A
Added in v2.5.0
Signature
export declare function max<A>(ord: Ord<A>): (nea: ReadonlyNonEmptyArray<A>) => A
Added in v2.5.0
Signature
export declare function min<A>(ord: Ord<A>): (nea: ReadonlyNonEmptyArray<A>) => A
Added in v2.5.0
Signature
export declare function modifyAt<A>(
i: number,
f: (a: A) => A
): (nea: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<A>>
Added in v2.5.0
Signature
export declare const sequence: Sequence1<'ReadonlyNonEmptyArray'>
Added in v2.6.3
Signature
export declare function tail<A>(nea: ReadonlyNonEmptyArray<A>): ReadonlyArray<A>
Added in v2.5.0
Signature
export declare const traverse: PipeableTraverse1<'ReadonlyNonEmptyArray'>
Added in v2.6.3
Signature
export declare const traverseWithIndex: PipeableTraverseWithIndex1<'ReadonlyNonEmptyArray', number>
Added in v2.6.3
Signature
export declare const unzip: <A, B>(
as: ReadonlyNonEmptyArray<readonly [A, B]>
) => readonly [ReadonlyNonEmptyArray<A>, ReadonlyNonEmptyArray<B>]
Added in v2.5.1
Signature
export declare function updateAt<A>(
i: number,
a: A
): (nea: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<A>>
Added in v2.5.0