Class: Plumb::GuaranteedFunction

Inherits:
Function
  • Object
show all
Defined in:
lib/plumb/function.rb

Overview

A Function whose output check is known at build time to be redundant, so it is simply not run. Two ways to earn that: the proc provably produces output_type (eg. a :to_i coercion always yields an Integer), or the output_type is Any, which nothing can fail — the opaque case, see Function.opaque. Choosing the class at build time means #call carries no per-call guaranteed? branch — the check is simply absent. It inherits Function's node_name (:function) and is_a?(Function), so visitors, JSON-schema, subtyping and the decorator treat it as a Function; only the produced value's output re-validation is dropped. @output_type is still kept as metadata (inference / JSON schema / subtyping).

Instance Attribute Summary

Attributes inherited from Function

#children, #fn, #identity, #input_type, #output_type

Instance Method Summary collapse

Methods inherited from Function

#==, [], #absorb_input, #absorb_output, #fuse_with, #initialize, opaque, #standard_call?, #with_children, #wraps_callable?

Methods included from TypedStep

#accepted_type, #fusable_step?, #opaque?, #standard_call?, #subtype_identity

Methods included from Composable

#&, #/, #>>, #[], #absorb_input, #absorb_output, #accepted_type, #as_node, #build, #check, #children, #defer, #fusable_step?, #fuse_with, #generate, #idempotent?, included, #input_type, #invalid, #invoke, #match, #metadata, #not, #output_type, #pipeline, #policy, resolve_operand, #static, #subtype_identity, #to_json_schema, #to_mermaid, #to_plumb_type, #to_s, #transform, #value, #value_preserving?, #where, #with, wrap, #|

Methods included from Callable

#parse, #resolve

Constructor Details

This class inherits a constructor from Plumb::Function

Instance Method Details

#call(result) ⇒ Object



339
340
341
# File 'lib/plumb/function.rb', line 339

def call(result)
  result.map(@input_type).map(@fn)
end

#checks_output?Boolean

The whole point of the class: no output check runs, so a seam has none to drop here. @see Plumb::TypedStep#checks_output?

Returns:

  • (Boolean)


345
# File 'lib/plumb/function.rb', line 345

def checks_output? = false