[Haskell-cafe] [Maybe Int] sans Nothings
michael rice
nowgate at yahoo.com
Mon May 23 19:52:21 CEST 2011
Thanks, all.
Earlier, I was going to ask how to break out of a sequence op prematurely, i.e., you give it some replication number but want to break early if you get an end-flag value. While I was composing the post I thought of using Maybe for the good values and Nothing for the end value. Ergo, losing the Nothings at the end.
I was passing a map and an empty list into some state, but since the map doesn't change once it's created I moved it into a Reader. I was using the list to collect the elements but thought I can get that functionality automatically using sequence.
So, one thing leads to another. It's interesting how ideas begin bubbling up after one absorbs some critical mass of Haskell.
Michael
--- On Mon, 5/23/11, Malcolm Wallace <malcolm.wallace at me.com> wrote:
From: Malcolm Wallace <malcolm.wallace at me.com>
Subject: Re: [Haskell-cafe] [Maybe Int] sans Nothings
To: "haskell-cafe Cafe" <haskell-cafe at haskell.org>
Date: Monday, May 23, 2011, 12:35 PM
On 23 May 2011, at 17:20, michael rice wrote:
> What's the best way to end up with a list composed of only the Just values,
> no Nothings?
Alternatively,
[ x | Just x <- originals ]
It also occurs to me that perhaps you still want the Just constructors.
[ Just x | Just x <- originals ]
[ x | x@(Just _) <- originals ]
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110523/36f23154/attachment.htm>
More information about the Haskell-Cafe
mailing list