Module blist

String Processing Functions for binary encoded strings.

Copyright © (C) 2013-2020, Jan Henry Nystrom <JanHenryNystrom@gmail.com> -------------------------------------------------------------------

Authors: Jan Henry Nystrom (JanHenryNystrom@gmail.com).

Description

String Processing Functions for binary encoded strings.

This is a drop in replacement for the lists module in stdlib working on binaries interpreted as strings of octets in Latin1.

The module generates ref binaries as much as possible so if copies are more suitable apply binary/copy/1 on the result.

All functions in the stblib lists that would operate on tuples operate on equally sized octet blobs binaries.

Data Types

thing()

thing() = atom() | integer() | float() | string() | binary()

Function Index

all/2 Returns true if Pred(Elem) returns true for all elements Elem in String, otherwise false.
any/2 Returns true if Pred(Elem) returns true for at least one element Elem in String.
append/1 Returns a String in which all the sub-strings of ListOfStrings have been appended.
append/2 Returns a new list String3 which is made from the elements of String1 followed by the elements of String2.
concat/1 Concatenates the text representation of the elements of Things.
delete/2 Returns a copy of String1 where the first element matching Elem is deleted, if there is such an element.
dropwhile/2 Drops elements Elem from String1 while Pred(Elem) returns true and returns the remaining string.
duplicate/2 Returns a string which contains N copies of the term Elem.
filter/2 String2 is a string of all elements Elem in String1 for which Pred(Elem) returns true.
flatlength/1 Equivalent to length(iolist_to_binary(DeepString)), but more efficient.
flatmap/2 Takes a function from As to strings of Bs, and a string of As (String1) and produces a string of Bs by applying the function to every element in String1 and appending the resulting strings.
flatten/1 Returns a flattened version of DeepString.
flatten/2 Returns a flattened version of DeepString with the tail Tail appended.
foldl/3 Calls Fun(Elem, AccIn) on successive elements A of String, starting with AccIn == Acc0.
foldr/3 Like foldl/3, but the string is traversed from right to left.
foreach/2 Calls Fun(Elem) for each element Elem in String.
keydelete/4 Returns a copy of BlobSequence1 where the first occurrence of a blob whose Nth element compares equal to Key is deleted, if there is such a blob.
keyfind/4 Searches the list of tuples BlobSequence for a tuple whose Nth element compares equal to Key.
keymap/4 Returns a sequence of blobs where, for each blob in BlobSequence1, the Nth element Octet of the blob has been replaced with the result of calling Fun(Octet).
keymember/4 Returns true if there is a blob in BlobSequence whose Nth element compares equal to Key, otherwise false.
keymerge/4 Returns the sorted binary formed by merging BlobSequence1 and BlobSequence2.
keyreplace/5 Returns a copy of BlobSequence1 where the first occurrence of a T blob whose Nth element compares equal to Key is replaced with NewBlob, if there is such a blob T.
keysearch/4 Searches the sequence of blobs BlobSequence for a blob whose Nth element compares equal to Key.
keysort/3 Returns a binary containing the sorted elements of the blob sequence BlobSequence1.
keystore/5 Returns a copy of BlobSequence1 where the first occurrence of a blob T whose Nth element compares equal to Key is replaced with NewBlob, if there is such a tuple T.
keytake/4 Searches the sequence of blobs BlobSequence1 for a blob whose Nth element compares equal to Key.
last/1 Returns the last octet in the binary.
map/2 Takes a function from octets to octets, and a binary produces binary by applying the function to every octet in the binary.
mapfoldl/3 mapfoldl combines the operations of map/2 and foldl/3 into one pass.
mapfoldr/3 mapfoldr combines the operations of map/2 and foldr/3 into one pass.
max/1 Returns the first octet of the binary that compares greater than or equal to all other octets in the binary.
member/2 Returns true if Elem matches some element of Binary, otherwise false.
merge/1 Returns the sorted binary formed by merging all the sub-binaries of ListOfBinaries.
merge/2 Returns the sorted binary formed by merging Binary1 and Binary2.
merge/3 Returns the sorted binary formed by merging Binary1 and Binary2.
merge3/3 Returns the sorted binary formed by merging Binary1, Binary2 and Binary3.
min/1 Returns the first octet of Binary that compares less than or equal to all other octets of Binary.
nth/2 Returns the Nth octet of Binary.
nthtail/2 Returns the Nth tail of Binary, that is, the sub-binary of Binary starting at N+1 and continuing up to the end of the binary.
partition/2 Partitions Binary into two binaries, where the first binary contains all octets for which Pred(Octet) returns true, and the second binary contains all octets for which Pred(Octet) returns false.
prefix/2 Returns true if Binary1 is a prefix of Binary2, otherwise false.
reverse/1 Returns a string with the elements in String1 in reverse order.
reverse/2 Returns a string with the elements in String1 in reverse order, with the tail Tail appended.
seq/2 Returns a sequence of integers which starts with From and contains the successive results of adding 1 to the previous element, until To has been reached number encompassed by the sequence.
seq/3 Returns a sequence of integers which starts with From and contains the successive results of adding Incr to the previous element, until To has been reached or passed (in the latter case, To is not an element of the sequence).
sort/1 Returns a binary containing the sorted octets of Binary1.
sort/2 Returns a binary containing the sorted octets of Binary1, according to the ordering function Fun.
split/2 Splits Binary1 into Binary2 and Binary3.
splitwith/2 Partitions Binary into two binaries according to Pred.
sublist/2 Returns the sub-binary of Binary1 starting at position 1 and with (max) Len octets.
sublist/3 Returns the sub-binary of Binary1 starting at Start and with (max) Len octets.
subtract/2 Returns a new binary Binary3 which is a copy of Binary1, subjected to the following procedure: for each octet in Binary2, its first occurrence in Binary1 is deleted.
suffix/2 Returns true if Binary1 is a suffix of Binary2, otherwise false.
sum/1 Returns the sum of the octets in binary.
takewhile/2 Takes octet Octet from Binary1 while Pred(Octet) returns true, that is, the function returns the longest prefix of the binary for which all octets satisfy the predicate.
ukeymerge/4 Returns the sorted binary formed by merging BlobSequence1 and BlobSequence2.
ukeysort/3 Returns a binary containing the sorted octets of the binary BlobSequence1 where all but the first blob of the blobs comparing equal have been deleted.
umerge/1 Returns the sorted binary formed by merging all the sub-binaries of ListOfBinaries.
umerge/2 Returns the sorted binary formed by merging Binary1 and Binary2.
umerge/3 Returns the sorted binary formed by merging Binary1 and Binary2.
umerge3/3 Returns the sorted binary formed by merging Binary1, Binary2 and Binary3.
unzip/1 "Unzips" a binary of two octet blobs into two binarys, where the first binary contains the first octet of each blob, and the second binary contains the second octet of each blob.
unzip3/1 "Unzips" a binary of three octet blobs into three binarys, where the first binary contains the first octet of each blob, the second binary contains the second octet of each blob, and the third binary contains the third octet of each blob.
usort/1 Returns a binary containing the sorted octets of Binary1 where all but the first octet of the octets comparing equal have been deleted.
usort/2 Returns a binary which contains the sorted octets of Binary1 where all but the first octet of the octets comparing equal according to the ordering function Fun have been deleted.
zip/2 "Zips" two binaries of equal length into one binary of two-blobs, where the first octet of each blob is taken from the first binary and the second octet is taken from corresponding octet in the second binary.
zip3/3 "Zips" three binaries of equal length into one binary of three-blobs, where the first octet of each blob is taken from the first binary, the second octet is taken from corresponding octet in the second binary, and the third octet is taken from the corresponding octet in the third binary.
zipwith/3 Combine the octets of two binarys of equal length into one binary.
zipwith3/4 Combine the octets of three binarys of equal length into one binary.

