funkr 0.0.25 → 0.0.40

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f5649962b565534f862b38ae383b658c1a5488822f5827ec87c1eb811d5c3037
4
+ data.tar.gz: e56a95ae98fd9d7d58d8da6243f4788ef078727a46af8ddd230be2ff926bd5fd
5
+ SHA512:
6
+ metadata.gz: 9f18403815d1715943156f2298babd16436a6979f75f86edbc8bb72e09e4b8f2a3d543a7c798ee61a4d21c42489afffad84cbba7d9a215dfaccc4da086d0f3a5
7
+ data.tar.gz: 8e82ba816b2a0b9fab4c1764a670364d137fbdf813699f5627448863a1565d8625a59b40f0273a5a265bc81fef6749afc4bfaaeefd9b22f415b0e5c4cd6c2f03
data/README CHANGED
@@ -1,13 +1,16 @@
1
1
  Funkr brings some common functional programming constructs to ruby.
2
2
 
3
- In particular, it offers a simple mechanism to create Algebraïc Data
4
- Types and do pattern matching on them. For an exemple
5
- implementation, {Funkr::Types see provided classes}.
3
+ In particular, it offers a simple mechanism to create Algebraic Data
4
+ Types and do pattern matching on them. For an exemple implementation,
5
+ see provided classes.
6
6
 
7
7
  It also provide modules for common categories (Monoid, Monad,
8
8
  Functor, Applicative ...), and extends common types to support
9
9
  categories they belongs to (Array, Hash ...). Categories can also be
10
- used with custom types, {Funkr::Types see provided classes}.
10
+ used with custom types, see provided classes.
11
11
 
12
12
  To get started, we recommand you to read the tests, and get feets wet
13
- with provided Algebraic Data Types (like Maybe).
13
+ with provided Algebraic Data Types (like Maybe).
14
+
15
+ Funkr is heavily used by its authors in production at
16
+ http://www.atikteam.com/en to ensure better code reliability.
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  $:.push File.expand_path("../lib", __FILE__)
3
2
  require "funkr/version"
4
3
 
@@ -9,8 +8,27 @@ Gem::Specification.new do |s|
9
8
  s.authors = ["Paul Rivier"]
10
9
  s.email = ["paul (dot) r (dot) ml (at) gmail (dot) com"]
11
10
  s.homepage = "http://github.com/paul-r-ml/funkr"
12
- s.summary = %q{[EXPERIMENTAL] Some functionnal constructs for ruby}
13
- s.description = %q{[EXPERIMENTAL] Some functionnal constructs for ruby, like ADT, functors, monads}
11
+ s.summary = %q{Functionnal toolbox for Ruby}
12
+ s.description = <<EOF
13
+ Funkr is a functionnal toolbox for the Ruby language.
14
+
15
+ In particular, it offers a simple mechanism to create Algebraic Data
16
+ Types and do pattern matching on them.
17
+
18
+ -
19
+
20
+ It also provide modules for common categories (Monoid, Monad,
21
+ Functor, Applicative ...), and extends common types to support
22
+ categories they belongs to (Array, Hash ...). Categories can also be
23
+ used with custom types, see provided classes.
24
+
25
+ -
26
+
27
+ Array and Hash classes are extended with methods providing correct
28
+ behaviour with respect to categories. Enumerable module comes with
29
+ a lot of useful functions for working with lists and sets. See the
30
+ module documentation and the test suite for examples.
31
+ EOF
14
32
 
15
33
  s.rubyforge_project = "funkr"
16
34
 
@@ -18,5 +36,5 @@ Gem::Specification.new do |s|
18
36
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
37
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
38
  s.require_paths = ["lib"]
21
- s.add_development_dependency 'rake', '~> 0.9.2'
39
+ s.add_development_dependency 'rake', '~> 12.3'
22
40
  end
@@ -41,11 +41,20 @@ module Funkr
41
41
  @data.map(&:inspect).join(", ") )
42
42
  end
43
43
 
44
+
45
+ def ==(o)
46
+ case o
47
+ when ADT then self.normal_form == o.normal_form
48
+ else false
49
+ end
50
+ end
51
+
52
+ def normal_form; [@const, *@data]; end
53
+
44
54
  private
45
55
 
46
56
  attr_reader :const, :data
47
57
 
48
- def normal_form; [@const, *@data]; end
49
58
 
50
59
  def self.build_adt(constructs)
51
60
  constructs.each do |c,*d|
@@ -14,7 +14,7 @@ module Funkr
14
14
  def self.build_matchers(constructs)
15
15
  @constructs = constructs
16
16
  constructs.each do |c|
17
- name, *data = c
17
+ name, *_ = c
18
18
  define_method(name) do |&b|
19
19
  @undefined.delete(name)
20
20
  if @const == name then
