composite_type 0.1.0 → 0.1.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
  SHA1:
3
- metadata.gz: 9faec747d46328dfe04c62ee29c4a1e98684db41
4
- data.tar.gz: bd68565039a8dbca31c5cc486ca2a705c964e871
3
+ metadata.gz: 79b73ddf6ca69a94ade50421d460271d88bfa71c
4
+ data.tar.gz: eff100ef24de4b9136566c47bd123eafe63491d0
5
5
  SHA512:
6
- metadata.gz: 4d9548cd6e18641f59295f6f7017f92d6ef9196b057b586552130da90f44374abedb7e4a66b8dee63482dc829f7a1fde4c5cb539299bea1e5821a397f98fa5a0
7
- data.tar.gz: d0f8c5ec6cce22afca349bb85d464919b3b3eb4b7015e912f45b047274a5265633d99f578218d98449275cd39c960ff0af128c86a349fac2131bc467ca9155bb
6
+ metadata.gz: 0be9100aa76f309188b51710feb30837f760c03556fa7a76f92541227811bb3499e62cbc8de7b395a045b47f17c98349968758c6800813773d4527263f805fe3
7
+ data.tar.gz: d05c6b593fee921e608bcb581c3478fb1b2b1d85ba3f2dd5c7582dac0ff3d12d5ad976be1afd3f27657aee22e3054590725b73f6de2422a7bfc5da570fbb7d8e
data/README.md CHANGED
@@ -1,42 +1,13 @@
1
- # TypedAttr
1
+ # CompositeType
2
2
 
3
- Typed Attributes and Composite Types for Functional Programming in Ruby
3
+ Composite Types for Ruby
4
4
 
5
5
  ## Usage
6
6
 
7
- TypedAttr simplifies typed functional programming in Ruby.
8
-
9
- The creation of data types is central to functional programming.
10
- Ruby does not enforce any typing of object attributes or method parameters.
11
-
12
- TypedAttr introduces a class macro "typed_attr". It constructs an #initialize method
13
- given a list of attributes and their expected types.
14
-
15
- Example:
16
-
17
- require 'typed_attr'
18
- class Account
19
- typed_attr name: String, amount: Money
20
- end
21
- Account.new("Foo", Money.new(1234))
22
- Account.new("Foo", 1234) # => raise TypeError
23
-
24
- Use "typecheck" to perform checks on values:
25
-
26
- def m x, y
27
- typecheck x, String
28
- typecheck y, Positive, Integer
29
- x * y
30
- end
31
- m("string", -1) # => raise TypeError
32
- m("string", 2) # => "stringstring"
33
-
34
- The type assertions use the #=== matching operator.
35
-
36
7
  Composite Types can be constructed to match deeper data structures:
37
8
 
38
9
  h = { "a" => 1, "b" => :symbol }
39
- typecheck h, Hash.of(String.with(Integer|Symbol))
10
+ Hash.of(String.with(Integer|Symbol)) === h # => true
40
11
 
41
12
  Defining types through Modules:
42
13
 
@@ -58,22 +29,24 @@ Thus composite types can be used in "case when" clauses:
58
29
  Logical operators: #|, #&, #~ are supported:
59
30
 
60
31
  a = [ 1, 2, 3 ]
61
- typecheck a, Array.of(Positive & Numeric)
62
- typecheck a, Array.of(~ NilClass)
32
+ Array.of(Positive & Numeric) === a # => true
33
+ Array.of(~ NilClass) === a # => false
63
34
 
64
35
  b = [ 1, -2, 3 ]
65
- typecheck b, Array.of(Positive & Numeric) # => raise TypeError
36
+ Array.of(Positive & Numeric) === b # => false
66
37
 
67
38
  c = [ 1, nil, 3 ]
68
- typecheck c, Array.of(~ NilClass) # => raise TypeError
39
+ Array.of(~ NilClass) === c # => false
69
40
 
70
41
  Composite types are cached indefinitely, therefore anonymous Modules cannot be composed.
71
42
 
43
+ See spec/lib/composite_type_spec.rb for more examples.
44
+
72
45
  ## Installation
73
46
 
74
47
  Add this line to your application's Gemfile:
75
48
 
76
- gem 'typed_attr'
49
+ gem 'composite_type'
77
50
 
78
51
  And then execute:
79
52
 
@@ -81,7 +54,7 @@ And then execute:
81
54
 
82
55
  Or install it yourself as:
83
56
 
84
- $ gem install typed_attr
57
+ $ gem install composite_type
85
58
 
86
59
  ## Contributing
87
60
 
@@ -1,3 +1,3 @@
1
1
  module CompositeType
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: composite_type
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kurt Stephens