Difference in Immediate Execution Between Effect.match and Either.match

Hey,

Why doesn't Effect.match run immediately while Either.match does on Effect returned by Schema.decode? Also why is the return type of decoding is an Effect instead of Either?

import { Effect, Either, Schema } from "effect";

const Person = Schema.Struct({
  name: Schema.String,
  age: Schema.Number,
});

const personEffect = Schema.decode(Person)({ age: 32, name: "John" });

// Runs immediately
personEffect.pipe(
  Either.match({
    onLeft: (error) => {
      console.error("Decoding failed:", error);
    },
    onRight: (person) => {
      console.log("Decoding succeeded:", person);
    },
  }),
);

// Does not run immediately, but requires something like Effect.runSync
personEffect.pipe(
  Effect.match({
    onFailure: (error) => {
      console.error("Decoding failed:", error);
    },
    onSuccess: (person) => {
      console.log("Decoding succeeded:", person);
    },
  }),
);
Was this page helpful?