vec/vec4
Types
Values
pub fn decoder(
of inner: decode.Decoder(value),
) -> decode.Decoder(Vec4(value))
A decoder that decodes 4D vectors where all elements are decoded with a given decoder.
pub fn map(vector: Vec4(a), with fun: fn(a) -> b) -> Vec4(b)
Returns a new vector containing only the elements of the first vector after the function has been applied to each one.
Examples
Vec4(12, -34, 420, 69) |> map(fn(x) { x * 2 })
// -> Vec4(24, -68, 840, 138)
pub fn map2(
a: Vec4(a),
b: Vec4(b),
with fun: fn(a, b) -> c,
) -> Vec4(c)
Combines two vectors into a single vector using the given function.
Examples
Vec4(12, -34, 420, 69) |> map2(Vec4(1, 2, 3, 4), fn(x, y) { x * y })
// -> Vec4(12, -68, 1260, 276)
pub fn map_w(
vector: Vec4(value),
with fun: fn(value) -> value,
) -> Vec4(value)
Returns a new vector with the w element having had with
applied to it.
Examples
Vec4(12, -34, 420, 69) |> map_w(fn(n) { n * 2 })
// -> Vec4(12, -34, 420, 138)
pub fn map_x(
vector: Vec4(value),
with fun: fn(value) -> value,
) -> Vec4(value)
Returns a new vector with the x element having had with
applied to it.
Examples
Vec4(12, -34, 420, 69) |> map_x(fn(n) { n * 2 })
// -> Vec4(24, -34, 420, 69)
pub fn map_y(
vector: Vec4(value),
with fun: fn(value) -> value,
) -> Vec4(value)
Returns a new vector with the y element having had with
applied to it.
Examples
Vec4(12, -34, 420, 69) |> map_y(fn(n) { n * 2 })
// -> Vec4(12, -68, 420, 69)
pub fn map_z(
vector: Vec4(value),
with fun: fn(value) -> value,
) -> Vec4(value)
Returns a new vector with the z element having had with
applied to it.
Examples
Vec4(12, -34, 420, 69) |> map_z(fn(n) { n * 2 })
// -> Vec4(12, -34, 840, 69)
pub fn replace_w(
vector: Vec4(value),
to value: value,
) -> Vec4(value)
Returns a new vector with the w element replace with value
.
Examples
Vec4(12, -34, 420, 69) |> replace_w(777)
// -> Vec4(12, -34, 420, 777)
pub fn replace_x(
vector: Vec4(value),
to value: value,
) -> Vec4(value)
Returns a new vector with the x element replace with value
.
Examples
Vec4(12, -34, 420, 69) |> replace_x(777)
// -> Vec4(777, -34, 420, 69)
pub fn replace_y(
vector: Vec4(value),
to value: value,
) -> Vec4(value)
Returns a new vector with the y element replace with value
.
Examples
Vec4(12, -34, 420, 69) |> replace_y(777)
// -> Vec4(12, 777, 420, 69)
pub fn replace_z(
vector: Vec4(value),
to value: value,
) -> Vec4(value)
Returns a new vector with the z element replace with value
.
Examples
Vec4(12, -34, 420, 69) |> replace_z(777)
// -> Vec4(12, -34, 777, 69)
pub fn result(vector: Vec4(Result(a, e))) -> Result(Vec4(a), e)
Combines a vector of results into a single result. If all elements in the
vector are Ok
then returns an Ok
holding the vector of values. If any
element is Error
then returns the first error.
Examples
Vec4(Ok(12), Ok(-34), Ok(420), Ok(69)) |> result()
// -> Ok(Vec4(12, -34, 420, 69))
Vec4(Ok(12), Error("foo"), Ok(420), Error("bar")) |> result()
// -> Error("foo")
pub fn splat(value: value) -> Vec4(value)
Creates a vector with all elements set to a value.
Examples
splat(12)
// -> Vec4(12, 12, 12, 12)
pub fn swap_xw(vector: Vec4(value)) -> Vec4(value)
Returns a new vector with the x and w elements swaped.
Examples
Vec4(12, -34, 420, 69) |> swap_xw()
// -> Vec4(69, -34, 420, 12)
pub fn swap_xy(vector: Vec4(value)) -> Vec4(value)
Returns a new vector with the x and y elements swaped.
Examples
Vec4(12, -34, 420, 69) |> swap_xy()
// -> Vec4(-34, 12, 420, 69)
pub fn swap_xz(vector: Vec4(value)) -> Vec4(value)
Returns a new vector with the x and z elements swaped.
Examples
Vec4(12, -34, 420, 69) |> swap_xz()
// -> Vec4(420, -34, 12, 69)
pub fn swap_yw(vector: Vec4(value)) -> Vec4(value)
Returns a new vector with the y and w elements swaped.
Examples
Vec4(12, -34, 420, 69) |> swap_yw()
// -> Vec4(12, 69, 420, -34)
pub fn swap_yz(vector: Vec4(value)) -> Vec4(value)
Returns a new vector with the y and z elements swaped.
Examples
Vec4(12, -34, 420, 69) |> swap_yz()
// -> Vec4(12, 420, -34, 69)
pub fn swap_zw(vector: Vec4(value)) -> Vec4(value)
Returns a new vector with the z and w elements swaped.
Examples
Vec4(12, -34, 420, 69) |> swap_zw()
// -> Vec4(12, -34, 69, 420)
pub fn to_list(vector: Vec4(value)) -> List(value)
Converts the set into a list of the contained elements.
Examples
Vec4(12, -34, 420, 69) |> to_list()
// -> [12, -34, 420, 69]
pub fn w(vector: Vec4(value)) -> value
Returns the w element in a vector.
Examples
Vec4(12, -34, 420, 69) |> w()
// -> 69
pub fn x(vector: Vec4(value)) -> value
Returns the x element in a vector.
Examples
Vec4(12, -34, 420, 69) |> x()
// -> 12
pub fn y(vector: Vec4(value)) -> value
Returns the y element in a vector.
Examples
Vec4(12, -34, 420, 69) |> y()
// -> -34