untag

The type Or is an type union with no wrapping. Or2(Int, String, Float) is the same as Int | String | Float, not {Left, Int} | {Right, {Left, String} | {Right, Float}}

You can either treat it as a dynamic type that gives you some options on what it might be, or as a group of types that can be whittled down with decoders.

There are functions for (example)

* Encoding: tail_3rd t3            -> Or2(t1,t2,t3)
* Decoding: dehead   Or2(t1,t2,t3) -> t1?
* Moving:   flip     Or(a,b)       -> Or(b,a)

The repeated functions with numbers are used to move around the types, so you dont have to make an external casting function. For example, rev4_with_tail just returns the same value with a different, equivalent type. It asserts that Or(k, Or(l, Or(m, n))) is equivalent to Or(n, Or(m, Or(l, k))).

head_4th puts a type in the 4th position in a union.

   V------------------------->V
fn(k) -> Or(l, Or(m, Or(n, Or(k, o))))

Using tail_4th puts the type in the 4th position at the very end of the union, terminating the list of types.

   V-----------------------V
fn(k) -> Or(l, Or(m, Or(n, k)))

Types

pub type Or(t1, t2)
pub type Or2(t1, t2, t3) =
  Or(t1, Or(t2, t3))
pub type Or3(a, b, c, d) =
  Or(a, Or(b, Or(c, d)))
pub type Or4(a, b, c, d, e) =
  Or(a, Or(b, Or(c, Or(d, e))))
pub type Or5(a, b, c, d, e, f) =
  Or(a, Or(b, Or(c, Or(d, Or(e, f)))))
pub type Or6(a, b, c, d, e, f, g) =
  Or(a, Or(b, Or(c, Or(d, Or(e, Or(f, g))))))
pub type Or7(a, b, c, d, e, f, g, h) =
  Or(a, Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, h)))))))
pub type Or8(a, b, c, d, e, f, g, h, i) =
  Or(a, Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, Or(h, i))))))))
pub type Or9(a, b, c, d, e, f, g, h, i, j) =
  Or(a, Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, Or(h, Or(i, j)))))))))

Values

pub fn decode(
  this or: Or(a, b),
  with decoder: decode.Decoder(c),
) -> Result(c, List(decode.DecodeError))
pub fn dehead_unsafe(
  this union: Or(head, tail),
  with decoder: decode.Decoder(head),
) -> Result(head, #(tail, List(decode.DecodeError)))

Tries to decode the head. if it fails, it will return the value as the tail type.

This function is unsound when the generic type of the decoder does not directly match with the data it wants to decode. For example,

"string" 
// String -> Or(String, b)
|> head
|> dehead_unsafe(dec.int |> dec.map(int.to_string))

The value of the Or(String, b) is “string”, not any integer.

pub fn detail_unsafe(
  this union: Or(head, tail),
  with decoder: decode.Decoder(tail),
) -> Result(tail, #(head, List(decode.DecodeError)))

Unsafe. See [dehead_unsafe]

pub fn flip(or: Or(a, b)) -> Or(b, a)
pub fn flip_head(or: Or(Or(a, b), c)) -> Or(Or(b, a), c)
pub fn flip_tail(or: Or(t1, Or(t2, t3))) -> Or(t1, Or(t3, t2))
pub fn flipped(
  or: Or(a, b),
  f: fn(Or(b, a)) -> Or(c, d),
) -> Or(d, c)
pub fn give(or: Or(Or(t1, t2), t3)) -> Or(t2, Or(t1, t3))
pub fn give2(
  or: Or(Or(a, Or(b, c)), d),
) -> Or(c, Or(b, Or(a, d)))
pub fn give3(
  or: Or(Or(a, Or(b, Or(c, d))), e),
) -> Or(d, Or(c, Or(b, Or(a, e))))
pub fn give4(
  or: Or(Or(a, Or(b, Or(c, Or(d, e)))), f),
) -> Or(e, Or(d, Or(c, Or(b, Or(a, f)))))
pub fn give5(
  or: Or(Or(a, Or(b, Or(c, Or(d, Or(e, f))))), g),
) -> Or(f, Or(e, Or(d, Or(c, Or(b, Or(a, g))))))
pub fn give6(
  or: Or(Or(a, Or(b, Or(c, Or(d, Or(e, Or(f, g)))))), h),
) -> Or(g, Or(f, Or(e, Or(d, Or(c, Or(b, Or(a, h)))))))
pub fn give7(
  or: Or(Or(a, Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, h))))))), i),
) -> Or(h, Or(g, Or(f, Or(e, Or(d, Or(c, Or(b, Or(a, i))))))))
pub fn give8(
  or: Or(
    Or(a, Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, Or(h, i)))))))),
    j,
  ),
) -> Or(
  i,
  Or(h, Or(g, Or(f, Or(e, Or(d, Or(c, Or(b, Or(a, j)))))))),
)
pub const head: fn(h) -> Or(h, a)
pub fn head_10th(
  x: a,
) -> Or(
  b,
  Or(c, Or(d, Or(e, Or(f, Or(g, Or(h, Or(i, Or(j, Or(a, k))))))))),
)
pub const head_1st: fn(a) -> Or(a, b)

