gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: nicer unions


From: gnunet
Subject: [taler-wallet-core] branch master updated: nicer unions
Date: Sat, 14 Dec 2019 18:00:07 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new 690bbfcf nicer unions
690bbfcf is described below

commit 690bbfcfd85ac63749c69eb6e29a7cc734b38d2c
Author: Florian Dold <address@hidden>
AuthorDate: Sat Dec 14 18:00:03 2019 +0100

    nicer unions
---
 src/util/codec-test.ts |  3 ++-
 src/util/codec.ts      | 12 ++++++++----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/util/codec-test.ts b/src/util/codec-test.ts
index 0d1ab560..640cd7c1 100644
--- a/src/util/codec-test.ts
+++ b/src/util/codec-test.ts
@@ -64,7 +64,8 @@ test("union", t => {
     .property("type", stringConstCodec("two"))
     .property("bar", stringCodec)
     .build("AltTwo");
-  const myUnionCodec: Codec<MyUnion> = unionCodec<MyUnion, "type">("type")
+  const myUnionCodec: Codec<MyUnion> = unionCodec<MyUnion>()
+    .discriminateOn("type")
     .alternative("one", altOneCodec)
     .alternative("two", altTwoCodec)
     .build<MyUnion>("MyUnion");
diff --git a/src/util/codec.ts b/src/util/codec.ts
index 78516183..a6fe7490 100644
--- a/src/util/codec.ts
+++ b/src/util/codec.ts
@@ -233,6 +233,12 @@ export function mapCodec<T>(innerCodec: Codec<T>): Codec<{ 
[x: string]: T }> {
   };
 }
 
+export class UnionCodecPreBuilder<T> {
+  discriminateOn<D extends keyof T>(discriminator: D): UnionCodecBuilder<T, D, 
never> {
+    return new UnionCodecBuilder<T, D, never>(discriminator);
+  }
+}
+
 /**
  * Return a builder for a codec that decodes an object with properties.
  */
@@ -240,8 +246,6 @@ export function objectCodec<T>(): ObjectCodecBuilder<T, {}> 
{
   return new ObjectCodecBuilder<T, {}>();
 }
 
-export function unionCodec<T, D extends keyof T>(
-  discriminator: D,
-): UnionCodecBuilder<T, D, never> {
-  return new UnionCodecBuilder<T, D, never>(discriminator);
+export function unionCodec<T>(): UnionCodecPreBuilder<T> {
+  return new UnionCodecPreBuilder<T>();
 }

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]