<commit_before>package ir

import (
	"fmt"

	"github.com/tisp-lang/tisp/src/lib/core"
)

// Switch represents a switch expression.
type Switch struct {
	patterns []core.Value
	values   []int
}

// NewSwitch creates a switch expression.
func NewSwitch(ps []core.Value, vs []int) Switch {
	if len(ps) != len(vs) {
		panic(fmt.Errorf(
			"A number of patterns (%d) doesn't match with a number of corresponding values (%d)",
			len(ps),
			len(vs)))
	} else if len(ps) == 0 {
		panic(fmt.Errorf("A number of patterns must be more than 0"))
	}

	return Switch{ps, vs}
}

func (s Switch) compileToDict() core.DictionaryType {
	ts := make([]*core.Thunk, 0, len(s.values))

	for _, v := range s.values {
		ts = append(ts, core.NewNumber(float64(v)))
	}

	return core.NewDictionary(s.patterns, ts).Eval().(core.DictionaryType)
}<commit_msg>Add matched value to switch type<commit_after>package ir

import (
	"fmt"

	"github.com/tisp-lang/tisp/src/lib/core"
)

// Switch represents a switch expression.
type Switch struct {
	value    interface{}
	patterns []core.Value
	values   []int
}

// NewSwitch creates a switch expression.
func NewSwitch(ps []core.Value, vs []int) Switch {
	if len(ps) != len(vs) {
		panic(fmt.Errorf(
			"A number of patterns (%d) doesn't match with a number of corresponding values (%d)",
			len(ps),
			len(vs)))
	} else if len(ps) == 0 {
		panic(fmt.Errorf("A number of patterns must be more than 0"))
	}

	return Switch{ps, vs}
}

func (s Switch) compileToDict() core.DictionaryType {
	ts := make([]*core.Thunk, 0, len(s.values))

	for _, v := range s.values {
		ts = append(ts, core.NewNumber(float64(v)))
	}

	return core.NewDictionary(s.patterns, ts).Eval().(core.DictionaryType)
}
{'fraction_non_alphanumeric': 0.15384615384615385, 'fraction_numerical': 0.005871990604815032, 'mean_word_length': 3.896551724137931, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2445190', 'n_tokens_mistral': 630, 'n_tokens_neox': 592, 'n_words': 173}