-module(untag). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/untag.gleam"). -export([id/1, to_dynamic/1, decode/2, dehead_unsafe/2, detail_unsafe/2, flip/1, flip_tail/1, flipped/2, flip_head/1, give/1, give2/1, give3/1, give4/1, give5/1, give6/1, give7/1, give8/1, take/1, take2/1, take3/1, take4/1, take5/1, take6/1, take7/1, take8/1, rev3_with_tail/1, rev4_with_tail/1, rev5_with_tail/1, rev6_with_tail/1, rev7_with_tail/1, rev8_with_tail/1, rev9_with_tail/1, rev10_with_tail/1, tail_3rd/1, tail_4th/1, tail_5th/1, tail_6th/1, tail_7th/1, tail_8th/1, tail_9th/1, tail_10th/1, head_2nd/1, head_3th/1, head_4th/1, head_5th/1, head_6th/1, head_7th/1, head_8th/1, head_9th/1, head_10th/1]). -export_type(['or'/2]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " The type `Or` is an type union with no wrapping.\n" " `Or2(Int, String, Float)` is the same as `Int | String | Float`, \n" " not `{Left, Int} | {Right, {Left, String} | {Right, Float}}`\n" " \n" " You can either treat it as a dynamic type that gives you some \n" " options on what it might be, or as a group of types that can \n" " be whittled down with decoders. \n" " \n" " There are functions for (example)\n" " ```\n" " * Encoding: tail_3rd t3 -> Or2(t1,t2,t3)\n" " * Decoding: dehead Or2(t1,t2,t3) -> t1?\n" " * Moving: flip Or(a,b) -> Or(b,a)\n" " ```\n" " \n" " The repeated functions with numbers are used to move around \n" " the types, so you dont have to make an external casting function.\n" " For example, `rev4_with_tail` just returns the same value with \n" " a different, equivalent type. It asserts that \n" " `Or(k, Or(l, Or(m, n)))` is equivalent to `Or(n, Or(m, Or(l, k)))`.\n" " \n" " head_4th puts a type in the 4th position in a union.\n" " ```\n" " V------------------------->V\n" " fn(k) -> Or(l, Or(m, Or(n, Or(k, o))))\n" " ```\n" " \n" " Using tail_4th puts the type in the 4th position at the \n" " very end of the union, terminating the list of types.\n" " ```\n" " V-----------------------V\n" " fn(k) -> Or(l, Or(m, Or(n, k)))\n" " ```\n" ). -type 'or'(EDZ, EEA) :: any() | {gleam_phantom, EDZ, EEA}. -file("src/untag.gleam", 42). ?DOC(false). -spec id(any()) -> any(). id(X) -> untag_ffi:id(X). -file("src/untag.gleam", 44). -spec to_dynamic('or'(any(), any())) -> gleam@dynamic:dynamic_(). to_dynamic(Or) -> untag_ffi:id(Or). -file("src/untag.gleam", 48). -spec decode('or'(any(), any()), gleam@dynamic@decode:decoder(EIQ)) -> {ok, EIQ} | {error, list(gleam@dynamic@decode:decode_error())}. decode(Or, Decoder) -> _pipe = Or, _pipe@1 = to_dynamic(_pipe), gleam@dynamic@decode:run(_pipe@1, Decoder). -file("src/untag.gleam", 65). ?DOC( " Tries to decode the head. if it fails, it will return the value as the tail type.\n" " \n" " This function is unsound when the generic type of the decoder \n" " does not directly match with the data it wants to decode.\n" " For example,\n" " ```\n" " \"string\" \n" " // String -> Or(String, b)\n" " |> head\n" " |> dehead_unsafe(dec.int |> dec.map(int.to_string))\n" " ```\n" " The value of the Or(String, b) is \"string\", not any integer.\n" ). -spec dehead_unsafe('or'(EIT, EIU), gleam@dynamic@decode:decoder(EIT)) -> {ok, EIT} | {error, {EIU, list(gleam@dynamic@decode:decode_error())}}. dehead_unsafe(Union, Decoder) -> _pipe = Union, _pipe@1 = to_dynamic(_pipe), _pipe@2 = gleam@dynamic@decode:run(_pipe@1, Decoder), gleam@result:map_error( _pipe@2, fun(Errs) -> {untag_ffi:id(Union), Errs} end ). -file("src/untag.gleam", 76). ?DOC(" Unsafe. See [dehead_unsafe]\n"). -spec detail_unsafe('or'(EJB, EJC), gleam@dynamic@decode:decoder(EJC)) -> {ok, EJC} | {error, {EJB, list(gleam@dynamic@decode:decode_error())}}. detail_unsafe(Union, Decoder) -> _pipe = Union, _pipe@1 = to_dynamic(_pipe), _pipe@2 = gleam@dynamic@decode:run(_pipe@1, Decoder), gleam@result:map_error( _pipe@2, fun(Errs) -> {untag_ffi:id(Union), Errs} end ). -file("src/untag.gleam", 197). -spec flip('or'(EKX, EKY)) -> 'or'(EKY, EKX). flip(Or) -> untag_ffi:id(Or). -file("src/untag.gleam", 201). -spec flip_tail('or'(ELD, 'or'(ELE, ELF))) -> 'or'(ELD, 'or'(ELF, ELE)). flip_tail(Or) -> untag_ffi:id(Or). -file("src/untag.gleam", 209). -spec flipped('or'(EPM, EPN), fun(('or'(EPN, EPM)) -> 'or'(EPQ, EPR))) -> 'or'(EPR, EPQ). flipped(Or, F) -> _pipe = Or, _pipe@1 = flip(_pipe), _pipe@2 = F(_pipe@1), flip(_pipe@2). -file("src/untag.gleam", 205). -spec flip_head('or'('or'(EPY, EPZ), EPX)) -> 'or'('or'(EPZ, EPY), EPX). flip_head(Or) -> _pipe = Or, flipped(_pipe, fun flip_tail/1). -file("src/untag.gleam", 213). -spec give('or'('or'(ELT, ELU), ELX)) -> 'or'(ELU, 'or'(ELT, ELX)). give(Or) -> untag_ffi:id(Or). -file("src/untag.gleam", 217). -spec give2('or'('or'(EQC, 'or'(EQG, EQH)), EQE)) -> 'or'(EQH, 'or'(EQG, 'or'(EQC, EQE))). give2(Or) -> _pipe = Or, _pipe@1 = give(_pipe), give(_pipe@1). -file("src/untag.gleam", 221). -spec give3('or'('or'(EQK, 'or'(EQO, 'or'(EQP, EQQ))), EQM)) -> 'or'(EQQ, 'or'(EQP, 'or'(EQO, 'or'(EQK, EQM)))). give3(Or) -> _pipe = Or, _pipe@1 = give(_pipe), give2(_pipe@1). -file("src/untag.gleam", 225). -spec give4('or'('or'(EQT, 'or'(EQX, 'or'(EQY, 'or'(EQZ, ERA)))), EQV)) -> 'or'(ERA, 'or'(EQZ, 'or'(EQY, 'or'(EQX, 'or'(EQT, EQV))))). give4(Or) -> _pipe = Or, _pipe@1 = give(_pipe), give3(_pipe@1). -file("src/untag.gleam", 229). -spec give5( 'or'('or'(ERD, 'or'(ERH, 'or'(ERI, 'or'(ERJ, 'or'(ERK, ERL))))), ERF) ) -> 'or'(ERL, 'or'(ERK, 'or'(ERJ, 'or'(ERI, 'or'(ERH, 'or'(ERD, ERF)))))). give5(Or) -> _pipe = Or, _pipe@1 = give(_pipe), give4(_pipe@1). -file("src/untag.gleam", 233). -spec give6( 'or'('or'(ERO, 'or'(ERS, 'or'(ERT, 'or'(ERU, 'or'(ERV, 'or'(ERW, ERX)))))), ERQ) ) -> 'or'(ERX, 'or'(ERW, 'or'(ERV, 'or'(ERU, 'or'(ERT, 'or'(ERS, 'or'(ERO, ERQ))))))). give6(Or) -> _pipe = Or, _pipe@1 = give(_pipe), give5(_pipe@1). -file("src/untag.gleam", 237). -spec give7( 'or'('or'(ESA, 'or'(ESE, 'or'(ESF, 'or'(ESG, 'or'(ESH, 'or'(ESI, 'or'(ESJ, ESK))))))), ESC) ) -> 'or'(ESK, 'or'(ESJ, 'or'(ESI, 'or'(ESH, 'or'(ESG, 'or'(ESF, 'or'(ESE, 'or'(ESA, ESC)))))))). give7(Or) -> _pipe = Or, _pipe@1 = give(_pipe), give6(_pipe@1). -file("src/untag.gleam", 241). -spec give8( 'or'('or'(ESN, 'or'(ESR, 'or'(ESS, 'or'(EST, 'or'(ESU, 'or'(ESV, 'or'(ESW, 'or'(ESX, ESY)))))))), ESP) ) -> 'or'(ESY, 'or'(ESX, 'or'(ESW, 'or'(ESV, 'or'(ESU, 'or'(EST, 'or'(ESS, 'or'(ESR, 'or'(ESN, ESP))))))))). give8(Or) -> _pipe = Or, _pipe@1 = give(_pipe), give7(_pipe@1). -file("src/untag.gleam", 245). -spec take('or'(EMS, 'or'(EMT, EMU))) -> 'or'('or'(EMT, EMS), EMU). take(Or) -> _pipe = Or, flipped(_pipe, fun give/1). -file("src/untag.gleam", 249). -spec take2('or'(ETI, 'or'(ETJ, 'or'(ETN, ETO)))) -> 'or'('or'(ETN, 'or'(ETJ, ETI)), ETO). take2(Or) -> _pipe = Or, _pipe@1 = take(_pipe), take(_pipe@1). -file("src/untag.gleam", 253). -spec take3('or'(ETQ, 'or'(ETR, 'or'(ETV, 'or'(ETW, ETX))))) -> 'or'('or'(ETW, 'or'(ETV, 'or'(ETR, ETQ))), ETX). take3(Or) -> _pipe = Or, _pipe@1 = take(_pipe), take2(_pipe@1). -file("src/untag.gleam", 257). -spec take4('or'(ETZ, 'or'(EUA, 'or'(EUE, 'or'(EUF, 'or'(EUG, EUH)))))) -> 'or'('or'(EUG, 'or'(EUF, 'or'(EUE, 'or'(EUA, ETZ)))), EUH). take4(Or) -> _pipe = Or, _pipe@1 = take(_pipe), take3(_pipe@1). -file("src/untag.gleam", 261). -spec take5( 'or'(EUJ, 'or'(EUK, 'or'(EUO, 'or'(EUP, 'or'(EUQ, 'or'(EUR, EUS)))))) ) -> 'or'('or'(EUR, 'or'(EUQ, 'or'(EUP, 'or'(EUO, 'or'(EUK, EUJ))))), EUS). take5(Or) -> _pipe = Or, _pipe@1 = take(_pipe), take4(_pipe@1). -file("src/untag.gleam", 265). -spec take6( 'or'(EUU, 'or'(EUV, 'or'(EUZ, 'or'(EVA, 'or'(EVB, 'or'(EVC, 'or'(EVD, EVE))))))) ) -> 'or'('or'(EVD, 'or'(EVC, 'or'(EVB, 'or'(EVA, 'or'(EUZ, 'or'(EUV, EUU)))))), EVE). take6(Or) -> _pipe = Or, _pipe@1 = take(_pipe), take5(_pipe@1). -file("src/untag.gleam", 269). -spec take7( 'or'(EVG, 'or'(EVH, 'or'(EVL, 'or'(EVM, 'or'(EVN, 'or'(EVO, 'or'(EVP, 'or'(EVQ, EVR)))))))) ) -> 'or'('or'(EVQ, 'or'(EVP, 'or'(EVO, 'or'(EVN, 'or'(EVM, 'or'(EVL, 'or'(EVH, EVG))))))), EVR). take7(Or) -> _pipe = Or, _pipe@1 = take(_pipe), take6(_pipe@1). -file("src/untag.gleam", 273). -spec take8( 'or'(EVT, 'or'(EVU, 'or'(EVY, 'or'(EVZ, 'or'(EWA, 'or'(EWB, 'or'(EWC, 'or'(EWD, 'or'(EWE, EWF))))))))) ) -> 'or'('or'(EWE, 'or'(EWD, 'or'(EWC, 'or'(EWB, 'or'(EWA, 'or'(EVZ, 'or'(EVY, 'or'(EVU, EVT)))))))), EWF). take8(Or) -> _pipe = Or, _pipe@1 = take(_pipe), take7(_pipe@1). -file("src/untag.gleam", 277). -spec rev3_with_tail('or'(EWH, 'or'(EWK, EWL))) -> 'or'(EWL, 'or'(EWK, EWH)). rev3_with_tail(Or) -> _pipe = Or, _pipe@1 = flip(_pipe), give(_pipe@1). -file("src/untag.gleam", 281). -spec rev4_with_tail('or'(EWO, 'or'(EWP, 'or'(EWS, EWT)))) -> 'or'(EWT, 'or'(EWS, 'or'(EWP, EWO))). rev4_with_tail(Or) -> _pipe = Or, _pipe@1 = rev3_with_tail(_pipe), give(_pipe@1). -file("src/untag.gleam", 285). -spec rev5_with_tail('or'(EWW, 'or'(EWX, 'or'(EWY, 'or'(EXB, EXC))))) -> 'or'(EXC, 'or'(EXB, 'or'(EWY, 'or'(EWX, EWW)))). rev5_with_tail(Or) -> _pipe = Or, _pipe@1 = rev4_with_tail(_pipe), give(_pipe@1). -file("src/untag.gleam", 289). -spec rev6_with_tail('or'(EXF, 'or'(EXG, 'or'(EXH, 'or'(EXI, 'or'(EXL, EXM)))))) -> 'or'(EXM, 'or'(EXL, 'or'(EXI, 'or'(EXH, 'or'(EXG, EXF))))). rev6_with_tail(Or) -> _pipe = Or, _pipe@1 = rev5_with_tail(_pipe), give(_pipe@1). -file("src/untag.gleam", 293). -spec rev7_with_tail( 'or'(EXP, 'or'(EXQ, 'or'(EXR, 'or'(EXS, 'or'(EXT, 'or'(EXW, EXX)))))) ) -> 'or'(EXX, 'or'(EXW, 'or'(EXT, 'or'(EXS, 'or'(EXR, 'or'(EXQ, EXP)))))). rev7_with_tail(Or) -> _pipe = Or, _pipe@1 = rev6_with_tail(_pipe), give(_pipe@1). -file("src/untag.gleam", 297). -spec rev8_with_tail( 'or'(EYA, 'or'(EYB, 'or'(EYC, 'or'(EYD, 'or'(EYE, 'or'(EYF, 'or'(EYI, EYJ))))))) ) -> 'or'(EYJ, 'or'(EYI, 'or'(EYF, 'or'(EYE, 'or'(EYD, 'or'(EYC, 'or'(EYB, EYA))))))). rev8_with_tail(Or) -> _pipe = Or, _pipe@1 = rev7_with_tail(_pipe), give(_pipe@1). -file("src/untag.gleam", 301). -spec rev9_with_tail( 'or'(EYM, 'or'(EYN, 'or'(EYO, 'or'(EYP, 'or'(EYQ, 'or'(EYR, 'or'(EYS, 'or'(EYV, EYW)))))))) ) -> 'or'(EYW, 'or'(EYV, 'or'(EYS, 'or'(EYR, 'or'(EYQ, 'or'(EYP, 'or'(EYO, 'or'(EYN, EYM)))))))). rev9_with_tail(Or) -> _pipe = Or, _pipe@1 = rev8_with_tail(_pipe), give(_pipe@1). -file("src/untag.gleam", 305). -spec rev10_with_tail( 'or'(EYZ, 'or'(EZA, 'or'(EZB, 'or'(EZC, 'or'(EZD, 'or'(EZE, 'or'(EZF, 'or'(EZG, 'or'(EZJ, EZK))))))))) ) -> 'or'(EZK, 'or'(EZJ, 'or'(EZG, 'or'(EZF, 'or'(EZE, 'or'(EZD, 'or'(EZC, 'or'(EZB, 'or'(EZA, EYZ))))))))). rev10_with_tail(Or) -> _pipe = Or, _pipe@1 = rev9_with_tail(_pipe), give(_pipe@1). -file("src/untag.gleam", 154). -spec head_in(fun(('or'(EKD, any())) -> EZU), EKD) -> EZU. head_in(Tn, X) -> Tn(untag_ffi:id(X)). -file("src/untag.gleam", 116). -spec tail_in(fun(('or'(any(), EJK)) -> FAE), EJK) -> FAE. tail_in(Tn, X) -> Tn(untag_ffi:id(X)). -file("src/untag.gleam", 122). -spec tail_3rd(EJM) -> 'or'(any(), 'or'(any(), EJM)). tail_3rd(X) -> _pipe = fun untag_ffi:id/1, tail_in(_pipe, X). -file("src/untag.gleam", 126). -spec tail_4th(EJO) -> 'or'(any(), 'or'(any(), 'or'(any(), EJO))). tail_4th(X) -> _pipe = fun tail_3rd/1, tail_in(_pipe, X). -file("src/untag.gleam", 130). -spec tail_5th(EJQ) -> 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), EJQ)))). tail_5th(X) -> _pipe = fun tail_4th/1, tail_in(_pipe, X). -file("src/untag.gleam", 134). -spec tail_6th(EJS) -> 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), EJS))))). tail_6th(X) -> _pipe = fun tail_5th/1, tail_in(_pipe, X). -file("src/untag.gleam", 138). -spec tail_7th(EJU) -> 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), EJU)))))). tail_7th(X) -> _pipe = fun tail_6th/1, tail_in(_pipe, X). -file("src/untag.gleam", 142). -spec tail_8th(EJW) -> 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), EJW))))))). tail_8th(X) -> _pipe = fun tail_7th/1, tail_in(_pipe, X). -file("src/untag.gleam", 146). -spec tail_9th(EJY) -> 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), EJY)))))))). tail_9th(X) -> _pipe = fun tail_8th/1, tail_in(_pipe, X). -file("src/untag.gleam", 150). -spec tail_10th(EKA) -> 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), EKA))))))))). tail_10th(X) -> _pipe = fun tail_9th/1, tail_in(_pipe, X). -file("src/untag.gleam", 161). -spec head_2nd(EKF) -> 'or'(any(), 'or'(EKF, any())). head_2nd(X) -> _pipe = fun untag_ffi:id/1, head_in(_pipe, X). -file("src/untag.gleam", 165). -spec head_3th(EKH) -> 'or'(any(), 'or'(any(), 'or'(EKH, any()))). head_3th(X) -> _pipe = fun tail_3rd/1, head_in(_pipe, X). -file("src/untag.gleam", 169). -spec head_4th(EKJ) -> 'or'(any(), 'or'(any(), 'or'(any(), 'or'(EKJ, any())))). head_4th(X) -> _pipe = fun tail_4th/1, head_in(_pipe, X). -file("src/untag.gleam", 173). -spec head_5th(EKL) -> 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(EKL, any()))))). head_5th(X) -> _pipe = fun tail_5th/1, head_in(_pipe, X). -file("src/untag.gleam", 177). -spec head_6th(EKN) -> 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(EKN, any())))))). head_6th(X) -> _pipe = fun tail_6th/1, head_in(_pipe, X). -file("src/untag.gleam", 181). -spec head_7th(EKP) -> 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(EKP, any()))))))). head_7th(X) -> _pipe = fun tail_7th/1, head_in(_pipe, X). -file("src/untag.gleam", 185). -spec head_8th(EKR) -> 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(EKR, any())))))))). head_8th(X) -> _pipe = fun tail_8th/1, head_in(_pipe, X). -file("src/untag.gleam", 189). -spec head_9th(EKT) -> 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(EKT, any()))))))))). head_9th(X) -> _pipe = fun tail_9th/1, head_in(_pipe, X). -file("src/untag.gleam", 193). -spec head_10th(EKV) -> 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(any(), 'or'(EKV, any())))))))))). head_10th(X) -> _pipe = fun tail_10th/1, head_in(_pipe, X).