[erlang-questions] Bounded length()
Erik Søe Sørensen
eriksoe@REDACTED
Wed Apr 10 11:28:31 CEST 2013
A pro pos split_at_most():
I've at times wished for a guard function 'lists:length_at_most(L,N)' -
something which determines min(length(L),N) in the non-stupid way, i.e.
counting the elements of the list but stopping when it reaches N.
>From time to time, I run into situations where I just need to know "is this
lists 'large'?", and it feels wasteful then to measure its entire length
when you know it might *be* quite large. And pattern-matching for [_,_,_,_,
... ,_|_] isn't nice (or efficient) either when the threshold length is,
say, a hundred.
Is this just me, or has anyone else run into such cases?
2013/4/10 Richard A. O'Keefe <ok@REDACTED>
> There are actually two different things that someone might want to do:
>
> (X) I want *exactly* N items from this sequence:
> n -> seq -> (pref, suff) where pref++suff == seq && #pref == n
>
> (Y) I want *at most* N items from this sequence:
> n -> seq -> (pref, suff) where pref++suff == seq &&
> #pref = min(#seq, n)
>
[snip]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130410/466ebf23/attachment.htm>
More information about the erlang-questions
mailing list