vec/vec3
Types
Values
pub fn decoder(
of inner: decode.Decoder(value),
) -> decode.Decoder(Vec3(value))
A decoder that decodes 3D vectors where all elements are decoded with a given decoder.
pub fn map(vector: Vec3(a), with fun: fn(a) -> b) -> Vec3(b)
Returns a new vector containing only the elements of the first vector after the function has been applied to each one.
Examples
Vec3(12, -34, 420) |> map(fn(x) { x * 2 })
// -> Vec3(24, -68, 840)
pub fn map2(
a: Vec3(a),
b: Vec3(b),
with fun: fn(a, b) -> c,
) -> Vec3(c)
Combines two vectors into a single vector using the given function.
Examples
Vec3(12, -34, 420) |> map2(Vec3(1, 2, 3), fn(x, y) { x * y })
// -> Vec3(12, -68, 1260)
pub fn map_x(
vector: Vec3(value),
with fun: fn(value) -> value,
) -> Vec3(value)
Returns a new vector with the x element having had with
applied to it.
Examples
Vec3(12, -34, 420) |> map_x(fn(n) { n * 2 })
// -> Vec3(24, -34, 420)
pub fn map_y(
vector: Vec3(value),
with fun: fn(value) -> value,
) -> Vec3(value)
Returns a new vector with the y element having had with
applied to it.
Examples
Vec3(12, -34, 420) |> map_y(fn(n) { n * 2 })
// -> Vec3(12, -68, 420)
pub fn map_z(
vector: Vec3(value),
with fun: fn(value) -> value,
) -> Vec3(value)
Returns a new vector with the z element having had with
applied to it.
Examples
Vec3(12, -34, 420) |> map_z(fn(n) { n * 2 })
// -> Vec3(12, -34, 840)
pub fn replace_x(
vector: Vec3(value),
to value: value,
) -> Vec3(value)
Returns a new vector with the x element replace with value
.
Examples
Vec3(12, -34, 420) |> replace_x(777)
// -> Vec3(777, -34, 420)
pub fn replace_y(
vector: Vec3(value),
to value: value,
) -> Vec3(value)
Returns a new vector with the y element replace with value
.
Examples
Vec3(12, -34, 420) |> replace_y(777)
// -> Vec3(12, 777, 420)
pub fn replace_z(
vector: Vec3(value),
to value: value,
) -> Vec3(value)
Returns a new vector with the z element replace with value
.
Examples
Vec3(12, -34, 420) |> replace_z(777)
// -> Vec3(12, -34, 777)
pub fn result(vector: Vec3(Result(a, e))) -> Result(Vec3(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
Vec3(Ok(12), Ok(-34), Ok(420)) |> result()
// -> Ok(Vec3(12, -34, 420))
Vec3(Ok(12), Error("foo"), Error("bar")) |> result()
// -> Error("foo")
pub fn splat(value: value) -> Vec3(value)
Creates a vector with all elements set to a value.
Examples
splat(12)
// -> Vec3(12, 12, 12)
pub fn swap_xy(vector: Vec3(value)) -> Vec3(value)
Returns a new vector with the x and y elements swaped.
Examples
Vec3(12, -34, 420) |> swap_xy()
// -> Vec3(-34, 12, 420)
pub fn swap_xz(vector: Vec3(value)) -> Vec3(value)
Returns a new vector with the x and z elements swaped.
Examples
Vec3(12, -34, 420) |> swap_xz()
// -> Vec3(420, -34, 12)
pub fn swap_yz(vector: Vec3(value)) -> Vec3(value)
Returns a new vector with the y and z elements swaped.
Examples
Vec3(12, -34, 420) |> swap_yz()
// -> Vec3(12, 420, -34)
pub fn to_list(vector: Vec3(value)) -> List(value)
Converts the set into a list of the contained elements.
Examples
Vec3(12, -34, 420) |> to_list()
// -> [12, -34, 420]
pub fn x(vector: Vec3(value)) -> value
Returns the x element in a vector.
Examples
Vec3(12, -34, 420) |> x()
// -> 12
pub fn y(vector: Vec3(value)) -> value
Returns the y element in a vector.
Examples
Vec3(12, -34, 420) |> y()
// -> -34