Function Details

all/2

all(Pred::fun((byte()) -> boolean()), X2::binary()) -> boolean()

Returns true if Pred(Elem) returns true for all elements Elem in String, otherwise false.

any/2

any(Pred::fun((byte()) -> boolean()), X2::binary()) -> boolean()

Returns true if Pred(Elem) returns true for at least one element Elem in String.

append/1

append(Binaries::[binary()]) -> binary()

Returns a String in which all the sub-strings of ListOfStrings have been appended.

append/2

append(Binary1::binary(), Binary2::binary()) -> binary()

Returns a new list String3 which is made from the elements of String1 followed by the elements of String2.

concat/1

concat(List::[thing()]) -> binary()

Concatenates the text representation of the elements of Things. The elements of Things can be atoms, integers, floats, strings, or binaries.

delete/2

delete(Elt::char(), Binary::binary()) -> binary()

Returns a copy of String1 where the first element matching Elem is deleted, if there is such an element.

dropwhile/2

dropwhile(Pred::fun((byte()) -> boolean()), Binary::binary()) -> binary()

Drops elements Elem from String1 while Pred(Elem) returns true and returns the remaining string.

duplicate/2

duplicate(N::pos_integer(), Char::byte()) -> binary()

Returns a string which contains N copies of the term Elem.

