Sha256: da79fc1d87d3e2628f090408a85ee43ef94e1be9f25e1427a6919bdfbfd6a852
Contents?: true
Size: 1.04 KB
Versions: 8
Compression:
Stored size: 1.04 KB
Contents
require "funkr/adt/matcher" module Funkr class ADT def initialize(const, *data) @const, @data = const, data end def self.adt(*constructs) build_adt(constructs) build_matcher(constructs) end def self.match_method=(method) @match_method = method end self.match_method = :safe def self.matcher; @matcher; end def match m = self.class.matcher.new(normal_form) yield m m.run_match end def to_s format("%s%s%s", @const, @data.any? ? " : " : "", @data.map(&:inspect).join(" ") ) end private attr_reader :const, :data def normal_form; [@const, *@data]; end def self.build_adt(constructs) constructs.each do |c,*d| define_singleton_method(c) do |*data| self.new(c,*data) end end end def self.build_matcher(constructs) @matcher = Class.new(Funkr::Matcher) do build_matchers(constructs) end end end end
Version data entries
8 entries across 8 versions & 1 rubygems