Skip to main content

oxilean_parse/pattern/
patterncompiler_bound_var_set_group.rs

1//! # PatternCompiler - bound_var_set_group Methods
2//!
3//! This module contains method implementations for `PatternCompiler`.
4//!
5//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
6
7use crate::Pattern;
8use std::collections::HashSet;
9
10use super::patterncompiler_type::PatternCompiler;
11
12impl PatternCompiler {
13    /// Get all variables bound by a pattern as a set.
14    pub fn bound_var_set(&self, pattern: &Pattern) -> HashSet<String> {
15        let names = self.extract_bound_names(pattern);
16        names.into_iter().collect()
17    }
18    /// Check if patterns bind the same variables.
19    pub fn same_bindings(&self, patterns: &[Pattern]) -> bool {
20        if patterns.is_empty() {
21            return true;
22        }
23        let first_set = self.bound_var_set(&patterns[0]);
24        patterns
25            .iter()
26            .skip(1)
27            .all(|p| self.bound_var_set(p) == first_set)
28    }
29}