Class: Plumb::ArrayClass::FilteredArray

Inherits:
Plumb::ArrayClass show all
Defined in:
lib/plumb/array_class.rb

Overview

Same element type as an ArrayClass, but drops invalid elements instead of rejecting the whole Array. Being an ArrayClass is what keeps it rewritable: a visitor — or a Codec — that maps the element type rebuilds a FilteredArray, not a plain one. @see HashMap::FilteredHashMap, the same arrangement for maps.

Direct Known Subclasses

ConcurrentFilteredArray

Instance Attribute Summary

Attributes inherited from Plumb::ArrayClass

#children

Instance Method Summary collapse

Methods inherited from Plumb::ArrayClass

#concurrent, #filtered, #initialize, #of, #output_type, #with_children

Methods included from CovariantFusion

#fuse_with

Methods included from Composable

#&, #/, #>>, #[], #absorb_input, #absorb_output, #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, #where, #with, wrap, #|

Methods included from Callable

#parse, #resolve

Constructor Details

This class inherits a constructor from Plumb::ArrayClass

Instance Method Details

#accepted_typeObject

Lenient: it never rejects an Array, so as a #>> consumer it accepts any enumerable — without this Types::Array >> Array[String].filtered is an illegal narrowing.



155
# File 'lib/plumb/array_class.rb', line 155

def accepted_type = Types::Each

#call(result) ⇒ Object



161
162
163
164
165
# File 'lib/plumb/array_class.rb', line 161

def call(result)
  return result.invalid!(errors: 'is not an Array') unless ::Array === result.value

  result.valid!(valid_elements(result.value))
end

#streamObject

Array[T].filtered.stream IS Array[T].stream.filtered — a filtered Stream drops the same elements, lazily.



159
# File 'lib/plumb/array_class.rb', line 159

def stream = super.filtered

#value_preserving?Boolean

It drops elements, so it changes the value whatever its element type does.

Returns:

  • (Boolean)


150
# File 'lib/plumb/array_class.rb', line 150

def value_preserving? = false