filter/2

filter(Pred::fun((byte()) -> boolean()), Binary::binary()) -> binary()

String2 is a string of all elements Elem in String1 for which Pred(Elem) returns true.

flatlength/1

flatlength(IOList::iolist()) -> non_neg_integer()

Equivalent to length(iolist_to_binary(DeepString)), but more efficient.

flatmap/2

flatmap(Fun::fun((byte()) -> binary()), Binary::binary()) -> binary()

Takes a function from As to strings of Bs, and a string of As (String1) and produces a string of Bs by applying the function to every element in String1 and appending the resulting strings.

flatten/1

flatten(IOList::iolist()) -> binary()

Returns a flattened version of DeepString.

flatten/2

flatten(IOList::iolist(), Binary::binary()) -> binary()

Returns a flattened version of DeepString with the tail Tail appended.

foldl/3

foldl(Fun::fun((byte(), Acc) -> Acc), Acc, X3::binary()) -> Acc

Calls Fun(Elem, AccIn) on successive elements A of String, starting with AccIn == Acc0. Fun/2 must return a new accumulator which is passed to the next call. The function returns the final value of the accumulator. Acc0 is returned if the string is empty.

foldr/3

foldr(Fun::fun((byte(), Acc) -> Acc), Acc, Binary::binary()) -> Acc

Like foldl/3, but the string is traversed from right to left.

foreach/2

foreach(Fun::fun((byte()) -> term()), X2::binary()) -> ok

Calls Fun(Elem) for each element Elem in String. This function is used for its side effects and the evaluation order is defined to be the same as the order of the elements in the string.

keydelete/4

keydelete(Key::byte(), N::pos_integer(), Size::pos_integer(), Binary::binary()) -> binary()

Returns a copy of BlobSequence1 where the first occurrence of a blob whose Nth element compares equal to Key is deleted, if there is such a blob.

keyfind/4

keyfind(Key::byte(), N::pos_integer(), Size::pos_integer(), Binary::binary()) -> binary() | false

Searches the list of tuples BlobSequence for a tuple whose Nth element compares equal to Key. Returns Blob if such a tuple is found, otherwise false.

keymap/4

keymap(F::fun((byte()) -> byte()), N::pos_integer(), Size::pos_integer(), Binary::binary()) -> binary()

Returns a sequence of blobs where, for each blob in BlobSequence1, the Nth element Octet of the blob has been replaced with the result of calling Fun(Octet).

keymember/4

keymember(Key::byte(), N::pos_integer(), Size::pos_integer(), Binary::binary()) -> boolean()

Returns true if there is a blob in BlobSequence whose Nth element compares equal to Key, otherwise false.

keymerge/4

keymerge(N::pos_integer(), Size::pos_integer(), Binary1::binary(), Binary2::binary()) -> binary()

Returns the sorted binary formed by merging BlobSequence1 and BlobSequence2. The merge is performed on the Nth element of each blob. Both BlobSequence1 and BlobSequence2 must be key-sorted prior to evaluating this function. When two blobs compare equal, the blob from BlobSequence1 is picked before the tuple from BlobSequence2.

keyreplace/5

keyreplace(Key::byte(), N::pos_integer(), Size::pos_integer(), Binary::binary(), Item::binary()) -> binary()

Returns a copy of BlobSequence1 where the first occurrence of a T blob whose Nth element compares equal to Key is replaced with NewBlob, if there is such a blob T.

