(key: Key, value: Value)
| 15859 | * @since 3.10.0 |
| 15860 | */ |
| 15861 | export 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 |
nothing calls this directly
no test coverage detected