Skip to content

Commit 830bfe4

Browse files
transclaude
andcommitted
Rename Kernel#tee to Kernel#functor
The method returns a Functor, so name it what it is. The tee/tap metaphors didn't quite fit — this isn't forking data or tapping into a stream, it's wrapping self in a Functor proxy. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8223fb2 commit 830bfe4

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

HISTORY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Changes:
1717
* Add `Binding#caller_locations`.
1818
* Add `Range.intersection` and `Range#intersection` for finding the shared
1919
region of multiple ranges. Works with any comparable type.
20-
* Add `Kernel#tee` — block-less method chaining via Functor, replaces `tap` override.
20+
* Add `Kernel#functor` — block-less method chaining via Functor, replaces `tap` override.
2121
* Rename `Hash#to_proc` to `Hash#setter` (avoids clash with Ruby 2.3's `Hash#to_proc`
2222
which does key lookup; Facets' version does attribute assignment).
2323
* Consolidate `Array#arrange` and `Array#to_ranges`; `to_ranges` is now primary,

lib/core/facets/kernel.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
require_relative 'kernel/silence.rb'
5757
require_relative 'kernel/silence_warnings.rb'
5858
require_relative 'kernel/super_method.rb'
59+
require_relative 'kernel/functor.rb'
5960
require_relative 'kernel/tap.rb'
6061
require_relative 'kernel/temporarily.rb'
6162
#require_relative 'kernel/trap_chain.rb' # uncommon

lib/core/facets/kernel/functor.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require 'facets/functor'
2+
3+
module Kernel
4+
5+
# Returns a Functor that intercepts method calls, forwards
6+
# them to self for side effects, and returns self. This is like
7+
# a block-less version of #tap that allows method chaining.
8+
#
9+
# YAML.functor.load_file('foo.yml').load_file('bar.yml')
10+
#
11+
12+
def functor
13+
Functor.new{ |op,*a,&b| self.send(op, *a, &b); self }
14+
end
15+
16+
end

lib/core/facets/kernel/tap.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Facets no longer overrides Kernel#tap. Use Kernel#tee instead
1+
# Facets no longer overrides Kernel#tap. Use Kernel#functor instead
22
# for the block-less Functor form.
3-
require 'facets/kernel/tee'
3+
require 'facets/kernel/functor'

lib/core/facets/kernel/tee.rb

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,2 @@
1-
require 'facets/functor'
2-
3-
module Kernel
4-
5-
# Returns a Functor that intercepts method calls, forwards
6-
# them to self for side effects, and returns self. This is like
7-
# a block-less version of #tap that allows method chaining.
8-
#
9-
# YAML.tee.load_file('foo.yml').load_file('bar.yml')
10-
#
11-
12-
def tee
13-
Functor.new{ |op,*a,&b| self.send(op, *a, &b); self }
14-
end
15-
16-
end
1+
# @deprecated Use Kernel#functor instead.
2+
require 'facets/kernel/functor'

0 commit comments

Comments
 (0)