-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable currying of procs, fixes most related specs.
1 parent
5c4ecb5
commit 6a3bcd3
Showing
6 changed files
with
68 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ lib/*jar | |
pkg | ||
pom.jruby-jars.gemspec.xml | ||
lib/jruby-jars/version.rb | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,3 @@ | ||
fails:Proc#curry returns a Proc when called on a proc | ||
fails:Proc#curry returns a Proc when called on a lambda | ||
fails:Proc#curry calls the curried proc with the arguments if sufficient arguments have been given | ||
fails:Proc#curry returns a Proc that consumes the remainder of the arguments unless sufficient arguments have been given | ||
fails:Proc#curry can be called multiple times on the same Proc | ||
fails:Proc#curry can be passed superfluous arguments if created from a proc | ||
fails:Proc#curry raises an ArgumentError if passed superfluous arguments when created from a lambda | ||
fails:Proc#curry returns Procs with arities of -1 | ||
fails:Proc#curry produces Procs that raise ArgumentError for #binding | ||
fails:Proc#curry produces Procs that return [[:rest]] for #parameters | ||
fails:Proc#curry produces Procs that return nil for #source_location | ||
fails:Proc#curry produces Procs that can be passed as the block for instance_exec | ||
fails:Proc#curry with arity argument accepts an optional Integer argument for the arity | ||
fails:Proc#curry with arity argument returns a Proc when called on a proc | ||
fails:Proc#curry with arity argument returns a Proc when called on a lambda | ||
fails:Proc#curry with arity argument retains the lambda-ness of the Proc on which its called | ||
fails:Proc#curry with arity argument calls the curried proc with the arguments if _arity_ arguments have been given | ||
fails:Proc#curry with arity argument returns a Proc that consumes the remainder of the arguments when fewer than _arity_ arguments are given | ||
fails:Proc#curry with arity argument can be specified multiple times on the same Proc | ||
fails:Proc#curry with arity argument raises an ArgumentError if passed more than _arity_ arguments when created from a lambda | ||
fails:Proc#curry with arity argument returns Procs with arities of -1 regardless of the value of _arity_ | ||
fails:Proc#curry combines arguments and calculates incoming arity accurately for successively currying | ||
fails:Proc#curry with arity argument raises an ArgumentError if called on a lambda that requires fewer than _arity_ arguments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright (c) 2007-2015, Evan Phoenix and contributors | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright notice | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# * Neither the name of Rubinius nor the names of its contributors | ||
# may be used to endorse or promote products derived from this software | ||
# without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | ||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
module Rubinius | ||
class Mirror | ||
class Proc < Mirror | ||
def self.from_block(klass, env) | ||
begin | ||
return Rubinius.invoke_primitive :proc_from_env, env, klass | ||
rescue Rubinius::Internal => exc | ||
if Type.object_kind_of? env, BlockEnvironment | ||
msg = "unable to create Proc from BlockEnvironment" | ||
raise PrimitiveFailure, msg, exc | ||
end | ||
end | ||
|
||
begin | ||
env.to_proc | ||
rescue Exception | ||
raise ArgumentError, "Unable to convert #{env.inspect} to a Proc" | ||
end | ||
end | ||
|
||
def curry(executable, args, arity) | ||
args.freeze | ||
|
||
name = executable.lambda? ? :lambda : :proc | ||
|
||
Proc.__send__(name) do |*a, &b| | ||
all_args = args + a | ||
if all_args.size < arity | ||
curry executable, all_args, arity | ||
else | ||
executable[*all_args] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |