Class: Validation

Inherits:
Object
  • Object
show all
Extended by:
ADT
Defined in:
lib/data/validation.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ADT

cases, operation

Class Method Details

.fail_with(error) ⇒ Object



10
11
12
# File 'lib/data/validation.rb', line 10

def self.fail_with(error)
  failure([error])
end

Instance Method Details

#bind(&b) ⇒ Object



18
19
20
# File 'lib/data/validation.rb', line 18

def bind(&b)
  fold(proc { |_| self }, b)
end

#mapObject



14
15
16
# File 'lib/data/validation.rb', line 14

def map
  fold(proc { |_| self }, proc { |v| Validation.success(yield v) })
end