Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Usage

import * as fun from "https://raw.githubusercontent.com/baetheus/fun/main/record.ts";

ReadonlyRecord is a readonly product structure that operates like a Map. Keys are always strings and Key/Value pairs can be added and removed arbitrarily. The ReadonlyRecord type in fun favors immutability.

§Variables

FilterableRecord

The canonical implementation of Filterable for ReadonlyRecord. It contains the methods filter, filterMap, partition, and partitionMap.

FoldableRecord

The canonical implementation of Foldable for ReadonlyRecord. It contains the method fold.

MappableRecord

The canonical implementation of Mappable for ReadonlyRecord. It contains the method map.

TraversableRecord

The canonical implementation of Traversable for ReadonlyRecord. It contains the methods map, fold, and traverse.

§Functions

collapse

Collect all values in a ReadonlyRecord into a single value I by using a Combinable. This is effectively fold using a Combinable for the initial value and combination.

collect

Collect all values in a ReadonlyRecord into a single value I by using a Combinable and a mapping function from A to I. This is effectively fold using a Combinable for the initial value.

deleteAt

Remove the value and key at key from a ReadonlyRecord. If the record does not hold the key then no change is made and the original record is returned.

deleteAtWithValue

Remove the key from the ReadonlyRecord, returning a pair containing the new record and an Option containing the removed key value. If the record did not hold the specified key then this is a non-op and the return will be the original record and none.

entries

An alias of Object.entries

filter

Given a refinement or a predicate, filter a ReadonlyRecord by removing any values that do not match the predicate or refinement. ie. When the predicate/refinement return true a value is kept and when it returns false a value is removed.

filterMap

Given a function over the values in a ReadonlyArray returning an Option, return a function thatsimultaneously filters and maps over the values in a ReadonlyRecord.

fold

Collect all of the A values in a ReadonlyRecord into a single O value by the process of reduction. The order of key/value pairs in this reduction are stable and determined by ecmascript standard here.

getCombinableRecord
getComparableRecord
getInitializableRecord
getShowableRecord

Given a Showable for the inner values of a ReadonlyRecord, return an instance of Showable for ReadonlyRecord.

insert

Insert a value A into a ReadonlyRecord at the key location. If the value inserted has object equality with the current value in the record then no change is made and the original record is returned.

insertAt

Insert a value A into a ReadonlyRecord at the key location. If the value inserted has object equality with the current value in the record then no change is made and the original record is returned. This is the same function as insert but with the order of parameters swapped

isSubrecord

Given an instance of Comparable for the values in a ReadonlyRecord return a curried function second => first => boolean that returns true when first is a subrecord of second.

keys

An alias of Object.keys specific to ReadonlyRecord.

lookupAt

Lookup the value at key. Returns an Option, where None indicates that the record does not hold the key.

lookupWithKey

Lookup the value in a record at key and return an optional pair with the key and the value if the record holds the key. Returns None if the record does not hold the key.

map

Creates a new object with the same keys of ua. Values are transformed using fai.

modify

Modify a value A into a ReadonlyRecord at the key location. If the object does not hold the specified key then no change is made.

modifyAt

Modify a value A into a ReadonlyRecord at the key location. If the object does not hold the specified key then no change is made. This is the same function as modify with the order of parameters flipped.

omit

Omit specified keys from a record. Value-space implementation of the Omit utility type.

partition

Given a refinement or predicate, return a function that splits a ReadonlyRecord into a Pair of ReadonlyRecords, with the first record containing the values for which the predicate/refinement returned true and the second record containing the values for which the predicate/refinement returned false.

partitionMap

Given a function that takes an A and a key and returns an Either<J, K> return a function that simultaneously partitions and maps over the values in a ReadonlyRecord. This is the equivalent of first partitioning a ReadonlyRecord, and then using Pair's Bimap over both values in a Pair.

pick

Picks specified keys from a record. Value-space implemenuation of the Pick utility type.

sequence

Sequence over an ReadonlyRecord of type V, inverting the relationship between V and ReadonlyRecord. This function also keeps the indexed types of in each V at covariant position 0. In other words sequence over [Option, Option] becomes Option<[number, string]>.

traverse

Traverse a ReadonlyRecord, mapping each A into an algebraic data type V (so V), then collecting each I in V back into a ReadonlyRecord, ultimately returning V<ReadonlyRecord>. In more concrete terms this can take ReadonlyRecord<Option> and return Option<ReadonlyRecord> (or any other inner type.

update

Update a ReadonlyRecord at key with a value A. The record will only be updated if it already holds the specified key, otherwise no changes are made.

updateAt

Update a ReadonlyRecord at key with a value A. The record will only be updated if it already holds the specified key, otherwise no changes are made. This function does the same as update but has the parameters switched in order

§Interfaces

KindReadonlyRecord

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

§Type Aliases

AnyReadonlyRecord

A type used to constrain an input to a ReadonlyRecord with any values.

NonEmptyRecord

NonEmptyRecord is a bounding type that will return a type level never if the type value of R is either not a record is a record without any index or key values.

ReadonlyRecord

ReadonlyRecord is an alias of Readonly<Record<string, A>>. It's meant to be used wherever a Record can be used.

SequenceRecord

The return type of sequence for use with type inference.

TypeOf

Extract the inner type of a ReadonlyRecord