Hey thank you!

On Wednesday, August 3, 2016 at 4:51:55 PM UTC-7, Joey Eremondi wrote:
>
> The key here is to use the wildcard _ in your pattern matching, which will 
> match any value. 
>
> You can also bundle your arguments in a tuple, without needing to use 
> records.
>
> forecastProtected : Maybe Float -> Maybe Float -> Maybe Float -> (List 
> Int) -> List Float
> forecastProtected q d b months =
>   case (q, d, b) of
>       ( Just qF, Just dF, Just bF ) -> forecast qF dF bF months
>       _ -> []
>
> Note also that your syntax was wrong in your case: Maybe is a type, not a 
> value, so you can never use it in a pattern match. You need to match either 
> against the constructors (Just, Nothing) or wildcards, or variables.
>
> On Wed, Aug 3, 2016 at 4:44 PM, Austin B <[email protected] <javascript:>> 
> wrote:
>
>> I am trying to ensure that three arguments to a function are all not 
>> Nothing.
>>
>> Right now I have this (below), which works, but uses "withDefault." I 
>> want to avoid this because the default values are meaningless and I want to 
>> clearly and fundamentally avoid any possible situation where a Nothing gets 
>> through to the "else" part
>>
>> forecastProtected : Maybe Float -> Maybe Float -> Maybe Float -> (List 
>> Int) -> List Float
>> forecastProtected q d b months =
>>   if List.any (\m -> m == Nothing) [q, e, b] then []
>>   else
>>     forecast
>>       (withDefault 0 q)
>>       (withDefault 0 d)
>>       (withDefault 0 b)
>>       months
>>
>>
>>  I am hoping to do something like this:
>> forecastProtected : Maybe Float -> Maybe Float -> Maybe Float -> (List 
>> Int) -> List Float
>> forecastProtected q d b months =
>>   let
>>     params = {q = q, d = d, b = b}
>>   in
>>     case params of
>>       { Just qF, Just dF, Just bF } -> forecast qF dF bF months
>>       { Maybe, Maybe, Maybe } -> []
>>
>> which more clearly shows what I am trying to achieve. Could someone point 
>> me to the appropriate syntax for this? Also the 'F' in qF, dF, and bF are 
>> "Float" to avoid masking of variables (not sure how this happens in elm); 
>> it would be best if I could avoid this complication too.
>>
>> Thanks everyone for all your help as I'm getting started!
>> Austin
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Elm Discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to