h_th = become nth head

pub fn head_2nd(x: a) -> Or(b, Or(a, c))
pub fn head_3th(x: a) -> Or(b, Or(c, Or(a, d)))
pub fn head_4th(x: a) -> Or(b, Or(c, Or(d, Or(a, e))))
pub fn head_5th(x: a) -> Or(b, Or(c, Or(d, Or(e, Or(a, f)))))
pub fn head_6th(
  x: a,
) -> Or(b, Or(c, Or(d, Or(e, Or(f, Or(a, g))))))
pub fn head_7th(
  x: a,
) -> Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, Or(a, h)))))))
pub fn head_8th(
  x: a,
) -> Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, Or(h, Or(a, i))))))))
pub fn head_9th(
  x: a,
) -> Or(
  b,
  Or(c, Or(d, Or(e, Or(f, Or(g, Or(h, Or(i, Or(a, j)))))))),
)
pub fn rev10_with_tail(
  or: Or(
    a,
    Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, Or(h, Or(i, j)))))))),
  ),
) -> Or(
  j,
  Or(i, Or(h, Or(g, Or(f, Or(e, Or(d, Or(c, Or(b, a)))))))),
)
pub fn rev3_with_tail(or: Or(a, Or(b, c))) -> Or(c, Or(b, a))
pub fn rev4_with_tail(
  or: Or(a, Or(b, Or(c, d))),
) -> Or(d, Or(c, Or(b, a)))
pub fn rev5_with_tail(
  or: Or(a, Or(b, Or(c, Or(d, e)))),
) -> Or(e, Or(d, Or(c, Or(b, a))))
pub fn rev6_with_tail(
  or: Or(a, Or(b, Or(c, Or(d, Or(e, f))))),
) -> Or(f, Or(e, Or(d, Or(c, Or(b, a)))))
pub fn rev7_with_tail(
  or: Or(a, Or(b, Or(c, Or(d, Or(e, Or(f, g)))))),
) -> Or(g, Or(f, Or(e, Or(d, Or(c, Or(b, a))))))
pub fn rev8_with_tail(
  or: Or(a, Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, h))))))),
) -> Or(h, Or(g, Or(f, Or(e, Or(d, Or(c, Or(b, a)))))))
pub fn rev9_with_tail(
  or: Or(a, Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, Or(h, i)))))))),
) -> Or(i, Or(h, Or(g, Or(f, Or(e, Or(d, Or(c, Or(b, a))))))))
pub const tail: fn(t) -> Or(a, t)
pub fn tail_10th(
  x: a,
) -> Or(
  b,
  Or(c, Or(d, Or(e, Or(f, Or(g, Or(h, Or(i, Or(j, a)))))))),
)
pub const tail_2nd: fn(a) -> Or(b, a)
pub fn tail_3rd(x: a) -> Or(b, Or(c, a))
pub fn tail_4th(x: a) -> Or(b, Or(c, Or(d, a)))
pub fn tail_5th(x: a) -> Or(b, Or(c, Or(d, Or(e, a))))
pub fn tail_6th(x: a) -> Or(b, Or(c, Or(d, Or(e, Or(f, a)))))
pub fn tail_7th(
  x: a,
) -> Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, a))))))
pub fn tail_8th(
  x: a,
) -> Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, Or(h, a)))))))
pub fn tail_9th(
  x: a,
) -> Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, Or(h, Or(i, a))))))))
pub fn take(or: Or(t1, Or(t2, t3))) -> Or(Or(t2, t1), t3)
pub fn take2(
  or: Or(a, Or(b, Or(c, d))),
) -> Or(Or(c, Or(b, a)), d)
pub fn take3(
  or: Or(a, Or(b, Or(c, Or(d, e)))),
) -> Or(Or(d, Or(c, Or(b, a))), e)
pub fn take4(
  or: Or(a, Or(b, Or(c, Or(d, Or(e, f))))),
) -> Or(Or(e, Or(d, Or(c, Or(b, a)))), f)
pub fn take5(
  or: Or(a, Or(b, Or(c, Or(d, Or(e, Or(f, g)))))),
) -> Or(Or(f, Or(e, Or(d, Or(c, Or(b, a))))), g)
pub fn take6(
  or: Or(a, Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, h))))))),
) -> Or(Or(g, Or(f, Or(e, Or(d, Or(c, Or(b, a)))))), h)
pub fn take7(
  or: Or(a, Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, Or(h, i)))))))),
) -> Or(Or(h, Or(g, Or(f, Or(e, Or(d, Or(c, Or(b, a))))))), i)
pub fn take8(
  or: Or(
    a,
    Or(b, Or(c, Or(d, Or(e, Or(f, Or(g, Or(h, Or(i, j)))))))),
  ),
) -> Or(
  Or(i, Or(h, Or(g, Or(f, Or(e, Or(d, Or(c, Or(b, a)))))))),
  j,
)
pub fn to_dynamic(or: Or(a, b)) -> dynamic.Dynamic
Search Document