Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
220 lines (139 sloc) 7.13 KB

Module ephp_array

The PHP Array is a collection that could be used as a simple array or a hash.

Description

This module helps to create an structure to handle the PHP Array.

An example for the use of this module:

       Array0 = ephp_array:new().
       Array1 = ephp_array:store(auto, <<"hello world!">>).
       Array2 = ephp_array:store(auto, <<"bye!">>).
       ArrayN = ephp_array:from_list([1, 2, 3, 4, 5]).

Function Index

current/1retrieves the element under the cursor.
cursor/2set the cursor for an array.
erase/2removes an element from the array given the index.
find/2finds an element by the key passed as a param.
find/3finds an element by the passed as a param.
first/1moves the cursor to the begin of the array and retrieves that element.
fold/3performs a fold on all of the elements in the array given an initial value and changing that value in each element.
from_list/1transform the list passed as param in a PHP Array.
last/1moves the cursor to the end of the array and retrieves that element.
map/2performs a map action on all of the elemnts in the array.
new/0creates an empty PHP Array structure.
next/1moves the cursor the to next element and retrieves that element.
prev/1moves the cursor to the previous element and retrieves that element.
size/1retrieve the size of the array.
store/3stores a new element given a key and a value.
to_list/1transform a PHP Array to a property list.

Function Details

current/1


current(Ephp_array::ephp_array()) -> {ok, mixed()} | {error, empty | enocursor}

retrieves the element under the cursor.

cursor/2


cursor(Ephp_array::ephp_array(), Cursor::pos_integer() | false) -> ephp_array()

set the cursor for an array.

erase/2


erase(Key::mixed(), Ephp_array::ephp_array()) -> ephp_array()

removes an element from the array given the index.

find/2


find(Key::mixed(), Ephp_array::ephp_array()) -> {ok, mixed()} | error

finds an element by the key passed as a param.

find/3


find(Key::mixed(), Array::ephp_array(), Default::mixed()) -> mixed()

finds an element by the passed as a param. If the value isn't found the default value passed as param is returned.

first/1


first(Ephp_array::ephp_array()) -> {ok, mixed(), ephp_array()} | {error, empty}

moves the cursor to the begin of the array and retrieves that element.

fold/3


fold(Fun::function(), Initial::mixed(), Ephp_array::ephp_array()) -> mixed()

performs a fold on all of the elements in the array given an initial value and changing that value in each element.

from_list/1


from_list(List::[mixed()]) -> ephp_array()

transform the list passed as param in a PHP Array.

last/1


last(Ephp_array::ephp_array()) -> {ok, mixed(), ephp_array()} | {error, empty}

moves the cursor to the end of the array and retrieves that element.

map/2


map(Fun::function(), Ephp_array::ephp_array()) -> ephp_array()

performs a map action on all of the elemnts in the array.

new/0


new() -> ephp_array()

creates an empty PHP Array structure.

next/1


next(Ephp_array::ephp_array()) -> {ok, mixed(), ephp_array()} | {error, eof | empty | enocursor}

moves the cursor the to next element and retrieves that element.

prev/1


prev(Ephp_array::ephp_array()) -> {ok, mixed(), ephp_array()} | {error, bof | empty | enocursor}

moves the cursor to the previous element and retrieves that element.

size/1


size(Ephp_array::ephp_array()) -> non_neg_integer()

retrieve the size of the array.

store/3


store(Key::auto | mixed(), Value::mixed(), Ephp_array::ephp_array()) -> ephp_array()

stores a new element given a key and a value. If the key passed is auto the key is autogenerated based on the last numeric index used.

to_list/1


to_list(Ephp_array::ephp_array()) -> [mixed()]

transform a PHP Array to a property list.