From 2e11ce0c24b09219fd0dae035f6630d228379a30 Mon Sep 17 00:00:00 2001 From: thadeu Date: Mon, 16 Dec 2024 20:44:13 -0300 Subject: [PATCH] rename: Core::Value to Core::Stack --- lib/zx/core.rb | 2 +- lib/zx/core/and_then.rb | 2 +- lib/zx/core/{value.rb => stack.rb} | 12 ++++++------ lib/zx/result.rb | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) rename lib/zx/core/{value.rb => stack.rb} (79%) diff --git a/lib/zx/core.rb b/lib/zx/core.rb index 08359b5..e5c232f 100644 --- a/lib/zx/core.rb +++ b/lib/zx/core.rb @@ -5,5 +5,5 @@ module Core require_relative 'core/and_then' require_relative 'core/caller' require_relative 'core/match' - require_relative 'core/value' + require_relative 'core/stack' end diff --git a/lib/zx/core/and_then.rb b/lib/zx/core/and_then.rb index c9d8cf5..0176e59 100644 --- a/lib/zx/core/and_then.rb +++ b/lib/zx/core/and_then.rb @@ -14,7 +14,7 @@ def initialize(result) end def spawn!(&block) - lastly = Core::Value.last(result) + lastly = Core::Stack.last(result) success = result.success? type = result.type diff --git a/lib/zx/core/value.rb b/lib/zx/core/stack.rb similarity index 79% rename from lib/zx/core/value.rb rename to lib/zx/core/stack.rb index c56f6c1..063bf43 100644 --- a/lib/zx/core/value.rb +++ b/lib/zx/core/stack.rb @@ -2,7 +2,7 @@ module Zx module Core - class Value + class Stack def self.first(result) new.first(result) end @@ -15,25 +15,25 @@ def self.unwrap!(object) new.unwrap!(object) end - def self.stack(object) + def self.nodes(object) new.stack(object, []) end - def stack(object, list = []) + def nodes(object, list = []) if need_recursion? object list << object - stack(object.value, list) + nodes(object.value, list) end Array(list).flatten end def first(object) - Array(stack(object)).flatten.first + Array(nodes(object)).flatten.first end def last(object) - Array(stack(object)).flatten.last + Array(nodes(object)).flatten.last end def unwrap!(object) diff --git a/lib/zx/result.rb b/lib/zx/result.rb index df21405..741eb7c 100644 --- a/lib/zx/result.rb +++ b/lib/zx/result.rb @@ -41,11 +41,11 @@ def unwrap end def last - Core::Value.last(self) || self + Core::Stack.last(self) || self end def first - Core::Value.first(self) || self + Core::Stack.first(self) || self end def inspect