MCPcopy Create free account
hub / github.com/Effect-TS/effect / HashMap

Function HashMap

packages/effect/src/Schema.ts:15861–15902  ·  view source on GitHub ↗
(key: Key, value: Value)

Source from the content-addressed store, hash-verified

15859 * @since 3.10.0
15860 */
15861export function HashMap<Key extends Constraint, Value extends Constraint>(key: Key, value: Value): HashMap<Key, Value> {
15862 const schema = declareConstructor<
15863 HashMap_.HashMap<Key["Type"], Value["Type"]>,
15864 HashMap_.HashMap<Key["Encoded"], Value["Encoded"]>,
15865 HashMapIso<Key, Value>
15866 >()(
15867 [key, value],
15868 ([key, value]) => {
15869 const entries = ArraySchema(Tuple([key, value]))
15870 return (input, ast, options) => {
15871 if (HashMap_.isHashMap(input)) {
15872 return Effect.mapBothEager(
15873 SchemaParser.decodeUnknownEffect(entries)(HashMap_.toEntries(input), options),
15874 {
15875 onSuccess: HashMap_.fromIterable,
15876 onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "entries", issue, input, options)
15877 }
15878 )
15879 }
15880 return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
15881 }
15882 },
15883 {
15884 representation: {
15885 id: "effect/schema/HashMap",
15886 payload: null
15887 },
15888 expected: "HashMap",
15889 toCodec: ([key, value]) => hashMapLink(ArraySchema(Tuple([key, value]))),
15890 toCodecArbitrary: ({ constraint, typeParameters: [key, value] }) =>
15891 hashMapLink(
15892 withArrayLengthConstraints(
15893 ArraySchema(Tuple([key, value])).check(isUniqueKey()),
15894 constraint?.minSize,
15895 constraint?.maxSize
15896 )
15897 ),
15898 toEquivalence: ([key, value]) => Equal.makeCompareMap(key, value)
15899 }
15900 )
15901 return make(schema.ast, { key, value })
15902}
15903
15904// -----------------------------------------------------------------------------
15905// HashSet schemas

Callers

nothing calls this directly

Calls 8

hashMapLinkFunction · 0.85
isUniqueKeyFunction · 0.85
declareConstructorFunction · 0.70
TupleFunction · 0.70
makeFunction · 0.70
failMethod · 0.65
checkMethod · 0.65

Tested by

no test coverage detected