ReadonlyNonEmptyArray
Instances
- Alt
- Applicative
- Apply
- Chain
- Comonad
- Foldable
- FoldableWithIndex
- Functor
- FunctorWithIndex
- Monad
- Pointed
- Traversable
- TraversableWithIndex
- getEq
- getSemigroup
- getShow
Comonad
Constructors
Conversions
Do notation
Error handling
Folding
Legacy
Mapping
Model
Pattern matching
Sequencing
Traversing
Type lambdas
Utilities
- ap
- apFirst
- apSecond
- chop
- chunksOf
- concat
- concatAll
- concatW
cons(deprecated)- duplicate
- extend
filter(deprecated)filterWithIndex(deprecated)fold(deprecated)- getUnionSemigroup
- group
- groupBy
groupSort(deprecated)- head
- init
insertAt(deprecated)- intercalate
- intersperse
- last
- let
- max
- min
- modifyAt
- modifyHead
- modifyLast
- prependAll
prependToAll(deprecated)readonlyNonEmptyArray(deprecated)- reverse
- rotate
snoc(deprecated)- sort
- sortBy
- splitAt
- tail
- unappend
uncons(deprecated)- union
- uniq
- unprepend
unsnoc(deprecated)- unzip
- updateAt
- updateHead
- updateLast
- zip
- zipWith
Instances
Alt
Signature
export declare const Alt: Alt1<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Applicative
Signature
export declare const Applicative: Applicative1<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Apply
Signature
export declare const Apply: Apply1<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Chain
Signature
export declare const Chain: Chain1<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Comonad
Signature
export declare const Comonad: Comonad1<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Foldable
Signature
export declare const Foldable: Foldable1<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
FoldableWithIndex
Signature
export declare const FoldableWithIndex: FoldableWithIndex1<URI, number>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Functor
Signature
export declare const Functor: Functor1<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
FunctorWithIndex
Signature
export declare const FunctorWithIndex: FunctorWithIndex1<URI, number>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Monad
Signature
export declare const Monad: Monad1<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Pointed
Signature
export declare const Pointed: Pointed1<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Traversable
Signature
export declare const Traversable: Traversable1<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
TraversableWithIndex
Signature
export declare const TraversableWithIndex: TraversableWithIndex1<URI, number>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
getEq
Signature
export declare const getEq: <A>(E: Eq<A>) => Eq<ReadonlyNonEmptyArray<A>>
Details
- Added in 0.1.0
Example
import { getEq } from '@fp-tx/core/ReadonlyNonEmptyArray'
import * as N from '@fp-tx/core/number'
const E = getEq(N.Eq)
assert.strictEqual(E.equals([1, 2], [1, 2]), true)
assert.strictEqual(E.equals([1, 2], [1, 3]), false)
License
- MIT – Copyright (c) 2017-present Giulio Canti
getSemigroup
Builds a Semigroup
instance for ReadonlyNonEmptyArray
Signature
export declare const getSemigroup: <A = never>() => Se.Semigroup<ReadonlyNonEmptyArray<A>>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
getShow
Signature
export declare const getShow: <A>(S: Show<A>) => Show<ReadonlyNonEmptyArray<A>>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Comonad
extract
Signature
export declare const extract: Comonad1<URI>['extract']
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Constructors
makeBy
Return a ReadonlyNonEmptyArray
of length n
with element i
initialized with f(i)
.
Note. n
is normalized to a natural number.
Signature
export declare const makeBy: <A>(f: (i: number) => A) => (n: number) => ReadonlyNonEmptyArray<A>
Details
- Added in 0.1.0
Example
import { makeBy } from '@fp-tx/core/ReadonlyNonEmptyArray'
import { pipe } from '@fp-tx/core/function'
const double = (n: number): number => n * 2
assert.deepStrictEqual(pipe(5, makeBy(double)), [0, 2, 4, 6, 8])
License
- MIT – Copyright (c) 2017-present Giulio Canti
of
Signature
export declare const of: <A>(a: A) => ReadonlyNonEmptyArray<A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
range
Create a ReadonlyNonEmptyArray
containing a range of integers, including both endpoints.
Signature
export declare const range: (start: number, end: number) => ReadonlyNonEmptyArray<number>
Details
- Added in 0.1.0
Example
import { range } from '@fp-tx/core/ReadonlyNonEmptyArray'
assert.deepStrictEqual(range(1, 5), [1, 2, 3, 4, 5])
License
- MIT – Copyright (c) 2017-present Giulio Canti
replicate
Create a ReadonlyNonEmptyArray
containing a value repeated the specified number of times.
Note. n
is normalized to a natural number.
Signature
export declare const replicate: <A>(a: A) => (n: number) => ReadonlyNonEmptyArray<A>
Details
- Added in 0.1.0
Example
import { replicate } from '@fp-tx/core/ReadonlyNonEmptyArray'
import { pipe } from '@fp-tx/core/function'
assert.deepStrictEqual(pipe(3, replicate('a')), ['a', 'a', 'a'])
License
- MIT – Copyright (c) 2017-present Giulio Canti
Conversions
fromArray
Signature
export declare const fromArray: <A>(as: A[]) => Option<ReadonlyNonEmptyArray<A>>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
fromReadonlyArray
Return a ReadonlyNonEmptyArray
from a ReadonlyArray
returning none
if the input is empty.
Signature
export declare const fromReadonlyArray: <A>(as: readonly A[]) => Option<ReadonlyNonEmptyArray<A>>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Do notation
Do
Signature
export declare const Do: ReadonlyNonEmptyArray<{}>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
apS
Signature
export declare const apS: <N extends string, A, B>(
name: Exclude<N, keyof A>,
fb: ReadonlyNonEmptyArray<B>,
) => (
fa: ReadonlyNonEmptyArray<A>,
) => ReadonlyNonEmptyArray<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
bind
Signature
export declare const bind: <N extends string, A, B>(
name: Exclude<N, keyof A>,
f: (a: A) => ReadonlyNonEmptyArray<B>,
) => (
ma: ReadonlyNonEmptyArray<A>,
) => ReadonlyNonEmptyArray<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
bindTo
Signature
export declare const bindTo: <N extends string>(
name: N,
) => <A>(fa: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<{ readonly [K in N]: A }>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Error handling
alt
Identifies an associative operation on a type constructor. It is similar to Semigroup
, except that it applies to types of kind * -> *
.
In case of ReadonlyNonEmptyArray
concatenates the inputs into a single array.
Signature
export declare const alt: <A>(
that: LazyArg<ReadonlyNonEmptyArray<A>>,
) => (as: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<A>
Details
- Added in 0.1.0
Example
import * as RNEA from '@fp-tx/core/ReadonlyNonEmptyArray'
import { pipe } from '@fp-tx/core/function'
assert.deepStrictEqual(
pipe(
[1, 2, 3],
RNEA.alt(() => [4, 5]),
),
[1, 2, 3, 4, 5],
)
License
- MIT – Copyright (c) 2017-present Giulio Canti
altW
Less strict version of alt
.
The W
suffix (short for Widening) means that the return types will be merged.
Signature
export declare const altW: <B>(
that: LazyArg<ReadonlyNonEmptyArray<B>>,
) => <A>(as: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<B | A>
Details
- Added in 0.1.0
Example
import * as RNEA from '@fp-tx/core/ReadonlyNonEmptyArray'
import { pipe } from '@fp-tx/core/function'
assert.deepStrictEqual(
pipe(
[1, 2, 3] as RNEA.ReadonlyNonEmptyArray<number>,
RNEA.altW(() => ['a', 'b']),
),
[1, 2, 3, 'a', 'b'],
)
License
- MIT – Copyright (c) 2017-present Giulio Canti
Folding
foldMap
Note. The constraint is relaxed: a Semigroup
instead of a Monoid
.
Signature
export declare const foldMap: <S>(S: Se.Semigroup<S>) => <A>(f: (a: A) => S) => (as: ReadonlyNonEmptyArray<A>) => S
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
foldMapWithIndex
Note. The constraint is relaxed: a Semigroup
instead of a Monoid
.
Signature
export declare const foldMapWithIndex: <S>(
S: Se.Semigroup<S>,
) => <A>(f: (i: number, a: A) => S) => (as: ReadonlyNonEmptyArray<A>) => S
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
reduce
Signature
export declare const reduce: <A, B>(b: B, f: (b: B, a: A) => B) => (as: ReadonlyNonEmptyArray<A>) => B
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
reduceRight
Signature
export declare const reduceRight: <A, B>(b: B, f: (a: A, b: B) => B) => (as: ReadonlyNonEmptyArray<A>) => B
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
reduceRightWithIndex
Signature
export declare const reduceRightWithIndex: <A, B>(
b: B,
f: (i: number, a: A, b: B) => B,
) => (as: ReadonlyNonEmptyArray<A>) => B
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
reduceWithIndex
Signature
export declare const reduceWithIndex: <A, B>(
b: B,
f: (i: number, b: B, a: A) => B,
) => (as: ReadonlyNonEmptyArray<A>) => B
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Legacy
chain
Alias of flatMap
.
Signature
export declare const chain: <A, B>(
f: (a: A) => ReadonlyNonEmptyArray<B>,
) => (ma: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<B>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Mapping
flap
Signature
export declare const flap: <A>(a: A) => <B>(fab: ReadonlyNonEmptyArray<(a: A) => B>) => ReadonlyNonEmptyArray<B>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
map
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) => (as: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<B>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
mapWithIndex
Signature
export declare const mapWithIndex: <A, B>(
f: (i: number, a: A) => B,
) => (as: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<B>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Model
ReadonlyNonEmptyArray
Signature
export type ReadonlyNonEmptyArray<A> = ReadonlyArray<A> & {
readonly 0: A
}
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Pattern matching
matchLeft
Break a ReadonlyArray
into its first element and remaining elements.
Signature
export declare const matchLeft: <A, B>(f: (head: A, tail: readonly A[]) => B) => (as: ReadonlyNonEmptyArray<A>) => B
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
matchRight
Break a ReadonlyArray
into its initial elements and the last element.
Signature
export declare const matchRight: <A, B>(f: (init: readonly A[], last: A) => B) => (as: ReadonlyNonEmptyArray<A>) => B
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Sequencing
chainFirst
Composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.
Signature
export declare const chainFirst: <A, B>(
f: (a: A) => ReadonlyNonEmptyArray<B>,
) => (first: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<A>
Details
- Added in 0.1.0
Example
import * as RA from '@fp-tx/core/ReadonlyArray'
import { pipe } from '@fp-tx/core/function'
assert.deepStrictEqual(
pipe(
[1, 2, 3],
RA.chainFirst(() => ['a', 'b']),
),
[1, 1, 2, 2, 3, 3],
)
License
- MIT – Copyright (c) 2017-present Giulio Canti
chainWithIndex
Signature
export declare const chainWithIndex: <A, B>(
f: (i: number, a: A) => ReadonlyNonEmptyArray<B>,
) => (as: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<B>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
flatMap
Signature
export declare const flatMap: {
<A, B>(f: (a: A, i: number) => ReadonlyNonEmptyArray<B>): (ma: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<B>
<A, B>(ma: ReadonlyNonEmptyArray<A>, f: (a: A, i: number) => ReadonlyNonEmptyArray<B>): ReadonlyNonEmptyArray<B>
}
Details
- Added in 0.1.0
Example
import * as RNEA from '@fp-tx/core/ReadonlyNonEmptyArray'
import { pipe } from '@fp-tx/core/function'
assert.deepStrictEqual(
pipe(
[1, 2, 3],
RNEA.flatMap(n => [`a${n}`, `b${n}`]),
),
['a1', 'b1', 'a2', 'b2', 'a3', 'b3'],
)
License
- MIT – Copyright (c) 2017-present Giulio Canti
flatten
Signature
export declare const flatten: <A>(mma: ReadonlyNonEmptyArray<ReadonlyNonEmptyArray<A>>) => ReadonlyNonEmptyArray<A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
traverseWithIndex
Signature
export declare const traverseWithIndex: PipeableTraverseWithIndex1<URI, number>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Traversing
sequence
Signature
export declare const sequence: Traversable1<URI>['sequence']
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
traverse
Signature
export declare const traverse: PipeableTraverse1<URI>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Type lambdas
URI
Signature
export type URI = typeof URI
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
URI
Signature
export declare const URI = 'ReadonlyNonEmptyArray'
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Utilities
ap
Signature
export declare const ap: <A>(
as: ReadonlyNonEmptyArray<A>,
) => <B>(fab: ReadonlyNonEmptyArray<(a: A) => B>) => ReadonlyNonEmptyArray<B>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
apFirst
Combine two effectful actions, keeping only the result of the first.
Signature
export declare const apFirst: <B>(
second: ReadonlyNonEmptyArray<B>,
) => <A>(first: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
apSecond
Combine two effectful actions, keeping only the result of the second.
Signature
export declare const apSecond: <B>(
second: ReadonlyNonEmptyArray<B>,
) => <A>(first: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<B>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
chop
A useful recursion pattern for processing a ReadonlyNonEmptyArray
to produce a new ReadonlyNonEmptyArray
, often used for "chopping" up the input ReadonlyNonEmptyArray
. Typically chop
is called with some function that will consume an initial prefix of the ReadonlyNonEmptyArray
and produce a value and the tail of the ReadonlyNonEmptyArray
.
Signature
export declare const chop: <A, B>(
f: (as: ReadonlyNonEmptyArray<A>) => readonly [B, readonly A[]],
) => (as: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<B>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
chunksOf
Splits a ReadonlyNonEmptyArray
into length-n
pieces. The last piece will be shorter if n
does not evenly divide the length of the ReadonlyNonEmptyArray
.
Signature
export declare const chunksOf: (
n: number,
) => <A>(as: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<ReadonlyNonEmptyArray<A>>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
concat
Signature
export declare function concat<A>(
second: ReadonlyNonEmptyArray<A>,
): (first: ReadonlyArray<A>) => ReadonlyNonEmptyArray<A>
export declare function concat<A>(
second: ReadonlyArray<A>,
): (first: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<A>
export declare function concat<A>(first: ReadonlyArray<A>, second: ReadonlyNonEmptyArray<A>): ReadonlyNonEmptyArray<A>
export declare function concat<A>(first: ReadonlyNonEmptyArray<A>, second: ReadonlyArray<A>): ReadonlyNonEmptyArray<A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
concatAll
Signature
export declare const concatAll: <A>(S: Se.Semigroup<A>) => (as: ReadonlyNonEmptyArray<A>) => A
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
concatW
Signature
export declare function concatW<B>(
second: ReadonlyNonEmptyArray<B>,
): <A>(first: ReadonlyArray<A>) => ReadonlyNonEmptyArray<A | B>
export declare function concatW<B>(
second: ReadonlyArray<B>,
): <A>(first: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<A | B>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
cons
cons
Use prepend
instead.
Signature
export declare function cons<A>(head: A): (tail: ReadonlyArray<A>) => ReadonlyNonEmptyArray<A>
export declare function cons<A>(head: A, tail: ReadonlyArray<A>): ReadonlyNonEmptyArray<A>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
duplicate
Signature
export declare const duplicate: <A>(ma: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<ReadonlyNonEmptyArray<A>>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
extend
Signature
export declare const extend: <A, B>(
f: (as: ReadonlyNonEmptyArray<A>) => B,
) => (as: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<B>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
filter
filter
Use filter
instead.
Signature
export declare function filter<A, B extends A>(
refinement: Refinement<A, B>,
): (as: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<B>>
export declare function filter<A>(
predicate: Predicate<A>,
): <B extends A>(bs: ReadonlyNonEmptyArray<B>) => Option<ReadonlyNonEmptyArray<B>>
export declare function filter<A>(
predicate: Predicate<A>,
): (as: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<A>>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
filterWithIndex
filterWithIndex
Use filterWithIndex
instead.
Signature
export declare const filterWithIndex: <A>(
predicate: (i: number, a: A) => boolean,
) => (as: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<A>>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
fold
fold
Use concatAll
instead.
Signature
export declare const fold: <A>(S: Se.Semigroup<A>) => (as: ReadonlyNonEmptyArray<A>) => A
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
getUnionSemigroup
Signature
export declare const getUnionSemigroup: <A>(E: Eq<A>) => Se.Semigroup<ReadonlyNonEmptyArray<A>>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
group
Group equal, consecutive elements of a ReadonlyArray
into ReadonlyNonEmptyArray
s.
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>>
}
Details
- Added in 0.1.0
Example
import { group } from '@fp-tx/core/ReadonlyNonEmptyArray'
import * as N from '@fp-tx/core/number'
assert.deepStrictEqual(group(N.Eq)([1, 2, 1, 1]), [[1], [2], [1, 1]])
License
- MIT – Copyright (c) 2017-present Giulio Canti
groupBy
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 const groupBy: <A>(
f: (a: A) => string,
) => (as: readonly A[]) => Readonly<Record<string, ReadonlyNonEmptyArray<A>>>
Details
- Added in 0.1.0
Example
import { groupBy } from '@fp-tx/core/ReadonlyNonEmptyArray'
assert.deepStrictEqual(groupBy((s: string) => String(s.length))(['a', 'b', 'ab']), {
'1': ['a', 'b'],
'2': ['ab'],
})
License
- MIT – Copyright (c) 2017-present Giulio Canti
groupSort
groupSort
This is just sort
followed by group
.
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>>
}
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
head
Signature
export declare const head: <A>(as: ReadonlyNonEmptyArray<A>) => A
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
init
Get all but the last element of a non empty array, creating a new array.
Signature
export declare const init: <A>(as: ReadonlyNonEmptyArray<A>) => readonly A[]
Details
- Added in 0.1.0
Example
import { init } from '@fp-tx/core/ReadonlyNonEmptyArray'
assert.deepStrictEqual(init([1, 2, 3]), [1, 2])
assert.deepStrictEqual(init([1]), [])
License
- MIT – Copyright (c) 2017-present Giulio Canti
insertAt
insertAt
Use insertAt
instead.
Signature
export declare const insertAt: <A>(i: number, a: A) => (as: readonly A[]) => Option<ReadonlyNonEmptyArray<A>>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
intercalate
Places an element in between members of a ReadonlyNonEmptyArray
, then folds the results using the provided Semigroup
.
Signature
export declare const intercalate: <A>(S: Se.Semigroup<A>) => (middle: A) => (as: ReadonlyNonEmptyArray<A>) => A
Details
- Added in 0.1.0
Example
import * as S from '@fp-tx/core/string'
import { intercalate } from '@fp-tx/core/ReadonlyNonEmptyArray'
assert.deepStrictEqual(intercalate(S.Semigroup)('-')(['a', 'b', 'c']), 'a-b-c')
License
- MIT – Copyright (c) 2017-present Giulio Canti
intersperse
Places an element in between members of a ReadonlyNonEmptyArray
.
Signature
export declare const intersperse: <A>(middle: A) => (as: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<A>
Details
- Added in 0.1.0
Example
import { intersperse } from '@fp-tx/core/ReadonlyNonEmptyArray'
assert.deepStrictEqual(intersperse(9)([1, 2, 3, 4]), [1, 9, 2, 9, 3, 9, 4])
License
- MIT – Copyright (c) 2017-present Giulio Canti
last
Signature
export declare const last: <A>(as: ReadonlyNonEmptyArray<A>) => A
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
let
Signature
export declare const let_: <N extends string, A, B>(
name: Exclude<N, keyof A>,
f: (a: A) => B,
) => (
fa: ReadonlyNonEmptyArray<A>,
) => ReadonlyNonEmptyArray<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
max
Signature
export declare const max: <A>(O: Ord<A>) => (as: ReadonlyNonEmptyArray<A>) => A
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
min
Signature
export declare const min: <A>(O: Ord<A>) => (as: ReadonlyNonEmptyArray<A>) => A
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
modifyAt
Signature
export declare const modifyAt: <A>(
i: number,
f: (a: A) => A,
) => (as: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<A>>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
modifyHead
Apply a function to the head, creating a new ReadonlyNonEmptyArray
.
Signature
export declare const modifyHead: <A>(f: Endomorphism<A>) => (as: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
modifyLast
Apply a function to the last element, creating a new ReadonlyNonEmptyArray
.
Signature
export declare const modifyLast: <A>(f: Endomorphism<A>) => (as: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<A>
Details
- Added in 0.1.0