From 15d58323a97f1c8891afe899db37736176cb92ee Mon Sep 17 00:00:00 2001 From: Seungheon Oh Date: Wed, 25 May 2022 14:35:57 -0500 Subject: [PATCH] better queries --- agora-spec/Spec/Specification.hs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/agora-spec/Spec/Specification.hs b/agora-spec/Spec/Specification.hs index 9570a30..3e2441e 100644 --- a/agora-spec/Spec/Specification.hs +++ b/agora-spec/Spec/Specification.hs @@ -47,7 +47,6 @@ module Spec.Specification ( toTestTree, ) where -import Data.Maybe (catMaybes) import Plutarch.Api.V1 (PMintingPolicy, PValidator) import Plutarch.Builtin (pforgetData) import Plutarch.Evaluate (evalScript) @@ -98,25 +97,18 @@ group name st | otherwise = Group name st -- | Query specific @Specification@ from a tree. -getSpecification :: String -> SpecificationTree -> Maybe Specification +getSpecification :: String -> SpecificationTree -> [Specification] getSpecification name (Terminal spec@(Specification sn _ _)) - | name == sn = Just spec - | otherwise = Nothing -getSpecification name (Group _ st) - | length specs == 1 = Just $ head specs - | otherwise = Nothing - where - specs = catMaybes $ getSpecification name <$> st + | name == sn = [spec] + | otherwise = [] +getSpecification name (Group _ st) = mconcat $ (getSpecification name) <$> st -- | Query specific @SpecificationTree@ from a tree. -getSpecificationTree :: String -> SpecificationTree -> Maybe SpecificationTree +getSpecificationTree :: String -> SpecificationTree -> [SpecificationTree] getSpecificationTree name specTree@(Group gn st) - | gn == name = Just specTree - | length trees == 1 = Just $ head trees - | otherwise = Nothing - where - trees = catMaybes $ getSpecificationTree name <$> st -getSpecificationTree _ _ = Nothing + | gn == name = [specTree] + | otherwise = mconcat $ (getSpecificationTree name) <$> st +getSpecificationTree _ _ = [] -- | Convert @SpecificationTree@ into @TestTree@ to be used as a unit test. toTestTree :: SpecificationTree -> TestTree