core 3.3.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +46 -3
- data/core.gemspec +1 -1
- data/lib/core/composable.rb +12 -0
- data/lib/core.rb +1 -0
- data.tar.gz.sig +0 -0
- metadata +3 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 34e053097ae6807acaccbceda960d36c0fab5727d1c4fd44b27d920a38d04e17
|
|
4
|
+
data.tar.gz: 0e8e8efa4f28893e6fe3b2319287ca999c5cf8551d13d9533b009b67c51f5863
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a1a1899d72683603248cb2a5690e3bd228352ea6f891a2e51f757ff2b1c01179178448c33be10c9218d24241b70ce1e9e9e6b3e5b8015281e912fefd0b1ed563
|
|
7
|
+
data.tar.gz: 7c1d341c9fdddc3e407e8d4aaec01e3e8b1cb2281bb9082922af73740acfbb2a5b4a93724b827f8400ceb75f6c5175e686d7c9b032558c90b3b8ff016f14d54e
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/README.adoc
CHANGED
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
:toclevels: 5
|
|
3
3
|
:figure-caption!:
|
|
4
4
|
|
|
5
|
+
:ruby_link: link:https://www.ruby-lang.org[Ruby]
|
|
6
|
+
:function_composition_link: link:https://alchemists.io/articles/ruby_function_composition[Function Composition]
|
|
7
|
+
:pipeable_link: link:https://alchemists.io/projects/pipeable[Pipeable]
|
|
8
|
+
|
|
5
9
|
= Core
|
|
6
10
|
|
|
7
|
-
Provides a collection of
|
|
11
|
+
Provides a collection of common objects missing from core {ruby_link}. This allows you to reduce duplication, improve performance, and improve memory usage in order to engineer advanced architectures.
|
|
8
12
|
|
|
9
13
|
toc::[]
|
|
10
14
|
|
|
@@ -14,7 +18,7 @@ toc::[]
|
|
|
14
18
|
|
|
15
19
|
== Requirements
|
|
16
20
|
|
|
17
|
-
.
|
|
21
|
+
. {ruby_link}.
|
|
18
22
|
|
|
19
23
|
== Setup
|
|
20
24
|
|
|
@@ -42,13 +46,52 @@ The following _empty_ constants are frozen by default and available for use as c
|
|
|
42
46
|
|
|
43
47
|
=== Functions
|
|
44
48
|
|
|
45
|
-
The following identity function (lambda) is available as a neutral value in
|
|
49
|
+
The following identity function (lambda) is available as a neutral value in {function_composition_link}:
|
|
46
50
|
|
|
47
51
|
[source,ruby]
|
|
48
52
|
----
|
|
49
53
|
Core::Identity.call "example" # "example"
|
|
50
54
|
----
|
|
51
55
|
|
|
56
|
+
=== Modules
|
|
57
|
+
|
|
58
|
+
A `Composable` module is available to you should you need to use {function_composition_link} in order to make your objects composable via procs, lambdas, methods, and/or classes. Pairs well with the {pipeable_link} gem. The module provides the following methods for you:
|
|
59
|
+
|
|
60
|
+
* `+>>+`: Forward composition.
|
|
61
|
+
* `+<<+`: Backward composition.
|
|
62
|
+
* `+#call+`: The primary method to implement in order to be composable. Fails with a `NoMethodError` if not implemented.
|
|
63
|
+
|
|
64
|
+
To use, include `Composable` and implement `#call` as follows:
|
|
65
|
+
|
|
66
|
+
[source,ruby]
|
|
67
|
+
----
|
|
68
|
+
class Greeter
|
|
69
|
+
include Core::Composable
|
|
70
|
+
|
|
71
|
+
def initialize salutation: "Heya"
|
|
72
|
+
@salutation = salutation
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def call(text) = "#{salutation} #{text}"
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
attr_reader :salutation
|
|
80
|
+
end
|
|
81
|
+
----
|
|
82
|
+
|
|
83
|
+
The above then allows you to compose your objects as functional pipelines:
|
|
84
|
+
|
|
85
|
+
[source,ruby]
|
|
86
|
+
----
|
|
87
|
+
appender = -> text { "#{text} -- An example of function composition."}
|
|
88
|
+
greeter = Greeter.new
|
|
89
|
+
|
|
90
|
+
(greeter >> appender).call "visitor"
|
|
91
|
+
|
|
92
|
+
# "Heya visitor -- An example of function composition."
|
|
93
|
+
----
|
|
94
|
+
|
|
52
95
|
== Development
|
|
53
96
|
|
|
54
97
|
To contribute, run:
|
data/core.gemspec
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Core
|
|
4
|
+
# Allows objects to be functionally composable.
|
|
5
|
+
module Composable
|
|
6
|
+
def >>(other) = method(:call) >> other
|
|
7
|
+
|
|
8
|
+
def <<(other) = method(:call) << other
|
|
9
|
+
|
|
10
|
+
def call = fail NoMethodError, "`#{self.class.name}##{__method__}` must be implemented."
|
|
11
|
+
end
|
|
12
|
+
end
|
data/lib/core.rb
CHANGED
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brooke Kuhlmann
|
|
@@ -47,6 +47,7 @@ files:
|
|
|
47
47
|
- README.adoc
|
|
48
48
|
- core.gemspec
|
|
49
49
|
- lib/core.rb
|
|
50
|
+
- lib/core/composable.rb
|
|
50
51
|
- lib/core/identity.rb
|
|
51
52
|
homepage: https://alchemists.io/projects/core
|
|
52
53
|
licenses:
|
|
@@ -73,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
73
74
|
- !ruby/object:Gem::Version
|
|
74
75
|
version: '0'
|
|
75
76
|
requirements: []
|
|
76
|
-
rubygems_version: 4.0.
|
|
77
|
+
rubygems_version: 4.0.20
|
|
77
78
|
specification_version: 4
|
|
78
79
|
summary: A collection of foundational objects.
|
|
79
80
|
test_files: []
|
metadata.gz.sig
CHANGED
|
Binary file
|