All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hydra.langs.json.decoding.Decoding Maven / Gradle / Ivy

package hydra.langs.json.decoding;

/**
 * Decoding functions for JSON data
 */
public interface Decoding {
  static  hydra.compute.Flow decodeString(hydra.json.Value v1) {
    return ((v1)).accept(new hydra.json.Value.PartialVisitor>() {
      @Override
      public hydra.compute.Flow otherwise(hydra.json.Value instance) {
        return hydra.lib.flows.Fail.apply("expected a string");
      }
      
      @Override
      public hydra.compute.Flow visit(hydra.json.Value.String_ instance) {
        return hydra.lib.flows.Pure.apply((instance.value));
      }
    });
  }
  
  static  hydra.compute.Flow decodeNumber(hydra.json.Value v1) {
    return ((v1)).accept(new hydra.json.Value.PartialVisitor>() {
      @Override
      public hydra.compute.Flow otherwise(hydra.json.Value instance) {
        return hydra.lib.flows.Fail.apply("expected a number");
      }
      
      @Override
      public hydra.compute.Flow visit(hydra.json.Value.Number_ instance) {
        return hydra.lib.flows.Pure.apply((instance.value));
      }
    });
  }
  
  static  hydra.compute.Flow decodeBoolean(hydra.json.Value v1) {
    return ((v1)).accept(new hydra.json.Value.PartialVisitor>() {
      @Override
      public hydra.compute.Flow otherwise(hydra.json.Value instance) {
        return hydra.lib.flows.Fail.apply("expected a boolean");
      }
      
      @Override
      public hydra.compute.Flow visit(hydra.json.Value.Boolean_ instance) {
        return hydra.lib.flows.Pure.apply((instance.value));
      }
    });
  }
  
  static  java.util.function.Function>> decodeArray(java.util.function.Function> decodeElem) {
    return (java.util.function.Function>>) (v1 -> ((v1)).accept(new hydra.json.Value.PartialVisitor>>() {
      @Override
      public hydra.compute.Flow> otherwise(hydra.json.Value instance) {
        return hydra.lib.flows.Fail.apply("expected an array");
      }
      
      @Override
      public hydra.compute.Flow> visit(hydra.json.Value.Array instance) {
        return hydra.lib.flows.MapList.apply(
          (decodeElem),
          (instance.value));
      }
    }));
  }
  
  static  hydra.compute.Flow> decodeObject(hydra.json.Value v1) {
    return ((v1)).accept(new hydra.json.Value.PartialVisitor>>() {
      @Override
      public hydra.compute.Flow> otherwise(hydra.json.Value instance) {
        return hydra.lib.flows.Fail.apply("expected an object");
      }
      
      @Override
      public hydra.compute.Flow> visit(hydra.json.Value.Object_ instance) {
        return hydra.lib.flows.Pure.apply((instance.value));
      }
    });
  }
  
  static  java.util.function.Function, hydra.compute.Flow>> decodeField(java.util.function.Function> decodeValue) {
    return (java.util.function.Function, hydra.compute.Flow>>) (name -> (java.util.function.Function, hydra.compute.Flow>) (m -> hydra.lib.flows.Bind.apply(
      ((hydra.langs.json.decoding.Decoding.decodeOptionalField((decodeValue))).apply((name))).apply((m)),
      (java.util.function.Function, hydra.compute.Flow>) (v1 -> (((v1)).map((java.util.function.Function>) (s0 -> hydra.lib.flows.Pure.apply((s0))))).orElse(hydra.lib.flows.Fail.apply(hydra.lib.strings.Cat.apply(java.util.Arrays.asList(
        "missing field: ",
        (name)))))))));
  }
  
  static  java.util.function.Function, hydra.compute.Flow>>> decodeOptionalField(java.util.function.Function> decodeValue) {
    return (java.util.function.Function, hydra.compute.Flow>>>) (name -> (java.util.function.Function, hydra.compute.Flow>>) (m -> ((hydra.lib.maps.Lookup.apply(
      (name),
      (m))).map((java.util.function.Function>>) (v -> hydra.lib.flows.Map.apply(
      (java.util.function.Function>) (x -> java.util.Optional.of((x))),
      ((decodeValue)).apply((v)))))).orElse(hydra.lib.flows.Pure.apply(java.util.Optional.empty()))));
  }
}