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/`].

Additional functions for list processing.

- New functions: first/2, is_deep/1, keyindex/3 and splitwith/2.

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

cut/2 | Cuts a List by an Index into two sublists. |

first/2 | Gets the first Element of List where Pred
is true. |

has_duplicates/1 | Determines if a list has duplicates or not. |

is_deep/1 | Returns true if List is a deep list, false
otherwise. |

keyindex/3 | Gets the Index of the tuple on TupleList whose
Nth element is Key. |

random/2 | Creates a list of random integers with Length elementes. |

random_seq/2 | Creates an ordered list of random integers with Length
elements. |

search/2 | Gets the first Element on the List where
Pred(Element) == true. |

split/2 | Splits a List into two lists whereList == List1 ++ List2 and length(List1) == N. |

splitwith/2 | Splits a List into two lists where elements on List1
satisfy Pred. |

to_integer/1 | Converts a list of octets to an integer. |

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

`List = [term()]``Result = {value, Element} | false``Element = term()`

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

`APred = fun(X) -> true | approximate | 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(List::List, Index::Index) -> {Prefix, Suffix}`

`List = [term()]``Index = int()``Prefix = [term()]``Suffix = [term()]`

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(Pred::Pred, T::List) -> Element`

`List = [Element]``Element = term()`

Gets the first `Element` of `List` where `Pred`
is `true`.

This function fails if no element on `List` satisfies
`Pred`.

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

`List = term()`

Determines if a list has duplicates or not.

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

`List = [Element]``Element = term()`

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

`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(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(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(Pred::Pred, T::List) -> Result`

`List = [term()]``Result = {value, Element} | false``Element = term()`

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

`Pred = fun(X) -> bool()`

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

`List = [Element]``List1 = [Element]``List2 = [Element]``Element = term()``N = int()`

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(Pred::Pred, L::List) -> {List1, List2}`

`List = [term()]``List1 = [term()]``List2 = [term()]`

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

`Pred = fun(X) -> bool()`

Ordering is preserved.

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

`OctetList = [Octet]``Octet = char()`

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.