totally_lazy 0.1.30 → 0.1.31
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 +8 -8
 - data/lib/totally_lazy/either.rb +10 -1
 - data/spec/totally_lazy/either_spec.rb +5 -0
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,15 +1,15 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            !binary "U0hBMQ==":
         
     | 
| 
       3 
3 
     | 
    
         
             
              metadata.gz: !binary |-
         
     | 
| 
       4 
     | 
    
         
            -
                 
     | 
| 
      
 4 
     | 
    
         
            +
                Y2UwOTI4NzkzYjg5ODZlN2MxNDJlYzdhMGE0MGUzYzRmNmZkNzM2Zg==
         
     | 
| 
       5 
5 
     | 
    
         
             
              data.tar.gz: !binary |-
         
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
      
 6 
     | 
    
         
            +
                MTZjNjBkYTU5ZGI4ODJjNjkwMDU1MzE0NWQwNDJiYzliNDEwZWNlZA==
         
     | 
| 
       7 
7 
     | 
    
         
             
            SHA512:
         
     | 
| 
       8 
8 
     | 
    
         
             
              metadata.gz: !binary |-
         
     | 
| 
       9 
     | 
    
         
            -
                 
     | 
| 
       10 
     | 
    
         
            -
                 
     | 
| 
       11 
     | 
    
         
            -
                 
     | 
| 
      
 9 
     | 
    
         
            +
                NjE0YTY1YzYwZGZkZmJhN2NjYjdkMDQwMDY5YzBlMDkxYTFiYTAyYWFkNWQw
         
     | 
| 
      
 10 
     | 
    
         
            +
                YzNjOTcxZWU0ZTQwOGVjMzJhZWYzMTE4YWU3MDEwZGZiNTE2ZDQ5N2I0OGZk
         
     | 
| 
      
 11 
     | 
    
         
            +
                YzljMmRlM2Q5Y2U4MWQ5ZjMxYmE2ZTJjOTM0OTg1MDA5NjAxZTg=
         
     | 
| 
       12 
12 
     | 
    
         
             
              data.tar.gz: !binary |-
         
     | 
| 
       13 
     | 
    
         
            -
                 
     | 
| 
       14 
     | 
    
         
            -
                 
     | 
| 
       15 
     | 
    
         
            -
                 
     | 
| 
      
 13 
     | 
    
         
            +
                MWZmZTgwNTM5NWRiY2VjZTI2MWRiMTUzMTRhYThiZWU5MmE3MzQ5YzJlMTBh
         
     | 
| 
      
 14 
     | 
    
         
            +
                YjBhMjE2M2UzNTQ1YTlkODA3MDFiYWJhMWZlNzFkZTRiZWFmNjYwMWI2Njc3
         
     | 
| 
      
 15 
     | 
    
         
            +
                ZjI3N2Y5MjJlMDM2NDM1MTYyNDBkNzU2MjRhYTQ5MjAyYjY1ZTk=
         
     | 
    
        data/lib/totally_lazy/either.rb
    CHANGED
    
    | 
         @@ -73,7 +73,12 @@ class Left < Either 
     | 
|
| 
       73 
73 
     | 
    
         
             
              def flat_map(fn=nil, &block) # a function which returns an either
         
     | 
| 
       74 
74 
     | 
    
         
             
                assert_funcs(fn, block_given?)
         
     | 
| 
       75 
75 
     | 
    
         
             
                self
         
     | 
| 
       76 
     | 
    
         
            -
            end
         
     | 
| 
      
 76 
     | 
    
         
            +
              end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
              def fold(seed, fn_left, fn_right)
         
     | 
| 
      
 79 
     | 
    
         
            +
                fn_left.(seed, @value)
         
     | 
| 
      
 80 
     | 
    
         
            +
              end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
       77 
82 
     | 
    
         
             
              def <=>(other)
         
     | 
| 
       78 
83 
     | 
    
         
             
                @value <=> other.left_value
         
     | 
| 
       79 
84 
     | 
    
         
             
              end
         
     | 
| 
         @@ -119,6 +124,10 @@ class Right < Either 
     | 
|
| 
       119 
124 
     | 
    
         
             
                block_given? ? block.call(@value) : fn.(@value)
         
     | 
| 
       120 
125 
     | 
    
         
             
              end
         
     | 
| 
       121 
126 
     | 
    
         | 
| 
      
 127 
     | 
    
         
            +
              def fold(seed, fn_left, fn_right)
         
     | 
| 
      
 128 
     | 
    
         
            +
                fn_right.(seed, @value)
         
     | 
| 
      
 129 
     | 
    
         
            +
              end
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
       122 
131 
     | 
    
         
             
              def <=>(other)
         
     | 
| 
       123 
132 
     | 
    
         
             
                @value <=> other.right_value
         
     | 
| 
       124 
133 
     | 
    
         
             
              end
         
     | 
| 
         @@ -40,6 +40,11 @@ describe 'Either' do 
     | 
|
| 
       40 
40 
     | 
    
         
             
                expect(right(right(1)).flatten).to eq(right(1))
         
     | 
| 
       41 
41 
     | 
    
         
             
              end
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
      
 43 
     | 
    
         
            +
              it 'should support fold' do
         
     | 
| 
      
 44 
     | 
    
         
            +
                expect(left(3).fold(2, sum, nil)).to eq(5)
         
     | 
| 
      
 45 
     | 
    
         
            +
                expect(right(3).fold(2, nil, sum)).to eq(5)
         
     | 
| 
      
 46 
     | 
    
         
            +
              end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
       43 
48 
     | 
    
         
             
              it 'should raise exception if you try to use both lambda and block' do
         
     | 
| 
       44 
49 
     | 
    
         
             
                expect { right(1).map(add(2)) { |a| a+2 } }.to raise_error(RuntimeError)
         
     | 
| 
       45 
50 
     | 
    
         
             
                expect { right(1).map_left(add(2)) { |a| a+2 } }.to raise_error(RuntimeError)
         
     |