@@ -39,10 +39,6 @@ module Funkr
39
39
  proxy_comp(other){|a,b| a <=> b}
40
40
  end
41
41
 
42
- def ==(other)
43
- proxy_comp(other){|a,b| a == b}
44
- end
45
-
46
42
  def <(other)
47
43
  proxy_comp(other){|a,b| a < b}
48
44
  end
@@ -59,6 +55,9 @@ module Funkr
59
55
  proxy_comp(other){|a,b| a >= b}
60
56
  end
61
57
 
58
+ def applicative_equal?(other)
59
+ proxy_comp(other){|a,b| a == b}
60
+ end
62
61
 
63
62
  private
64
63
 
@@ -1,4 +1,4 @@
1
- require 'funkr/extensions/fixnum'
1
+ require 'funkr/extensions/integer'
2
2
  require 'funkr/extensions/array'
3
3
  require 'funkr/extensions/enumerable'
4
4
  require 'funkr/extensions/hash'
@@ -17,9 +17,10 @@ class Array
17
17
 
18
18
 
19
19
  # Array can be made an applicative functor, for example :
20
- # f = Array.curry_lift_proc{|x,y| x + y}
21
- # f.apply([0,4]).apply([5,7]) => [5, 7, 9, 11]
22
- # f.apply([0,4]).apply([]) => []
20
+ #
21
+ # f = Array.curry_lift_proc{|x,y| x + y}
22
+ # f.apply([0,4]).apply([5,7]) => [5, 7, 9, 11]
23
+ # f.apply([0,4]).apply([]) => []
23
24
  include Applicative
24
25
  extend Applicative::ClassMethods
25
26
 
@@ -49,10 +50,12 @@ class Array
49
50
  end
50
51
 
51
52
 
52
- # Array is also a monad
53
53
  include Monad
54
54
  extend Monad::ClassMethods
55
55
 
56
+ # Array is also a monad
57
+ #
58
+ # [1,2].bind{|x| [3,4].bind{|y| x + y}} # => [4,5,5,6]
56
59
  def bind(&block)
57
60
  self.map(&block).flatten(1)
58
61
  end
@@ -40,26 +40,27 @@ module Enumerable
40
40
  return [ inc, [] ]
41
41
  end
42
42
 
43
- # Constitue des groupes disjoints de n éléments au plus
43
+ # builds up disjoint groups of n elements or less
44
44
  def groups_of(n)
45
45
  g = self.take(n)
46
46
  return [] if g.empty?
47
47
  [g] + self.drop(n).groups_of(n)
48
48
  end
49
49
 
50
- # constitue des groupes de n éléments exactement, décalés de 1
50
+ # builds up sliding groups of exactly n elements
51
51
  def sliding_groups_of(n)
52
52
  return [] if self.size < n
53
53
  [ self.take(n) ] + self.drop(1).sliding_groups_of(n)
54
54
  end
55
55
 
56
- # trouve l'index d'une séquence
56
+ # find the position of a sequence
57
+ # [1,2,3,4,5,4,3,2,1].seq_index([4,3]) # => 5
57
58
  def seq_index(seq)
58
59
  self.sliding_groups_of(seq.size).index(seq)
59
60
  end
60
61
 
61
- # Prend un prédicat p(x,y), et construit un tableau dans lequel tous
62
- # les couples (a,b), tels que 'a' précède 'b', vérifient p(a,b).
62
+ # Takes a block predicate p(x,y) and builds an array of elements so
63
+ # that for any (a,b), a being before b in the list, p(a,b) holds.
63
64
  def make_uniq_by(&block)
64
65
  result = []
65
66
  self.each do |e|
@@ -68,8 +69,7 @@ module Enumerable
68
69
  return result
69
70
  end
70
71
 
71
- # difference entre 2 tableaux, retourne le triplet [ [missing] , [intersection], [added] ]
72
- # codé en impératif parce que inject est trop lent :(
72
+ # compare 2 enumerables, and returns [ [missing] , [intersection], [added] ]
73
73
  def diff_with(other, &block)
74
74
  m, i, a = [], [], []
75
75
  u_s = self.make_uniq_by(&block)
@@ -1,6 +1,6 @@
1
1
  require "funkr/categories/monoid"
2
2
 
3
- class Fixnum
3
+ class Integer
4
4
 
5
5
  include Funkr::Categories
6
6
 
@@ -10,6 +10,9 @@ class Fixnum
10
10
  def mplus(y)
11
11
  self + y
12
12
  end
13
+
14
+ def self.mzero
15
+ 0
16
+ end
13
17
 
14
18
  end
15
-
@@ -1,3 +1,3 @@
1
1
  module Funkr
2
- VERSION = "0.0.25"
2
+ VERSION = "0.0.40"
3
3
  end
