diff options
author | Peter Saxton <peterhsaxton@gmail.com> | 2020-05-29 08:41:16 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2020-05-29 13:06:51 +0100 |
commit | 84cfab50958409c862ec4bb36d7e32dec266e84b (patch) | |
tree | 96325554036cfebf8cc1162a8423ef77fda3492a /src | |
parent | 078b0b0483c90dd7c24df4650a2b5a8db61fc24a (diff) | |
download | gleam_stdlib-84cfab50958409c862ec4bb36d7e32dec266e84b.tar.gz gleam_stdlib-84cfab50958409c862ec4bb36d7e32dec266e84b.zip |
add append function
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/binary.gleam | 9 | ||||
-rw-r--r-- | src/gleam/binary_native.erl | 5 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/gleam/binary.gleam b/src/gleam/binary.gleam index 7c7e308..7ce8c3e 100644 --- a/src/gleam/binary.gleam +++ b/src/gleam/binary.gleam @@ -11,6 +11,15 @@ pub external fn from_string(String) -> Binary = pub external fn byte_size(Binary) -> Int = "erlang" "byte_size" +/// Create a new binary by joining two binaries. +/// +/// ## Examples +/// +/// > append(to: "butter", suffix: "fly") +/// "butterfly" +/// +pub external fn append(first: Binary, second: Binary) -> Binary = "binary_native" "append" + /// Extracts part of a binary. /// /// Binary part will start at given position and continue up to specified length. diff --git a/src/gleam/binary_native.erl b/src/gleam/binary_native.erl index 1969602..c7dfad7 100644 --- a/src/gleam/binary_native.erl +++ b/src/gleam/binary_native.erl @@ -1,5 +1,8 @@ -module (binary_native). --export ([int_to_u32/1, int_from_u32/1, part/3]). +-export ([int_to_u32/1, int_from_u32/1, append/2, part/3]). + +append(First, Second) -> + <<First/binary, Second/binary>>. part(Bin, Pos, Len) -> try {ok, binary:part(Bin, Pos, Len)} catch |