<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>But alternative does not apply function to first Nothing. `maybe`
      can exec function on Nothing or apply another one on Just.</p>
    <p>maybe (g x) id (f x) ?<br>
    </p>
    <br>
    <div class="moz-cite-prefix">31.07.2018 11:10, Imants Cekusins
      wrotes:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAP1qinZTzSB8R6Zbc+HqbVCXDM6qaYKHUd8uuePR8rNpNBg0aA@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <div dir="ltr">Salut Marc,
        <div><br>
        </div>
        <div>Are you looking for Alternative by any chance:</div>
        <div>
          <div
style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><a
href="http://hackage.haskell.org/package/base-4.11.1.0/docs/Control-Applicative.html#t:Alternative"
              moz-do-not-send="true">http://hackage.haskell.org/package/base-4.11.1.0/docs/Control-Applicative.html#t:Alternative</a><br>
          </div>
          <br class="gmail-Apple-interchange-newline">
          <br>
        </div>
        <div>
          <div>Prelude> :m Control.Applicative</div>
          <div>Prelude Control.Applicative> Just 1 <|> Just
            2::Maybe Int</div>
          <div>Just 1</div>
          <div>Prelude Control.Applicative> Nothing <|> Just
            2::Maybe Int</div>
          <div>Just 2</div>
          <div><br>
          </div>
          <div><br>
          </div>
          <div><br>
          </div>
        </div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On 31 July 2018 at 10:47, Marc Busqué <span
            dir="ltr"><<a href="mailto:marc@lamarciana.com"
              target="_blank" moz-do-not-send="true">marc@lamarciana.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">Apologies,
            I clearly asked the question in a rushed way...<br>
            <br>
            I'm working with [req](<a
              href="http://hackage.haskell.org/package/req"
              rel="noreferrer" target="_blank" moz-do-not-send="true">http://hackage.haskell.o<wbr>rg/package/req</a>)
            package.<br>
            I need to parse a url from a string, but I don't know
            whether its schema<br>
            will be `http` or `https`. However, `req` just provides me
            with two<br>
            functions:<br>
            <br>
            ```<br>
            parseUrlHttp :: ByteString -> Maybe (Url Http, Option
            scheme)<br>
            parseUrlHttps :: ByteString -> Maybe (Url Https, Option
            scheme)<br>
            ```<br>
            <br>
            As I don't know the schema beforehand, I have to apply one
            of the two<br>
            functions, do a case analysis on its result and, depending
            on the<br>
            result, call the second one or return the first result.<br>
            <br>
            What I think is a common case here (perhaps I'm wrong) is
            the need to<br>
            choose between two or more `Maybe` values where at most one
            of them will<br>
            be a `Just`. `maybe` does not do that. `catMaybes` could be
            used for<br>
            that when all the `Maybe` have the same inner type, but it
            is not the<br>
            exact abstraction and it would need more code (just like
            simply doing a<br>
            case analysis).<br>
            <br>
            Thanks and, again, sorry for the hurried question before (I
            don't like<br>
            when I see it from others :()<br>
            <br>
            Marc Busqué<br>
            <a href="http://waiting-for-dev.github.io/about/"
              rel="noreferrer" target="_blank" moz-do-not-send="true">http://waiting-for-dev.github.<wbr>io/about/</a><br>
            <br>
            On Tue, 31 Jul 2018, Paul wrote:<br>
            <br>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <br>
              Something like "maybe" function?<br>
              <br>
              <br>
              31.07.2018 10:07, Marc Busqué wrotes:<br>
                    Hi!<br>
              <br>
                    I have two functions:<br>
              <br>
                    ```<br>
                    foo :: a -> Maybe b<br>
                    bar :: a -> Maybe c<br>
                    ```<br>
              <br>
                    From which I want to build a higher order function:<br>
              <br>
                    ```<br>
                    foobar :: a -> (a -> Maybe b) -> (a ->
              Maybe c) -> Either b c<br>
                    ```<br>
              <br>
                    The implementation I need is:<br>
              <br>
                    ```<br>
                    foobar x f g =<br>
                      case (f x) of<br>
                        Nothing -> g x<br>
                        Just y  -> Just y<br>
                    ```<br>
              <br>
                    I'm a bit surprised that looking at hoogle I don't
              find a built-in<br>
                    solution for this quite common need for `Maybe`
              types (or perhaps for<br>
                    any monad).<br>
              <br>
                    Am I looking in the wrong way? Does it exist a
              similar abstraction but<br>
                    with a different shape?<br>
              <br>
                    Thanks in advance,<br>
              <br>
                    Marc Busqué<br>
                    <a href="http://waiting-for-dev.github.io/about/"
                rel="noreferrer" target="_blank" moz-do-not-send="true">http://waiting-for-dev.github.<wbr>io/about/</a><br>
              <br>
              <br>
              ______________________________<wbr>_________________<br>
              Haskell-Cafe mailing list<br>
              To (un)subscribe, modify options or view archives go to:<br>
              <a
                href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe"
                rel="noreferrer" target="_blank" moz-do-not-send="true">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/haskell-caf<wbr>e</a><br>
              Only members subscribed via the mailman list are allowed
              to post.<br>
              <br>
              <br>
              <br>
            </blockquote>
            <br>
            ______________________________<wbr>_________________<br>
            Haskell-Cafe mailing list<br>
            To (un)subscribe, modify options or view archives go to:<br>
            <a
              href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe"
              rel="noreferrer" target="_blank" moz-do-not-send="true">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/haskell-<wbr>cafe</a><br>
            Only members subscribed via the mailman list are allowed to
            post.<br>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>