@@ -66,4 +66,9 @@ class TestExtensions < Test::Unit::TestCase
66
66
  a.make_uniq_by{|x,y| x[:v] == y[:v]})
67
67
  end
68
68
 
69
+
70
+ def test_mconcat_integer
71
+ assert_equal(6, Integer.mconcat([1,2,3]))
72
+ end
73
+
69
74
  end
@@ -16,7 +16,6 @@ class TestMaybe < Test::Unit::TestCase
16
16
 
17
17
  def test_map
18
18
  assert_equal(j(6), j(5).map{|v| v+1 })
19
- assert_equal(n, j(5).map{|v| v+1})
20
19
  end
21
20
 
22
21
  def test_curry_lift
@@ -57,8 +56,10 @@ class TestMaybe < Test::Unit::TestCase
57
56
  assert_equal(j(true), j(3) < j(7))
58
57
  assert_equal(n, j(4) <=> n)
59
58
  assert_equal(n, n <=> j(2))
59
+ assert_equal(j(false), j(5).applicative_equal?(j(7)))
60
60
  end
61
61
 
62
+
62
63
  def test_unbox
63
64
  assert_equal(5, j(5).unbox)
64
65
  assert_equal(5, j(5).unbox(2))
metadata CHANGED
@@ -1,49 +1,56 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: funkr
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 25
9
- version: 0.0.25
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.40
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Paul Rivier
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2011-12-06 00:00:00 +01:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2020-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: rake
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ~>
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 9
31
- - 2
32
- version: 0.9.2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12.3'
33
20
  type: :development
34
- version_requirements: *id001
35
- description: "[EXPERIMENTAL] Some functionnal constructs for ruby, like ADT, functors, monads"
36
- email:
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12.3'
27
+ description: |
28
+ Funkr is a functionnal toolbox for the Ruby language.
29
+
30
+ In particular, it offers a simple mechanism to create Algebraic Data
31
+ Types and do pattern matching on them.
32
+
33
+ -
34
+
35
+ It also provide modules for common categories (Monoid, Monad,
36
+ Functor, Applicative ...), and extends common types to support
37
+ categories they belongs to (Array, Hash ...). Categories can also be
38
+ used with custom types, see provided classes.
39
+
40
+ -
41
+
42
+ Array and Hash classes are extended with methods providing correct
43
+ behaviour with respect to categories. Enumerable module comes with
44
+ a lot of useful functions for working with lists and sets. See the
45
+ module documentation and the test suite for examples.
46
+ email:
37
47
  - paul (dot) r (dot) ml (at) gmail (dot) com
38
48
  executables: []
39
-
40
49
  extensions: []
41
-
42
50
  extra_rdoc_files: []
43
-
44
- files:
45
- - .gitignore
46
- - .travis.yml
51
+ files:
52
+ - ".gitignore"
53
+ - ".travis.yml"
47
54
  - Gemfile
48
55
  - README
49
56
  - Rakefile
@@ -61,8 +68,8 @@ files:
61
68
  - lib/funkr/extensions.rb
62
69
  - lib/funkr/extensions/array.rb
63
70
  - lib/funkr/extensions/enumerable.rb
64
- - lib/funkr/extensions/fixnum.rb
65
71
  - lib/funkr/extensions/hash.rb
72
+ - lib/funkr/extensions/integer.rb
66
73
  - lib/funkr/types.rb
67
74
  - lib/funkr/types/container.rb
68
75
  - lib/funkr/types/failable.rb
@@ -74,37 +81,27 @@ files:
74
81
  - test/test_hash.rb
75
82
  - test/test_maybe.rb
76
83
  - test/test_simple_records.rb
77
- has_rdoc: true
78
84
  homepage: http://github.com/paul-r-ml/funkr
79
85
  licenses: []
80
-
86
+ metadata: {}
81
87
  post_install_message:
82
88
  rdoc_options: []
83
-
84
- require_paths:
89
+ require_paths:
85
90
  - lib
86
- required_ruby_version: !ruby/object:Gem::Requirement
87
- none: false
88
- requirements:
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
89
93
  - - ">="
90
- - !ruby/object:Gem::Version
91
- segments:
92
- - 0
93
- version: "0"
94
- required_rubygems_version: !ruby/object:Gem::Requirement
95
- none: false
96
- requirements:
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
97
98
  - - ">="
98
- - !ruby/object:Gem::Version
99
- segments:
100
- - 0
101
- version: "0"
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
102
101
  requirements: []
103
-
104
102
  rubyforge_project: funkr
105
- rubygems_version: 1.3.7
103
+ rubygems_version: 2.7.6.2
106
104
  signing_key:
107
- specification_version: 3
108
- summary: "[EXPERIMENTAL] Some functionnal constructs for ruby"
105
+ specification_version: 4
106
+ summary: Functionnal toolbox for Ruby
109
107
  test_files: []
110
-