-- Copyright 2013 Evan Laforge
-- This program is distributed under the terms of the GNU General Public
-- License 3.0, see COPYING or http://www.gnu.org/licenses/gpl-3.0.txt

module Cmd.Repl.Util where
import qualified Data.Map as Map
import qualified Data.Text as Text

import qualified Derive.ScoreT as ScoreT
import qualified Ui.Id as Id

import           Global


type Instrument = Text

-- | Create a 'ScoreT.Instrument'.  Drop a leading @>@, since I often
-- accidentally include one.
instrument :: Instrument -> ScoreT.Instrument
instrument :: Instrument -> Instrument
instrument = Instrument -> Instrument
ScoreT.Instrument forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Instrument -> Instrument
Text.dropWhile (forall a. Eq a => a -> a -> Bool
==Char
'>')

match_map :: Id.Ident id => Text -> Map id a -> Map id a
match_map :: forall id a. Ident id => Instrument -> Map id a -> Map id a
match_map Instrument
match = forall k a. (k -> a -> Bool) -> Map k a -> Map k a
Map.filterWithKey (\id
k a
_ -> forall id. Ident id => Instrument -> id -> Bool
match_id Instrument
match id
k)

-- | True if the ID contains the given substring.
match_id :: Id.Ident id => Text -> id -> Bool
match_id :: forall id. Ident id => Instrument -> id -> Bool
match_id Instrument
sub = (Instrument
sub `Text.isInfixOf`) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Id -> Instrument
Id.show_id forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Ident a => a -> Id
Id.unpack_id