invokable 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1704e11155d49e8801c46591a662a28633d93c7c069fa7a52c5412d4aa9a2162
4
- data.tar.gz: 016e698868ebfe51cfd36c304391a0932a45e743f262fcd6004c208f6b8b3c09
3
+ metadata.gz: 4908901ef4becc2a2de44b1ce8a23d656ac5f2a5b00b3122b59d087fdc30e7c7
4
+ data.tar.gz: a042c77682ff40a6d481d14cb20840113eac45757b21c13ec0e2e40f52abdad5
5
5
  SHA512:
6
- metadata.gz: b6ea38312e09b45aae62501b6d1ea623d991a358aae63c4056150d28bac91c039b795c58b67c7f6fedc8c8e336fa2dbed456739cf333164db11237c4e865085b
7
- data.tar.gz: 888c37a34ba29d412b2451d28cc22b0da328f978fc08445e5872e5b8d2e293d8261132209cf1bca63148762a888592dfa9d3c466e24f55345f4d0df81d19a236
6
+ metadata.gz: 9e320d788d71a963d844f262a56a3c9413a016b89f050a9249d17e5cd57157d39588410f190f0b85b682c91b11c183597955a72ea508cea0460dcf1f033adf86
7
+ data.tar.gz: f7b08dcbf9311e95791c98df269e2533ace49abc7aba539c767aa4755db60e3d81754f4e65574094ede2f01c621167cd5270b135ea5329b36810441cf49e7dfb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- invokable (0.2.0)
4
+ invokable (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -60,6 +60,28 @@ A function is a mapping of one value to another with the additional constraint t
60
60
  always get the same output value. So, conceptually, Ruby Hashes, Arrays, and Sets are all functions. Also, there are
61
61
  many one method objects out there (e.g. ServiceObjects) that are essentially functions. Why not treat them as such?
62
62
 
63
+ # API
64
+
65
+ ## to_proc -> a_proc
66
+
67
+ ```ruby
68
+ hash = { a: 1, b, 2 }
69
+ hash.class # => Hash
70
+ hash.to_proc.class # => Proc
71
+ [:a, :b].map(&hash) # => [1, 2]
72
+ ```
73
+
74
+ Convert an object into a proc. When the `Invokable` module is included in a class it will do this by
75
+ returning a proc that passes it's arguments to the object's `call` method. When `invokable/data` is
76
+ loaded `Hash#call` is mapped to `Hash#dig`, `Array#call` is mapped to `Array#at`, and `Set#call`
77
+ is mapped to `Set#include?`.
78
+
79
+ ## curry -> a_proc
80
+ ## curry(arity) -> a_proc
81
+
82
+ Returns a curried proc. If the `arity` is given, it determines the number of arguments.
83
+ (see [Proc#curry](https://ruby-doc.org/core-2.7.0/Proc.html#method-i-curry)).
84
+
63
85
  # Installation
64
86
 
65
87
  Add this line to your application's Gemfile:
@@ -83,7 +105,7 @@ Or install it yourself as:
83
105
 
84
106
  # TODO
85
107
 
86
- - add support for `curry`, `memoize` and maybe transducers.
108
+ - add support for `memoize` and maybe transducers.
87
109
  - benchmark Invokable#to_proc
88
110
 
89
111
  # License
data/lib/invokable.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  require 'invokable/version'
2
2
 
3
- # TODO: Add curry, memoize, transducers?
3
+ # TODO: Add memoize, transducers?
4
4
  module Invokable
5
5
  # If object responds to `call` convert into a Proc forwards it's arguments along to `call`.
6
6
  #
7
+ # @see [Proc#call]
7
8
  # @return [Proc]
8
9
  def to_proc
9
10
  if respond_to?(:call)
@@ -16,7 +17,14 @@ module Invokable
16
17
  end
17
18
  end
18
19
 
19
- def curry
20
- to_proc.curry
20
+ # Return a curried proc. If the optional arity argument is given, it determines the number of arguments.
21
+ # A curried proc receives some arguments. If a sufficient number of arguments are supplied, it passes the
22
+ # supplied arguments to the original proc and returns the result. Otherwise, returns another curried proc
23
+ # that takes the rest of arguments.
24
+ #
25
+ # @see [Proc#curry]
26
+ # @return [Proc]
27
+ def curry(*args)
28
+ to_proc.curry(*args)
21
29
  end
22
30
  end
@@ -1,3 +1,3 @@
1
1
  module Invokable
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invokable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delon Newman