title | nav_order | parent |
---|---|---|
Record.ts |
88 |
Modules |
Added in v2.0.0
- Compactable
- Filterable
- Foldable
- Witherable
- combinators
- instances
- Compactable
- Filterable
- FilterableWithIndex
- Functor
- FunctorWithIndex
- URI
- URI (type alias)
- getDifferenceMagma
- getEq
- getFoldable
- getFoldableWithIndex
- getIntersectionSemigroup
- getMonoid
- getShow
- getTraversable
- getTraversableWithIndex
- getUnionMonoid
- getUnionSemigroup
- getWitherable
FoldableWithIndexFoldableTraversableWithIndexTraversableWitherablerecord
- utils
- collect
- deleteAt
- elem
- every
- filterCollect
- filterMapWithIndex
- filterWithIndex
- foldMapWithIndex
- fromFoldable
- fromFoldableMap
- has
- isEmpty
- isSubrecord
- keys
- lookup
- map
- mapWithIndex
- modifyAt
- partitionMapWithIndex
- partitionWithIndex
- pop
- reduceRightWithIndex
- reduceWithIndex
- sequence
- singleton
- size
- some
- toArray
- toUnfoldable
- traverse
- traverseWithIndex
- updateAt
emptyhasOwnProperty (function)insertAt
Signature
export declare const compact: <A>(fa: Record<string, Option<A>>) => Record<string, A>
Added in v2.0.0
Signature
export declare const separate: <A, B>(
fa: Record<string, Either<A, B>>
) => Separated<Record<string, A>, Record<string, B>>
Added in v2.0.0
Signature
export declare const filter: {
<A, B extends A>(refinement: Refinement<A, B>): (fa: Record<string, A>) => Record<string, B>
<A>(predicate: Predicate<A>): <B extends A>(fb: Record<string, B>) => Record<string, B>
<A>(predicate: Predicate<A>): (fa: Record<string, A>) => Record<string, A>
}
Added in v2.0.0
Signature
export declare const filterMap: <A, B>(f: (a: A) => Option<B>) => (fa: Record<string, A>) => Record<string, B>
Added in v2.0.0
Signature
export declare const partition: {
<A, B extends A>(refinement: Refinement<A, B>): (
fa: Record<string, A>
) => Separated<Record<string, A>, Record<string, B>>
<A>(predicate: Predicate<A>): <B extends A>(fb: Record<string, B>) => Separated<Record<string, B>, Record<string, B>>
<A>(predicate: Predicate<A>): (fa: Record<string, A>) => Separated<Record<string, A>, Record<string, A>>
}
Added in v2.0.0
Signature
export declare const partitionMap: <A, B, C>(
f: (a: A) => Either<B, C>
) => (fa: Record<string, A>) => Separated<Record<string, B>, Record<string, C>>
Added in v2.0.0
Signature
export declare function foldMap(
O: Ord<string>
): <M>(M: Monoid<M>) => <A>(f: (a: A) => M) => (fa: Record<string, A>) => M
export declare function foldMap<M>(M: Monoid<M>): <A>(f: (a: A) => M) => (fa: Record<string, A>) => M
Added in v2.0.0
Signature
export declare function reduce(O: Ord<string>): <A, B>(b: B, f: (b: B, a: A) => B) => (fa: Record<string, A>) => B
export declare function reduce<A, B>(b: B, f: (b: B, a: A) => B): (fa: Record<string, A>) => B
Added in v2.0.0
Signature
export declare function reduceRight(O: Ord<string>): <A, B>(b: B, f: (a: A, b: B) => B) => (fa: Record<string, A>) => B
export declare function reduceRight<A, B>(b: B, f: (a: A, b: B) => B): (fa: Record<string, A>) => B
Added in v2.0.0
Signature
export declare const wilt: PipeableWilt1<'Record'>
Added in v2.6.5
Signature
export declare const wither: PipeableWither1<'Record'>
Added in v2.6.5
Signature
export declare const difference: <A>(second: Record<string, A>) => (first: Record<string, A>) => Record<string, A>
Added in v2.11.0
Derivable from Functor
.
Signature
export declare const flap: <A>(a: A) => <B>(fab: Record<string, (a: A) => B>) => Record<string, B>
Added in v2.10.0
Signature
export declare const intersection: <A>(
M: Magma<A>
) => (second: Record<string, A>) => (first: Record<string, A>) => Record<string, A>
Added in v2.11.0
Signature
export declare const union: <A>(
M: Magma<A>
) => (second: Record<string, A>) => (first: Record<string, A>) => Record<string, A>
Added in v2.11.0
Insert or replace a key/value pair in a Record
.
Signature
export declare const upsertAt: <A>(k: string, a: A) => (r: Record<string, A>) => Record<string, A>
Added in v2.10.0
Signature
export declare const Compactable: Compactable1<'Record'>
Added in v2.7.0
Signature
export declare const Filterable: Filterable1<'Record'>
Added in v2.7.0
Signature
export declare const FilterableWithIndex: FilterableWithIndex1<'Record', string>
Added in v2.7.0
Signature
export declare const Functor: Functor1<'Record'>
Added in v2.7.0
Signature
export declare const FunctorWithIndex: FunctorWithIndex1<'Record', string>
Added in v2.7.0
Signature
export declare const URI: 'Record'
Added in v2.0.0
Signature
export type URI = typeof URI
Added in v2.0.0
Signature
export declare const getDifferenceMagma: <A>() => Magma<Record<string, A>>
Added in v2.11.0
Signature
export declare const getEq: <K extends string, A>(E: Eq<A>) => Eq<Record<K, A>>
Added in v2.0.0
Signature
export declare const getFoldable: (O: Ord<string>) => Foldable1<URI>
Added in v2.11.0
Signature
export declare const getFoldableWithIndex: (O: Ord<string>) => FoldableWithIndex1<URI, string>
Added in v2.11.0
Signature
export declare const getIntersectionSemigroup: <A>(S: Semigroup<A>) => Semigroup<Record<string, A>>
Added in v2.11.0
Returns a Monoid
instance for Record
s given a Semigroup
instance for their values.
Signature
export declare const getMonoid: <K extends string, A>(S: Semigroup<A>) => Monoid<Record<K, A>>
Example
import { SemigroupSum } from 'fp-ts/number'
import { getMonoid } from 'fp-ts/Record'
const M = getMonoid(SemigroupSum)
assert.deepStrictEqual(M.concat({ foo: 123 }, { foo: 456 }), { foo: 579 })
Added in v2.0.0
Signature
export declare function getShow(O: Ord<string>): <A>(S: Show<A>) => Show<Record<string, A>>
export declare function getShow<A>(S: Show<A>): Show<Record<string, A>>
Added in v2.0.0
Signature
export declare const getTraversable: (O: Ord<string>) => Traversable1<URI>
Added in v2.11.0
Signature
export declare const getTraversableWithIndex: (O: Ord<string>) => TraversableWithIndex1<URI, string>
Added in v2.11.0
Signature
export declare const getUnionMonoid: <A>(S: Semigroup<A>) => Monoid<Record<string, A>>
Added in v2.11.0
Signature
export declare const getUnionSemigroup: <A>(S: Semigroup<A>) => Semigroup<Record<string, A>>
Added in v2.11.0
Signature
export declare const getWitherable: (O: Ord<string>) => Witherable1<URI>
Added in v2.11.0
Use getFoldableWithIndex
instead.
Signature
export declare const FoldableWithIndex: FoldableWithIndex1<'Record', string>
Added in v2.7.0
Use getFoldable
instead.
Signature
export declare const Foldable: Foldable1<'Record'>
Added in v2.7.0
Use the getTraversableWithIndex
instead.
Signature
export declare const TraversableWithIndex: TraversableWithIndex1<'Record', string>
Added in v2.7.0
Use getTraversable
instead.
Signature
export declare const Traversable: Traversable1<'Record'>
Added in v2.7.0
Use getWitherable
instead.
Signature
export declare const Witherable: Witherable1<'Record'>
Added in v2.7.0
Use small, specific instances instead.
Signature
export declare const record: FunctorWithIndex1<'Record', string> &
FoldableWithIndex1<'Record', string> &
FilterableWithIndex1<'Record', string> &
TraversableWithIndex1<'Record', string> &
Witherable1<'Record'>
Added in v2.0.0
Map a Record
into an Array
.
Signature
export declare function collect(
O: Ord<string>
): <K extends string, A, B>(f: (k: K, a: A) => B) => (r: Record<K, A>) => Array<B>
export declare function collect<K extends string, A, B>(f: (k: K, a: A) => B): (r: Record<K, A>) => Array<B>
Example
import { collect } from 'fp-ts/Record'
import { Ord } from 'fp-ts/string'
const x: { readonly a: string; readonly b: boolean } = { a: 'c', b: false }
assert.deepStrictEqual(collect(Ord)((key, val) => ({ key: key, value: val }))(x), [
{ key: 'a', value: 'c' },
{ key: 'b', value: false },
])
Added in v2.0.0
Delete a key and value from a Record
.
Signature
export declare function deleteAt<K extends string>(
k: K
): <KS extends string, A>(r: Record<KS, A>) => Record<string extends K ? string : Exclude<KS, K>, A>
Added in v2.0.0
Signature
export declare const elem: <A>(
E: Eq<A>
) => { (a: A): (fa: Record<string, A>) => boolean; (a: A, fa: Record<string, A>): boolean }
Added in v2.0.0
Signature
export declare const every: <A>(predicate: Predicate<A>) => (r: Record<string, A>) => boolean
Added in v2.0.0
Map a Record
into an Array
passing a key/value pair to the iterating
function and filtering out undesired results. The keys in the resulting
record are sorted according to the passed instance of Ord<string>
.
Signature
export declare const filterCollect: (
O: Ord<string>
) => <K extends string, A, B>(f: (k: K, a: A) => Option<B>) => (r: Record<K, A>) => B[]
Example
import { none, some } from 'fp-ts/Option'
import { filterCollect } from 'fp-ts/Record'
import { Ord } from 'fp-ts/string'
const x: { readonly a: string; readonly b: boolean; readonly c: number } = { a: 'c', b: false, c: 123 }
assert.deepStrictEqual(
filterCollect(Ord)((key, value) => (typeof value === 'boolean' ? none : some({ key, value })))(x),
[
{ key: 'a', value: 'c' },
{ key: 'c', value: 123 },
]
)
Added in v2.12.0
Signature
export declare const filterMapWithIndex: <K extends string, A, B>(
f: (key: K, a: A) => Option<B>
) => (fa: Record<K, A>) => Record<string, B>
Added in v2.0.0
Signature
export declare function filterWithIndex<K extends string, A, B extends A>(
refinementWithIndex: RefinementWithIndex<K, A, B>
): (fa: Record<K, A>) => Record<string, B>
export declare function filterWithIndex<K extends string, A>(
predicateWithIndex: PredicateWithIndex<K, A>
): <B extends A>(fb: Record<K, B>) => Record<string, B>
export declare function filterWithIndex<K extends string, A>(
predicateWithIndex: PredicateWithIndex<K, A>
): (fa: Record<K, A>) => Record<string, A>
Added in v2.0.0
Signature
export declare function foldMapWithIndex(
O: Ord<string>
): <M>(M: Monoid<M>) => <K extends string, A>(f: (k: K, a: A) => M) => (fa: Record<K, A>) => M
export declare function foldMapWithIndex<M>(
M: Monoid<M>
): <K extends string, A>(f: (k: K, a: A) => M) => (fa: Record<K, A>) => M
Added in v2.0.0
Create a Record
from a foldable collection of key/value pairs, using the
specified Magma
to combine values for duplicate keys.
Signature
export declare function fromFoldable<F extends URIS3, A>(
M: Magma<A>,
F: Foldable3<F>
): <R, E>(fka: Kind3<F, R, E, [string, A]>) => Record<string, A>
export declare function fromFoldable<F extends URIS2, A>(
M: Magma<A>,
F: Foldable2<F>
): <E>(fka: Kind2<F, E, [string, A]>) => Record<string, A>
export declare function fromFoldable<F extends URIS, A>(
M: Magma<A>,
F: Foldable1<F>
): (fka: Kind<F, [string, A]>) => Record<string, A>
export declare function fromFoldable<F, A>(
M: Magma<A>,
F: FoldableHKT<F>
): (fka: HKT<F, [string, A]>) => Record<string, A>
Added in v2.0.0
Create a Record
from a foldable collection using the specified functions to
- map to key/value pairs
- combine values for duplicate keys.
Signature
export declare function fromFoldableMap<F extends URIS3, B>(
M: Magma<B>,
F: Foldable3<F>
): <R, E, A>(fa: Kind3<F, R, E, A>, f: (a: A) => [string, B]) => Record<string, B>
export declare function fromFoldableMap<F extends URIS2, B>(
M: Magma<B>,
F: Foldable2<F>
): <E, A>(fa: Kind2<F, E, A>, f: (a: A) => [string, B]) => Record<string, B>
export declare function fromFoldableMap<F extends URIS, B>(
M: Magma<B>,
F: Foldable1<F>
): <A>(fa: Kind<F, A>, f: (a: A) => [string, B]) => Record<string, B>
export declare function fromFoldableMap<F, B>(
M: Magma<B>,
F: FoldableHKT<F>
): <A>(fa: HKT<F, A>, f: (a: A) => [string, B]) => Record<string, B>
Example
import { last } from 'fp-ts/Semigroup'
import { Foldable, zip } from 'fp-ts/Array'
import { identity } from 'fp-ts/function'
import { fromFoldableMap } from 'fp-ts/Record'
export const zipObject = <K extends string, A>(keys: Array<K>, values: Array<A>): Record<K, A> =>
fromFoldableMap(last<A>(), Foldable)(zip(keys, values), identity)
assert.deepStrictEqual(zipObject(['a', 'b'], [1, 2, 3]), { a: 1, b: 2 })
interface User {
readonly id: string
readonly name: string
}
const users: Array<User> = [
{ id: 'id1', name: 'name1' },
{ id: 'id2', name: 'name2' },
{ id: 'id1', name: 'name3' },
]
assert.deepStrictEqual(
fromFoldableMap(last<User>(), Foldable)(users, (user) => [user.id, user]),
{
id1: { id: 'id1', name: 'name3' },
id2: { id: 'id2', name: 'name2' },
}
)
Added in v2.0.0
Test whether or not a key exists in a Record
.
Note. This function is not pipeable because is a Refinement
.
Signature
export declare const has: <K extends string>(k: string, r: Record<K, unknown>) => k is K
Added in v2.10.0
Test whether a Record
is empty.
Signature
export declare const isEmpty: <A>(r: Record<string, A>) => boolean
Added in v2.0.0
Test whether one Record
contains all of the keys and values contained in another Record
.
Signature
export declare const isSubrecord: <A>(
E: Eq<A>
) => {
(that: Record<string, A>): (me: Record<string, A>) => boolean
(me: Record<string, A>, that: Record<string, A>): boolean
}
Added in v2.0.0
Signature
export declare const keys: <K extends string>(r: Record<K, unknown>) => K[]
Added in v2.0.0
Lookup the value for a key in a Record
.
Signature
export declare const lookup: {
(k: string): <A>(r: Record<string, A>) => Option<A>
<A>(k: string, r: Record<string, A>): Option<A>
}
Added in v2.0.0
Map a Record
passing the values to the iterating function.
Signature
export declare const map: <A, B>(f: (a: A) => B) => <K extends string>(fa: Record<K, A>) => Record<K, B>
Added in v2.0.0
Map a Record
passing the keys to the iterating function.
Signature
export declare const mapWithIndex: <K extends string, A, B>(f: (k: K, a: A) => B) => (fa: Record<K, A>) => Record<K, B>
Added in v2.0.0
Signature
export declare const modifyAt: <A>(
k: string,
f: (a: A) => A
) => <K extends string>(r: Record<K, A>) => Option<Record<K, A>>
Added in v2.0.0
Signature
export declare const partitionMapWithIndex: <K extends string, A, B, C>(
f: (key: K, a: A) => Either<B, C>
) => (fa: Record<K, A>) => Separated<Record<string, B>, Record<string, C>>
Added in v2.0.0
Signature
export declare function partitionWithIndex<K extends string, A, B extends A>(
refinementWithIndex: RefinementWithIndex<K, A, B>
): (fa: Record<K, A>) => Separated<Record<string, A>, Record<string, B>>
export declare function partitionWithIndex<K extends string, A>(
predicateWithIndex: PredicateWithIndex<K, A>
): <B extends A>(fb: Record<K, B>) => Separated<Record<string, B>, Record<string, B>>
export declare function partitionWithIndex<K extends string, A>(
predicateWithIndex: PredicateWithIndex<K, A>
): (fa: Record<K, A>) => Separated<Record<string, A>, Record<string, A>>
Added in v2.0.0
Delete a key and value from a Record
, returning the value as well as the subsequent Record
.
Signature
export declare function pop<K extends string>(
k: K
): <KS extends string, A>(r: Record<KS, A>) => Option<[A, Record<string extends K ? string : Exclude<KS, K>, A>]>
Added in v2.0.0
Signature
export declare function reduceRightWithIndex(
O: Ord<string>
): <K extends string, A, B>(b: B, f: (k: K, a: A, b: B) => B) => (fa: Record<K, A>) => B
export declare function reduceRightWithIndex<K extends string, A, B>(
b: B,
f: (k: K, a: A, b: B) => B
): (fa: Record<K, A>) => B
Added in v2.0.0
Signature
export declare function reduceWithIndex(
O: Ord<string>
): <K extends string, A, B>(b: B, f: (k: K, b: B, a: A) => B) => (fa: Record<K, A>) => B
export declare function reduceWithIndex<K extends string, A, B>(
b: B,
f: (k: K, b: B, a: A) => B
): (fa: Record<K, A>) => B
Added in v2.0.0
Signature
export declare function sequence<F extends URIS3>(
F: Applicative3<F>
): <K extends string, R, E, A>(ta: Record<K, Kind3<F, R, E, A>>) => Kind3<F, R, E, Record<K, A>>
export declare function sequence<F extends URIS3, E>(
F: Applicative3C<F, E>
): <K extends string, R, A>(ta: Record<K, Kind3<F, R, E, A>>) => Kind3<F, R, E, Record<K, A>>
export declare function sequence<F extends URIS2>(
F: Applicative2<F>
): <K extends string, E, A>(ta: Record<K, Kind2<F, E, A>>) => Kind2<F, E, Record<K, A>>
export declare function sequence<F extends URIS2, E>(
F: Applicative2C<F, E>
): <K extends string, A>(ta: Record<K, Kind2<F, E, A>>) => Kind2<F, E, Record<K, A>>
export declare function sequence<F extends URIS>(
F: Applicative1<F>
): <K extends string, A>(ta: Record<K, Kind<F, A>>) => Kind<F, Record<K, A>>
export declare function sequence<F>(
F: Applicative<F>
): <K extends string, A>(ta: Record<K, HKT<F, A>>) => HKT<F, Record<K, A>>
Added in v2.0.0
Create a Record
with one key/value pair.
Signature
export declare const singleton: <A>(k: string, a: A) => Record<string, A>
Added in v2.0.0
Calculate the number of key/value pairs in a Record
.
Signature
export declare const size: <A>(r: Record<string, A>) => number
Added in v2.0.0
Signature
export declare const some: <A>(predicate: (a: A) => boolean) => (r: Record<string, A>) => boolean
Added in v2.0.0
Get a sorted Array
of the key/value pairs contained in a Record
.
Signature
export declare const toArray: <K extends string, A>(r: Record<K, A>) => [K, A][]
Added in v2.0.0
Unfolds a Record
into a list of key/value pairs.
Signature
export declare function toUnfoldable<F extends URIS>(
U: Unfoldable1<F>
): <K extends string, A>(r: Record<K, A>) => Kind<F, [K, A]>
export declare function toUnfoldable<F>(U: Unfoldable<F>): <K extends string, A>(r: Record<K, A>) => HKT<F, [K, A]>
Added in v2.0.0
Signature
export declare function traverse<F extends URIS3>(
F: Applicative3<F>
): <R, E, A, B>(f: (a: A) => Kind3<F, R, E, B>) => <K extends string>(ta: Record<K, A>) => Kind3<F, R, E, Record<K, B>>
export declare function traverse<F extends URIS3, E>(
F: Applicative3C<F, E>
): <R, A, B>(f: (a: A) => Kind3<F, R, E, B>) => <K extends string>(ta: Record<K, A>) => Kind3<F, R, E, Record<K, B>>
export declare function traverse<F extends URIS2>(
F: Applicative2<F>
): <E, A, B>(f: (a: A) => Kind2<F, E, B>) => <K extends string>(ta: Record<K, A>) => Kind2<F, E, Record<K, B>>
export declare function traverse<F extends URIS2, E>(
F: Applicative2C<F, E>
): <A, B>(f: (a: A) => Kind2<F, E, B>) => <K extends string>(ta: Record<K, A>) => Kind2<F, E, Record<K, B>>
export declare function traverse<F extends URIS>(
F: Applicative1<F>
): <A, B>(f: (a: A) => Kind<F, B>) => <K extends string>(ta: Record<K, A>) => Kind<F, Record<K, B>>
export declare function traverse<F>(
F: Applicative<F>
): <A, B>(f: (a: A) => HKT<F, B>) => <K extends string>(ta: Record<K, A>) => HKT<F, Record<K, B>>
Added in v2.0.0
Signature
export declare function traverseWithIndex<F extends URIS3>(
F: Applicative3<F>
): <K extends string, R, E, A, B>(
f: (k: K, a: A) => Kind3<F, R, E, B>
) => (ta: Record<K, A>) => Kind3<F, R, E, Record<K, B>>
export declare function traverseWithIndex<F extends URIS3, E>(
F: Applicative3C<F, E>
): <K extends string, R, A, B>(
f: (k: K, a: A) => Kind3<F, R, E, B>
) => (ta: Record<K, A>) => Kind3<F, R, E, Record<K, B>>
export declare function traverseWithIndex<F extends URIS2>(
F: Applicative2<F>
): <K extends string, E, A, B>(f: (k: K, a: A) => Kind2<F, E, B>) => (ta: Record<K, A>) => Kind2<F, E, Record<K, B>>
export declare function traverseWithIndex<F extends URIS2, E>(
F: Applicative2C<F, E>
): <K extends string, A, B>(f: (k: K, a: A) => Kind2<F, E, B>) => (ta: Record<K, A>) => Kind2<F, E, Record<K, B>>
export declare function traverseWithIndex<F extends URIS>(
F: Applicative1<F>
): <K extends string, A, B>(f: (k: K, a: A) => Kind<F, B>) => (ta: Record<K, A>) => Kind<F, Record<K, B>>
export declare function traverseWithIndex<F>(
F: Applicative<F>
): <K extends string, A, B>(f: (k: K, a: A) => HKT<F, B>) => (ta: Record<K, A>) => HKT<F, Record<K, B>>
Added in v2.0.0
Signature
export declare const updateAt: <A>(k: string, a: A) => <K extends string>(r: Record<K, A>) => Option<Record<K, A>>
Added in v2.0.0
Use a new {}
instead.
Signature
export declare const empty: Record<string, never>
Added in v2.0.0
Use has
instead.
Signature
export declare const hasOwnProperty: <K extends string>(k: string, r: Record<K, unknown>) => k is K
Added in v2.0.0
Use upsertAt
instead.
Signature
export declare const insertAt: <A>(k: string, a: A) => (r: Record<string, A>) => Record<string, A>
Added in v2.0.0