class Emu::Decoder
Public Class Methods
new(&block)
click to toggle source
# File lib/emu/decoder.rb, line 6 def initialize(&block) @f = block end
Public Instance Methods
>(value)
click to toggle source
# File lib/emu/decoder.rb, line 53 def >(value) fmap { |_| value } end
fmap() { |unwrap)| ... }
click to toggle source
# File lib/emu/decoder.rb, line 23 def fmap Decoder.new do |input| result = run(input) if result.error? result else Ok.new(yield result.unwrap) end end end
run(value)
click to toggle source
# File lib/emu/decoder.rb, line 10 def run(value) @f.call(value) end
run!(value)
click to toggle source
# File lib/emu/decoder.rb, line 14 def run!(value) result = run(value) if result.error? raise DecodeError, result.unwrap_err else result.unwrap end end
then() { |result).run(input)| ... }
click to toggle source
# File lib/emu/decoder.rb, line 34 def then Decoder.new do |input| run(input).then do |result| (yield result).run(input) end end end
|(decoder)
click to toggle source
# File lib/emu/decoder.rb, line 42 def |(decoder) Decoder.new do |input| result = run(input) if result.error? decoder.run(input) else result end end end