keysearch/4

keysearch(Key::byte(), N::pos_integer(), Size::pos_integer(), Binary::binary()) -> {value, binary()} | false

Searches the sequence of blobs BlobSequence for a blob whose Nth element compares equal to Key. Returns {value, Blob} if such a blob is found, otherwise false.

keysort/3

keysort(N::pos_integer(), Size::pos_integer(), Binary::binary()) -> binary()

Returns a binary containing the sorted elements of the blob sequence BlobSequence1. Sorting is performed on the Nth element of the blobs. The sort is stable.

keystore/5

keystore(Key::byte(), N::pos_integer(), Size::pos_integer(), Binary::binary(), Item::binary()) -> binary()

Returns a copy of BlobSequence1 where the first occurrence of a blob T whose Nth element compares equal to Key is replaced with NewBlob, if there is such a tuple T. If there is no such blob T a copy of BlobSequence1 where NewBlob has been appended to the end is returned.

keytake/4

keytake(Key::byte(), N::pos_integer(), Size::pos_integer(), Binary::binary()) -> {value, binary(), binary()} | false

Searches the sequence of blobs BlobSequence1 for a blob whose Nth element compares equal to Key. Returns {value, Blob, BlobSequence2} if such a tuple is found, otherwise false. BlobSequence2 is a copy of BlobSequence1 where the first occurrence of Blob has been removed.

last/1

last(Binary::binary()) -> byte()

Returns the last octet in the binary.

map/2

map(F::fun((byte()) -> byte()), Binary::binary()) -> binary()

Takes a function from octets to octets, and a binary produces binary by applying the function to every octet in the binary. This function is used to obtain the return values. The evaluation order is implementation dependent.

mapfoldl/3

mapfoldl(Fun::fun((byte(), Acc) -> {byte(), Acc}), Acc, Binary::binary()) -> {binary(), Acc}

mapfoldl combines the operations of map/2 and foldl/3 into one pass.

mapfoldr/3

mapfoldr(Fun::fun((byte(), Acc) -> {byte(), Acc}), Acc, Binary::binary()) -> {binary(), Acc}

mapfoldr combines the operations of map/2 and foldr/3 into one pass

max/1

max(X1::binary()) -> byte()

Returns the first octet of the binary that compares greater than or equal to all other octets in the binary.

member/2

member(C::char(), X2::binary()) -> boolean()

Returns true if Elem matches some element of Binary, otherwise false.

merge/1

merge(Binaries::[binary()]) -> binary()

Returns the sorted binary formed by merging all the sub-binaries of ListOfBinaries. All sub-binaries must be sorted prior to evaluating this function. When two octets compare equal, the octets from the sub-binary with the lowest position in ListOfBinaries is picked before the other octet.

merge/2

merge(B1::binary(), B2::binary()) -> binary()

Returns the sorted binary formed by merging Binary1 and Binary2. Both Binary1 and Binary2 must be sorted prior to evaluating this function. When two octets compare equal, the octet from Binary1 is picked before the octet from Binary2.

merge/3

merge(Pred::fun((byte(), byte()) -> boolean()), B1::binary(), B2::binary()) -> binary()

Returns the sorted binary formed by merging Binary1 and Binary2. Both Binary1 and Binary2 must be sorted according to the ordering function Fun prior to evaluating this function. Fun(A, B) should return true if A compares less than or equal to B in the ordering, false otherwise. When two octets compare equal, the octet from Binary1 is picked before the octet from Binary2.

merge3/3

merge3(B1::binary(), B2::binary(), B3::binary()) -> binary()

Returns the sorted binary formed by merging Binary1, Binary2 and Binary3. All of Binary1, Binary2 and Binary3 must be sorted prior to evaluating this function. When two octets compare equal, the octet from Binary1, if there is such an octet, is picked before the other octet, otherwise the octet from Binary2 is picked before the octet from Binary3.

min/1

min(X1::binary()) -> byte()

Returns the first octet of Binary that compares less than or equal to all other octets of Binary.

nth/2

nth(Pos::pos_integer(), Binary::binary()) -> byte()

Returns the Nth octet of Binary. One based.

nthtail/2

nthtail(Pos::pos_integer(), Binary::binary()) -> binary()

