Perhaps we could think of a different name - runList is very general and
doesn't give any information about what the function does. Perhaps
something like 'headOr', 'fromHead', ...?


On Mon, Feb 17, 2014 at 10:53 AM, Petr Pudlák <[email protected]> wrote:

> LGTM, thanks.
>
>
> On Sat, Feb 15, 2014 at 12:40 AM, Klaus Aehlig <[email protected]> wrote:
>
>> The list monad provides convenient syntax for non-deterministic
>> algorithms. Add a function leaving that monad with this intuition
>> in mind.
>>
>> Signed-off-by: Klaus Aehlig <[email protected]>
>> ---
>>  src/Ganeti/BasicTypes.hs | 7 +++++++
>>  1 file changed, 7 insertions(+)
>>
>> diff --git a/src/Ganeti/BasicTypes.hs b/src/Ganeti/BasicTypes.hs
>> index 30ebc8b..42acd7b 100644
>> --- a/src/Ganeti/BasicTypes.hs
>> +++ b/src/Ganeti/BasicTypes.hs
>> @@ -48,6 +48,7 @@ module Ganeti.BasicTypes
>>    , handleErrorT
>>    , iterateOk
>>    , select
>> +  , runList
>>    , LookupResult(..)
>>    , MatchPriority(..)
>>    , lookupName
>> @@ -312,6 +313,12 @@ select :: a            -- ^ default result
>>         -> a            -- ^ first result which has a True condition, or
>> default
>>  select def = maybe def snd . find fst
>>
>> +-- | Apply a function to the first element of a list, return the default
>> +-- value, if the list is empty. This is just a convenient combination of
>> +-- maybe and listToMaybe.
>> +runList :: a -> (b -> a) -> [b] -> a
>> +runList a f = maybe a f . listToMaybe
>> +
>>  -- * Lookup of partial names functionality
>>
>>  -- | The priority of a match in a lookup result.
>> --
>> 1.9.0.rc1.175.g0b1dcb5
>>
>>
>

Reply via email to