<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:large">yes both works, code looks like this now:</div><div class="gmail_default" style="font-size:large">-- remove the records having N°BD NULL<br><br> let fltWDS = Prelude.filter (\(Only a) -><br> case a of<br> Nothing -> False<br> Just a -> True)<br> bd_rows_WDS<br><br><br><br>-- let fltWDS = [a | Only (Just a) <- bd_rows_WDS]<br><br>-- let fltWDS = catMaybes (Prelude.map fromOnly bd_rows_WDS)<br><br><br> putStr "bd_rows_WDS filtered fltWDS ="<br> putStrLn $ show fltWDS<br><br> let lg_fltWDS = Prelude.length fltWDS<br> putStrLn ("lg_fltWDS = " ++ (show lg_fltWDS))<br><br><br> let resBDtxt = if lg_fltWDS == 0<br> then<br> Nothing<br> else<br> if lg_fltWDS == 1<br> then <br> --Just (Prelude.head fltWDS)<br> fromOnly (Prelude.head fltWDS)<br> else <br> --trace "WARNING: multiple BD in WDS result" (Just (Prelude.head fltWDS))<br> trace "WARNING: multiple BD in WDS result" fromOnly (Prelude.head fltWDS)<br><br> putStr "resBDtxt ="<br> putStrLn (maybe "Empty List" show resBDtxt)</div><div class="gmail_default" style="font-size:large"><br></div><div class="gmail_default" style="font-size:large">i will keep a Maybe type because in fact there is a possibility of having no result or one (extract sometimes from many) from the databases, so there is a possibility for Nothing i must keep and handle for the next instructions...<br></div><div class="gmail_default" style="font-size:large">thanks<br></div></div></div><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:large"><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jan 3, 2019 at 3:54 PM Neil Mayhew <<a href="mailto:neil_mayhew@users.sourceforge.net" target="_blank">neil_mayhew@users.sourceforge.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF">
On 2019-01-03 12:43 AM, Ganesh Sittampalam wrote:<br>
<blockquote type="cite">If you
did have [Maybe Text] you could use the library function<br>
<br>
catMaybes :: [Maybe a] -> [a]<br>
<br>
to both do the filtering and change the types.<br>
<br>
...<br>
<br>
But in your case you actually have [Only (Maybe Text)] rather than
[Maybe Text] so catMaybes won't work. One option is to use a list
comprehension instead:<br>
<br>
let fltWDS = [Only a | Only (Just a) <- bd_rows_WDS]<br>
</blockquote>
<br>
It probably would be helpful to remove the Only wrapper at this
stage, so this might be even better:<br>
<br>
let fltWDS = [a | Only (Just a) <- bd_rows_WDS]<br>
<br>
The way to do it with catMaybes would be to map with fromOnly first:<br>
<br>
let fltWDS = catMaybes (map fromOnly bd_rows_WDS)<br>
<br>
As Ganesh shows, there's no need for a type annotation after you've
done the query, because the compiler can infer the type [Text] from
the types of the functions that are used. The annotations are
necessary with query only because it's polymorphic and can work with
a wide variety of types.<br>
</div>
_______________________________________________<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">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div></div>