Returns the Nth tail of Binary, that is, the sub-binary of Binary starting at N+1 and continuing up to the end of the binary.

partition/2

partition(Pred::fun((byte()) -> boolean()), Binary::binary()) -> {binary(), binary()}

Partitions Binary into two binaries, where the first binary contains all octets for which Pred(Octet) returns true, and the second binary contains all octets for which Pred(Octet) returns false.

prefix/2

prefix(Binary1::binary(), Binary2::binary()) -> boolean()

Returns true if Binary1 is a prefix of Binary2, otherwise false.

reverse/1

reverse(X1::binary()) -> binary()

Returns a string with the elements in String1 in reverse order.

reverse/2

reverse(Binary::binary(), Tail::binary()) -> binary()

Returns a string with the elements in String1 in reverse order, with the tail Tail appended.

seq/2

seq(From::byte(), To::byte()) -> binary()

Returns a sequence of integers which starts with From and contains the successive results of adding 1 to the previous element, until To has been reached number encompassed by the sequence. Wraps to zero when it reaches 255.

seq/3

seq(From::byte(), To::byte(), Incr::byte()) -> binary()

Returns a sequence of integers which starts with From and contains the successive results of adding Incr to the previous element, until To has been reached or passed (in the latter case, To is not an element of the sequence). Wraps to zero when it reaches 255.

sort/1

sort(Binary::binary()) -> binary()

Returns a binary containing the sorted octets of Binary1.

sort/2

sort(Fun::fun((byte(), byte()) -> boolean()), Binary::binary()) -> binary()

Returns a binary containing the sorted octets of Binary1, according to the ordering function Fun. Fun(A, B) should return true if A compares less than or equal to B in the ordering, false otherwise.

split/2

split(N::non_neg_integer(), Binary::binary()) -> {binary(), binary()}

Splits Binary1 into Binary2 and Binary3. Binary2 contains the first N octets and Binary3 the rest of the octets (the Nth tail).

splitwith/2

splitwith(Pred::fun((byte()) -> boolean()), Binary::binary()) -> {binary(), binary()}

Partitions Binary into two binaries according to Pred. splitwith/2 behaves as if it is defined as follows:

splitwith(Pred, Binary) -> {takewhile(Pred, Binary), dropwhile(Pred, Binary)}.

sublist/2

sublist(Binary::binary(), Len::pos_integer()) -> binary()

Returns the sub-binary of Binary1 starting at position 1 and with (max) Len octets. It is not an error for Len to exceed the length of the binary, in that case the whole binary is returned.

sublist/3

sublist(Binary::binary(), Start::pos_integer(), Len::pos_integer()) -> binary()

Returns the sub-binary of Binary1 starting at Start and with (max) Len octets. It is not an error for Start+Len to exceed the length of the binary.

subtract/2

subtract(Binary1::binary(), Binary2::binary()) -> binary()

Returns a new binary Binary3 which is a copy of Binary1, subjected to the following procedure: for each octet in Binary2, its first occurrence in Binary1 is deleted.

suffix/2

suffix(Binary1::binary(), Binary2::binary()) -> boolean()

Returns true if Binary1 is a suffix of Binary2, otherwise false.

sum/1

sum(Binary::binary()) -> integer()

Returns the sum of the octets in binary.

takewhile/2

takewhile(Pred::fun((byte()) -> boolean()), Binary::binary()) -> binary()

Takes octet Octet from Binary1 while Pred(Octet) returns true, that is, the function returns the longest prefix of the binary for which all octets satisfy the predicate.

ukeymerge/4

ukeymerge(N::pos_integer(), Size::pos_integer(), Binary1::binary(), Binary2::binary()) -> binary()

Returns the sorted binary formed by merging BlobSequence1 and BlobSequence2. The merge is performed on the Nth octet of each blob. Both BlobSequence1 and BlobSequence2 must be key-sorted without duplicates prior to evaluating this function. When two blobs compare equal, the blob from BlobSequence1 is picked and the one from BlobSequence2 deleted.

ukeysort/3

ukeysort(N::pos_integer(), Size::pos_integer(), Binary::binary()) -> binary()

