Module my_lists

My Lists Library.

Copyright © 2003 - 2004 Enrique Marcote Peña

Version: 1.0, {19 Feb 2003} 12:29:46.

Authors: Enrique Marcote Peña (mpquique@users.sourceforge.net) [web site: http://www.des.udc.es/~mpquique/].

Description

My Lists Library.

Additional functions for list processing.

Changes 0.2 -> 1.0

[12 May 2004]

Function Index

asearch/2Gets the first Element on the List where APred(Element) /= false.
cut/2Cuts a List by an Index into two sublists.
first/2Gets the first Element of List where Pred is true.
has_duplicates/1Determines if a list has duplicates or not.
is_deep/1Returns true if List is a deep list, false otherwise.
keyindex/3Gets the Index of the tuple on TupleList whose Nth element is Key.
random/2Creates a list of random integers with Length elementes.
random_seq/2Creates an ordered list of random integers with Length elements.
search/2Gets the first Element on the List where Pred(Element) == true.
split/2Splits a List into two lists where
List == List1 ++ List2 and length(List1) == N.
splitwith/2Splits a List into two lists where elements on List1 satisfy Pred.
to_integer/1Converts a list of octets to an integer.

Function Details

asearch/2

asearch(APred::APred, List::List) -> Result

Gets the first Element on the List where APred(Element) /= false.

APred is an approximate predicate that returns true, false or approximate.

If matching is ambiguous, there is more than one element on the list where the approximate-predicate returns approximate, false is returned. This behaviour may be changed in the future returning the atom ambiguous is such circumstances.

See also: my_string:aequal/2, my_string:aequal/6.

cut/2

cut(List::List, Index::Index) -> {Prefix, Suffix}

Cuts a List by an Index into two sublists. Prefix ++ Suffix == List.

> my_lists:cut([a, b, c, d, e], 3).
{[a, b, c], [d, e]}

first/2

first(Pred::Pred, T::List) -> Element

Gets the first Element of List where Pred is true.

This function fails if no element on List satisfies Pred.

has_duplicates/1

has_duplicates(T::List) -> bool()

Determines if a list has duplicates or not.

is_deep/1

is_deep(T::List) -> bool()

Returns true if List is a deep list, false otherwise.

keyindex/3

keyindex(Key::Key, N::N, TupleList::TupleList) -> Index

Gets the Index of the tuple on TupleList whose Nth element is Key.

The functions fails if no element with such a Key exists on TupleList.

random/2

random(Max::Max, Length::Length) -> List

Creates a list of random integers with Length elementes.

Duplicates allowed, the values will be between 1 and Max (both included).

See also: random_seq/2.

random_seq/2

random_seq(Max::Max, Length::Length) -> List

Creates an ordered list of random integers with Length elements.

No duplicates allowed, the values will be between 1 and Max (both included).

See also: random/2, random_add/3, random_del/3.

search/2

search(Pred::Pred, T::List) -> Result

Gets the first Element on the List where Pred(Element) == true.

split/2

split(List::List, N::N) -> {List1, List2}

Splits a List into two lists where
List == List1 ++ List2 and length(List1) == N.

I couldn't find it, but I'm sure this function must already exist.

splitwith/2

splitwith(Pred::Pred, L::List) -> {List1, List2}

Splits a List into two lists where elements on List1 satisfy Pred. List2 holds the elements for which Pred is false.

Ordering is preserved.

to_integer/1

to_integer(OctetList::OctetList) -> int()

Converts a list of octets to an integer.

Please notice the difference:

48> my_lists:to_integer("100").
3223600
49> list_to_integer("100").
100
50> my_lists:to_integer("F").
70
51> list_to_integer("F").
=ERROR REPORT==== 21-Mar-2003::12:38:43 ===
Error in process <0.118.0> with exit value: {badarg,
[{erlang,list_to_integer,["F"]},{erl_eval,expr,3},{erl_eval,exprs,4},
{shell,eval_loop,2}]}
** exited: {badarg,[{erlang,list_to_integer,["F"]},
{erl_eval,expr,3},
{erl_eval,exprs,4},
{shell,eval_loop,2}]} **

See also: list_to_integer/1.