Extract

Pulls a nested property or field out of a Memory object into its own Memory slot. Uses reflection to find the first public property or field of type TOut on the TIn object.

Signatures

Extract<TIn, TOut>()

Retrieves TIn from Memory, then extracts a TOut property/field from it.

public Monad<TInput, TReturn> Extract<TIn, TOut>()

Extract&lt;TIn, TOut&gt;(TIn input)

Extracts a TOut property/field from the provided TIn object.

public Monad<TInput, TReturn> Extract<TIn, TOut>(TIn input)

Type Parameters

Type ParameterDescription
TInThe source type to extract from. Must have a public property or field of type TOut.
TOutThe target type to extract and store in Memory.

Parameters

ParameterTypeRequiredDescription
inputTInNoThe source object (second overload only). If omitted, TIn is retrieved from Memory.

Returns

Monad<TInput, TReturn> — the train instance, for fluent chaining.

Example

public record OrderInput(string CustomerId, OrderDetails Details);
public record OrderDetails(string ItemId, int Quantity);
 
protected override async Task<Either<Exception, OrderResult>> RunInternal(OrderInput input)
{
    return Activate(input)
        .Extract<OrderInput, OrderDetails>()  // Pulls OrderDetails out of OrderInput
        .Chain<ProcessOrder>()                // ProcessOrder receives OrderDetails from Memory
        .Resolve();
}

Behavior

  1. Looks for the first public property of type TOut on TIn.
  2. If not found, looks for the first public field of type TOut.
  3. If found, stores the value in Memory under typeof(TOut).
  4. If not found or null, sets the exception: "Could not find non-null value of type: ({TOut}) in properties or fields for ({TIn}). Is it public?"

Remarks

  • Only the first matching property/field is extracted. If TIn has multiple properties of type TOut, only the first one found is used.
  • Properties and fields must be public to be discoverable.
  • If TIn is not found in Memory (parameterless overload), sets the exception: "Could not find type: ({TIn})."