funkr 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
data/lib/funkr/adt/adt.rb CHANGED
@@ -13,7 +13,7 @@ module Funkr
13
13
  end
14
14
 
15
15
  # Declare ADT constructors, for example :
16
- # class Maybe < ADT; adt :just, :nothing; end
16
+ # class Maybe < ADT; adt :just, :nothing; end
17
17
  def self.adt(*constructs)
18
18
  build_adt(constructs)
19
19
  build_matcher(constructs)
@@ -22,11 +22,11 @@ module Funkr
22
22
  def self.matcher; @matcher; end
23
23
 
24
24
  # Match your ADT against its constructors, for example :
25
- # a = Maybe.just("hello")
26
- # a.match do |on|
27
- # on.just{|x| puts x}
28
- # on.nothing{ }
29
- # end
25
+ # a = Maybe.just("hello")
26
+ # a.match do |on|
27
+ # on.just{|x| puts x}
28
+ # on.nothing{ }
29
+ # end
30
30
  def match(&block)
31
31
  self.class.matcher.match_with(normal_form, &block)
32
32
  end
@@ -23,18 +23,18 @@ module Funkr
23
23
  ### Categories
24
24
 
25
25
  include Functor
26
-
27
- # Maybe.nothing.map{|x| something(x)} # => nothing
28
- # Maybe.just(x).map{|x| something(x)} # => just something(x)
29
- #
26
+
30
27
  # {Funkr::Categories::Functor#map see functor map}
28
+ #
29
+ # Maybe.nothing.map{|x| something(x)} # => nothing
30
+ # Maybe.just(x).map{|x| something(x)} # => just something(x)
31
31
  def map(&block)
32
32
  # This implementation isn't safe but is a bit faster than the
33
33
  # safe one. A safe implementation would be as follow :
34
- # self.match do |on|
35
- # on.just {|v| self.class.just(yield(v))}
36
- # on.nothing { self }
37
- # end
34
+ # self.match do |on|
35
+ # on.just {|v| self.class.just(yield(v))}
36
+ # on.nothing { self }
37
+ # end
38
38
  if self.just? then self.class.just(yield(unsafe_content))
39
39
  else self end
40
40
  end
@@ -42,27 +42,27 @@ module Funkr
42
42
  include Applicative
43
43
  extend Applicative::ClassMethods
44
44
 
45
- # Maybe can be made an applicative functor, for example :
46
- # f = Maybe.curry_lift_proc{|x,y| x + y}
47
- # a = Maybe.just(3)
48
- # b = Maybe.just(4)
49
- # c = Maybe.nothing
50
- # f.apply(a).apply(b) => Just 7
51
- # f.apply(a).apply(c) => Nothing
52
- #
53
45
  # {Funkr::Categories::Applicative#apply see applicative apply}
46
+ #
47
+ # Maybe can be made an applicative functor, for example :
48
+ # f = Maybe.curry_lift_proc{|x,y| x + y}
49
+ # a = Maybe.just(3)
50
+ # b = Maybe.just(4)
51
+ # c = Maybe.nothing
52
+ # f.apply(a).apply(b) => Just 7
53
+ # f.apply(a).apply(c) => Nothing
54
54
  def apply(to)
55
55
  # This implementation isn't safe but is a bit faster than the
56
56
  # safe one. A safe implementation would be as follow :
57
- # self.match do |f_on|
58
- # f_on.just do |f|
59
- # to.match do |t_on|
60
- # t_on.just {|t| self.class.unit(f.call(t)) }
61
- # t_on.nothing { to }
57
+ # self.match do |f_on|
58
+ # f_on.just do |f|
59
+ # to.match do |t_on|
60
+ # t_on.just {|t| self.class.unit(f.call(t)) }
61
+ # t_on.nothing { to }
62
+ # end
62
63
  # end
64
+ # f_on.nothing { self }
63
65
  # end
64
- # f_on.nothing { self }
65
- # end
66
66
  if self.just? and to.just? then
67
67
  self.class.unit(self.unsafe_content.call(to.unsafe_content))
68
68
  else self.class.nothing end
@@ -103,10 +103,10 @@ module Funkr
103
103
  def bind(&block)
104
104
  # This implementation isn't safe but is a bit faster than the
105
105
  # safe one. A safe implementation would be as follow :
106
- # self.match do |on|
107
- # on.just {|v| yield(v)}
108
- # on.nothing {self}
109
- # end
106
+ # self.match do |on|
107
+ # on.just {|v| yield(v)}
108
+ # on.nothing {self}
109
+ # end
110
110
  if self.just? then yield(self.unsafe_content)
111
111
  else self end
112
112
  end
@@ -11,16 +11,17 @@ module Funkr
11
11
  # mistyping it or by combining it with a different structure
12
12
  # - you have easy access to fields : named AND positional
13
13
  #
14
- # usage : r = SimpleRecord.new(Hash), then r.field
15
- # r = SimpleRecord.new( name: "Paul", age: 27 )
16
- # r.name # => "Paul"
17
- # r.age # => 27
18
- # name, age = r # => [ "Paul", 27 ]
19
- # r.with(age: 29) # => [ "Paul", 29 ]
14
+ # usage :
15
+ #
16
+ # r = SimpleRecord.new( name: "Paul", age: 27 )
17
+ # r.name # => "Paul"
18
+ # r.age # => 27
19
+ # name, age = r # => [ "Paul", 27 ]
20
+ # r.with(age: 29) # => [ "Paul", 29 ]
20
21
  #
21
22
  # other usage :
22
- # class Person < SimpleRecord; fields :name, :age; end
23
- # Person.new( name: Paul ) => Error, missing :age
23
+ # class Person < SimpleRecord; fields :name, :age; end
24
+ # Person.new( name: Paul ) => Error, missing :age
24
25
  class SimpleRecord < Array
25
26
 
26
27
  class << self; attr_accessor :fields_list; end
data/lib/funkr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Funkr
2
- VERSION = "0.0.24"
2
+ VERSION = "0.0.25"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 24
9
- version: 0.0.24
8
+ - 25
9
+ version: 0.0.25
10
10
  platform: ruby
11
11
  authors:
12
12
  - Paul Rivier