Returns a binary containing the sorted octets of the binary BlobSequence1 where all but the first blob of the blobs comparing equal have been deleted. Sorting is performed on the Nth element of the blobs.

umerge/1

umerge(Binaries::[binary()]) -> binary()

Returns the sorted binary formed by merging all the sub-binaries of ListOfBinaries. All sub-binaries must be sorted and contain no duplicates prior to evaluating this function. When two elements compare equal, the element from the sub-binaries with the lowest position in ListOfBinaries is picked and the other one deleted.

umerge/2

umerge(B1::binary(), B2::binary()) -> binary()

Returns the sorted binary formed by merging Binary1 and Binary2. Both Binary1 and Binary2 must be sorted and contain no duplicates prior to evaluating this function. When two octets compare equal, the octet from Binary1 is picked and the one from Binary2 deleted.

umerge/3

umerge(Pred::fun((byte(), byte()) -> boolean()), B1::binary(), B2::binary()) -> binary()

Returns the sorted binary formed by merging Binary1 and Binary2. Both Binary1 and Binary2 must be sorted according to the ordering function Fun and contain no duplicates prior to evaluating this function. Fun(A, B) should return true if A compares less than or equal to B in the ordering, false otherwise. When two octets compare equal, the octet from Binary1 is picked and the one from Binary2 deleted.

umerge3/3

umerge3(B1::binary(), B2::binary(), B3::binary()) -> binary()

Returns the sorted binary formed by merging Binary1, Binary2 and Binary3. All of Binary1, Binary2 and Binary3 must be sorted and contain no duplicates prior to evaluating this function. When two octets compare equal, the octet from Binary1 is picked if there is such an octet, otherwise the octet from Binary2 is picked, and the other one deleted.

unzip/1

unzip(Binary::binary()) -> {binary(), binary()}

"Unzips" a binary of two octet blobs into two binarys, where the first binary contains the first octet of each blob, and the second binary contains the second octet of each blob.

unzip3/1

unzip3(Binary::binary()) -> {binary(), binary(), binary()}

"Unzips" a binary of three octet blobs into three binarys, where the first binary contains the first octet of each blob, the second binary contains the second octet of each blob, and the third binary contains the third octet of each blob.

usort/1

usort(Binary::binary()) -> binary()

Returns a binary containing the sorted octets of Binary1 where all but the first octet of the octets comparing equal have been deleted.

usort/2

usort(Fun::fun((byte(), byte()) -> boolean()), Binary::binary()) -> binary()

Returns a binary which contains the sorted octets of Binary1 where all but the first octet of the octets comparing equal according to the ordering function Fun have been deleted. Fun(A, B) should return true if A compares less than or equal to B in the ordering, false otherwise.

zip/2

zip(Binary1::binary(), Binary2::binary()) -> binary()

"Zips" two binaries of equal length into one binary of two-blobs, where the first octet of each blob is taken from the first binary and the second octet is taken from corresponding octet in the second binary.

zip3/3

zip3(Binary1::binary(), Binary2::binary(), Binary3::binary()) -> binary()

"Zips" three binaries of equal length into one binary of three-blobs, where the first octet of each blob is taken from the first binary, the second octet is taken from corresponding octet in the second binary, and the third octet is taken from the corresponding octet in the third binary.

zipwith/3

zipwith(Fun::fun((byte(), byte()) -> binary()), Binary1::binary(), Binary2::binary()) -> binary()

Combine the octets of two binarys of equal length into one binary. For each pair X, Y of binary octets from the two binarys, the binary in the result binary will be Combine(X, Y).

zipwith(fun(X, Y) -> <<X, Y>> end, Binary1, Binary2) is equivalent to zip(Binary1, Binary2).

zipwith3/4

zipwith3(Fun::fun((byte(), byte(), byte()) -> binary()), Binary1::binary(), Binary2::binary(), Binary3::binary()) -> binary()

Combine the octets of three binarys of equal length into one binary. For each triple X, Y, Z of binary octets from the thre binarys, the binary in the result binary will be Combine(X, Y, Z).

zipwith(fun(X, Y, Z) -> <<X, Y, Z>> end, Binary1, Binary2, Binary3) is equivalent to zip(Binary1, Binary2. Binary3).


Generated by EDoc