| call | -> | __call__ |
| call | -> | [] |
| call | -> | __call__ |
| call | -> | [] |
| call | -> | __call__ |
| call | -> | [] |
| call | -> | __call__ |
| call | -> | [] |
C++ TR1 style bind use _#{n} for placeholders
_1 => 1st arg _2 => 2nd arg ...and so on
# File lib/ludy/proc/bind.rb, line 8
8: def bind *args
9: lambda{ |*new_args|
10: self[*(args.map{ |arg|
11: if (arg.kind_of? Symbol) && arg.to_s =~ /^_(\d+)$/
12: # is placeholder
13: new_args[$1.to_i-1]
14: else
15: # is not placeholder
16: arg
17: end
18: } + new_args).first(self.arity)]
19: }
20: end
C++ TR1 style bind use _#{n} for placeholders
_1 => 1st arg _2 => 2nd arg ...and so on
# File lib/ludy/proc/bind.rb, line 8
8: def bind *args
9: lambda{ |*new_args|
10: self[*(args.map{ |arg|
11: if (arg.kind_of? Symbol) && arg.to_s =~ /^_(\d+)$/
12: # is placeholder
13: new_args[$1.to_i-1]
14: else
15: # is not placeholder
16: arg
17: end
18: } + new_args).first(self.arity)]
19: }
20: end
C++ TR1 style bind use _#{n} for placeholders
_1 => 1st arg _2 => 2nd arg ...and so on
# File lib/ludy/proc/bind.rb, line 8
8: def bind *args
9: lambda{ |*new_args|
10: self[*(args.map{ |arg|
11: if (arg.kind_of? Symbol) && arg.to_s =~ /^_(\d+)$/
12: # is placeholder
13: new_args[$1.to_i-1]
14: else
15: # is not placeholder
16: arg
17: end
18: } + new_args).first(self.arity)]
19: }
20: end
C++ TR1 style bind use _#{n} for placeholders
_1 => 1st arg _2 => 2nd arg ...and so on
# File lib/ludy/proc/bind.rb, line 8
8: def bind *args
9: lambda{ |*new_args|
10: self[*(args.map{ |arg|
11: if (arg.kind_of? Symbol) && arg.to_s =~ /^_(\d+)$/
12: # is placeholder
13: new_args[$1.to_i-1]
14: else
15: # is not placeholder
16: arg
17: end
18: } + new_args).first(self.arity)]
19: }
20: end
TODO: missing traversal of chain create a chain of proc. whenever you call the chain, each proc would be called. the return value would be all the results saved orderly in a array.
# File lib/ludy/proc/chain.rb, line 7
7: def chain *procs, &block
8: procs << block if block
9: lambda{ |*args|
10: result = []
11: ([self] + procs).each{ |i|
12: result += [i[*args]].flatten
13: }
14: result
15: }
16: end
TODO: missing traversal of chain create a chain of proc. whenever you call the chain, each proc would be called. the return value would be all the results saved orderly in a array.
# File lib/ludy/proc/chain.rb, line 7
7: def chain *procs, &block
8: procs << block if block
9: lambda{ |*args|
10: result = []
11: ([self] + procs).each{ |i|
12: result += [i[*args]].flatten
13: }
14: result
15: }
16: end
TODO: missing traversal of chain create a chain of proc. whenever you call the chain, each proc would be called. the return value would be all the results saved orderly in a array.
# File lib/ludy/proc/chain.rb, line 7
7: def chain *procs, &block
8: procs << block if block
9: lambda{ |*args|
10: result = []
11: ([self] + procs).each{ |i|
12: result += [i[*args]].flatten
13: }
14: result
15: }
16: end
TODO: missing traversal of chain create a chain of proc. whenever you call the chain, each proc would be called. the return value would be all the results saved orderly in a array.
# File lib/ludy/proc/chain.rb, line 7
7: def chain *procs, &block
8: procs << block if block
9: lambda{ |*args|
10: result = []
11: ([self] + procs).each{ |i|
12: result += [i[*args]].flatten
13: }
14: result
15: }
16: end
make the caller be a curried function
lambda{|a,b,c| [a,b,c]}.curry[1][2][3]
=> [1,2,3]
# File lib/ludy/proc/curry.rb, line 14
14: def curry
15: class << self
16: alias_method :__call__, :call
17: def call *args, &block # :nodoc:
18: if self.arity == -1
19: begin # let's try if arguments are ready
20: # is there any better way to determine this?
21: # it's hard to detect correct arity value when
22: # Symbol#to_proc happened
23: # e.g., :message_that_you_never_know.to_proc.arity => ?
24: # i'd tried put hacks in Symbol#to_proc, but it's
25: # difficult to implement in correct way
26: # i would try it again in other day
27: self.public_send :__call__, *args, &block
28: rescue ArgumentError # oops, let's curry it
29: method(:call).to_proc.public_send :__curry__, *args
30: end
31: elsif args.size == self.arity
32: self.public_send :__call__, *args, &block
33: else
34: method(:call).to_proc.public_send :__curry__, *args
35: end
36: end
37: alias_method :[], :call
38: end
39: self
40: end
make the caller be a curried function
lambda{|a,b,c| [a,b,c]}.curry[1][2][3]
=> [1,2,3]
# File lib/ludy/proc/curry.rb, line 14
14: def curry
15: class << self
16: alias_method :__call__, :call
17: def call *args, &block # :nodoc:
18: if self.arity == -1
19: begin # let's try if arguments are ready
20: # is there any better way to determine this?
21: # it's hard to detect correct arity value when
22: # Symbol#to_proc happened
23: # e.g., :message_that_you_never_know.to_proc.arity => ?
24: # i'd tried put hacks in Symbol#to_proc, but it's
25: # difficult to implement in correct way
26: # i would try it again in other day
27: self.public_send :__call__, *args, &block
28: rescue ArgumentError # oops, let's curry it
29: method(:call).to_proc.public_send :__curry__, *args
30: end
31: elsif args.size == self.arity
32: self.public_send :__call__, *args, &block
33: else
34: method(:call).to_proc.public_send :__curry__, *args
35: end
36: end
37: alias_method :[], :call
38: end
39: self
40: end
make the caller be a curried function
lambda{|a,b,c| [a,b,c]}.curry[1][2][3]
=> [1,2,3]
# File lib/ludy/proc/curry.rb, line 14
14: def curry
15: class << self
16: alias_method :__call__, :call
17: def call *args, &block # :nodoc:
18: if self.arity == -1
19: begin # let's try if arguments are ready
20: # is there any better way to determine this?
21: # it's hard to detect correct arity value when
22: # Symbol#to_proc happened
23: # e.g., :message_that_you_never_know.to_proc.arity => ?
24: # i'd tried put hacks in Symbol#to_proc, but it's
25: # difficult to implement in correct way
26: # i would try it again in other day
27: self.public_send :__call__, *args, &block
28: rescue ArgumentError # oops, let's curry it
29: method(:call).to_proc.public_send :__curry__, *args
30: end
31: elsif args.size == self.arity
32: self.public_send :__call__, *args, &block
33: else
34: method(:call).to_proc.public_send :__curry__, *args
35: end
36: end
37: alias_method :[], :call
38: end
39: self
40: end
make the caller be a curried function
lambda{|a,b,c| [a,b,c]}.curry[1][2][3]
=> [1,2,3]
# File lib/ludy/proc/curry.rb, line 14
14: def curry
15: class << self
16: alias_method :__call__, :call
17: def call *args, &block # :nodoc:
18: if self.arity == -1
19: begin # let's try if arguments are ready
20: # is there any better way to determine this?
21: # it's hard to detect correct arity value when
22: # Symbol#to_proc happened
23: # e.g., :message_that_you_never_know.to_proc.arity => ?
24: # i'd tried put hacks in Symbol#to_proc, but it's
25: # difficult to implement in correct way
26: # i would try it again in other day
27: self.public_send :__call__, *args, &block
28: rescue ArgumentError # oops, let's curry it
29: method(:call).to_proc.public_send :__curry__, *args
30: end
31: elsif args.size == self.arity
32: self.public_send :__call__, *args, &block
33: else
34: method(:call).to_proc.public_send :__curry__, *args
35: end
36: end
37: alias_method :[], :call
38: end
39: self
40: end