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