-module(on). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -define(FILEPATH, "src/on.gleam"). -export([ok/2, error/2, error_ok/3, ok_error/3, true/2, false/2, false_true/3, lazy_false_true/3, true_false/3, lazy_true_false/3, some/2, none/2, none_some/3, lazy_none_some/3, some_none/3, nonempty/2, empty/2, empty_nonempty/3, lazy_empty_nonempty/3, nonempty_empty/3, empty_singleton_gt1/4, lazy_empty_singleton_gt1/4, empty_gt1_singleton/4, lazy_empty_gt1_singleton/4, singleton_gt1_empty/4, main/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -file("src/on.gleam", 29). ?DOC( " Given a Result(a, b) and a callback f(a) -> Result(c, b) applies\n" " the callback if the Result has type Ok else maps the Error variant\n" " of type Result(a, b) to the Error variant of type Result(c, b).\n" " \n" " Equivalent to result.try and to error_ok(_, fn(e) -> {Error(e)}, _).\n" "\n" " ### Example 1\n" "\n" " ```gleam\n" " use ok_payload <- on.ok(Ok(3))\n" " // -> execution proceeds, ok_payload == 3; the current scope must\n" " // return a Result(c, b) for some c, b\n" " ```\n" "\n" " ### Example 2\n" "\n" " ```gleam\n" " use ok_payload <- on.ok(Error(\"Joe\"))\n" " // -> execution discontinues, scope returns Error(\"Joe\")\n" " ```\n" ). -spec ok({ok, DTU} | {error, DTV}, fun((DTU) -> {ok, DTY} | {error, DTV})) -> {ok, DTY} | {error, DTV}. ok(Result, F2) -> case Result of {error, E} -> {error, E}; {ok, A} -> F2(A) end. -file("src/on.gleam", 60). ?DOC( " Given a Result(a, b) and a callback f(b) -> Result(a, c) applies\n" " the callback if the Result has type Error else maps the Ok variant\n" " of type Result(a, b) to the Ok variant of type Result(c, b).\n" "\n" " Equivalent to on.ok_error(_, fn(o) -> {Ok(o)}, _).\n" "\n" " ### Example 1\n" "\n" " ```gleam\n" " use error_payload <- on.error(Ok(3))\n" " // -> execution discontinues, scope returns Ok(3)\n" " ```\n" "\n" " ### Example 2\n" "\n" " ```gleam\n" " use error_payload <- on.error(Error(\"Joe\"))\n" " // -> execution proceeds, error_payload == \"Joe\";\n" " // the scope must return a Result(a, c)\n" " ```\n" ). -spec error({ok, DUD} | {error, DUE}, fun((DUE) -> {ok, DUD} | {error, DUH})) -> {ok, DUD} | {error, DUH}. error(Result, F2) -> case Result of {ok, A} -> {ok, A}; {error, E} -> F2(E) end. -file("src/on.gleam", 99). ?DOC( " Given a Result(a, b) and callbacks f(b) -> c, f(a) -> c, \n" " returns the evaluation of the relevant callback depending on\n" " the contents of the Result.\n" "\n" " ### Example 1\n" " \n" " ```gleam\n" " use ok_payload <- on.error_ok(\n" " Ok(3),\n" " on_error: fn(e) { \"hi \" <> e <> \"!\" },\n" " )\n" " // -> execution proceeds, ok_payload == 3; the scope must return\n" " // a String to match the return value of the on_error callback\n" " ```\n" " \n" " ### Example 2\n" " \n" " ```gleam\n" " use ok_payload <- on.error_ok(\n" " Error(\"Joe\"),\n" " on_error: fn(e) { \"hi \" <> e <> \"!\" },\n" " )\n" " // -> execution discontinues, scope returns \"hi Joe!\"\n" " ```\n" ). -spec error_ok({ok, DUM} | {error, DUN}, fun((DUN) -> DUQ), fun((DUM) -> DUQ)) -> DUQ. error_ok(Result, F1, F2) -> case Result of {error, B} -> F1(B); {ok, A} -> F2(A) end. -file("src/on.gleam", 136). ?DOC( " Given a Result(a, b) and callbacks f(a) -> c, f(b) -> c,\n" " returns the evaluation of the relevant callback depending on\n" " the contents of the Result.\n" "\n" " ### Example 1\n" "\n" " ```gleam\n" " use error_payload <- on.ok_error(\n" " Ok(3),\n" " on_ok: fn(x) { x + 1 },\n" " )\n" " // -> execution discontinues, scope returns 4\n" " ```\n" "\n" " ### Example 2\n" " \n" " ```gleam\n" " use error_payload <- on.ok_error(\n" " Error(\"Joe\"),\n" " on_ok: fn(x) { x + 1 },\n" " )\n" " // -> execution proceeds, error_payload == \"Joe\"; the scope\n" " // must return an Int to match the return value of the on_ok\n" " // callback\n" " ```\n" ). -spec ok_error({ok, DUR} | {error, DUS}, fun((DUR) -> DUV), fun((DUS) -> DUV)) -> DUV. ok_error(Result, F1, F2) -> case Result of {ok, A} -> F1(A); {error, B} -> F2(B) end. -file("src/on.gleam", 170). ?DOC( " Given a Bool returns False if the bool is False, else\n" " returns a lazily evaluated callback.\n" "\n" " Equivalent to on.false_true(_, False, _).\n" "\n" " ### Example 1\n" "\n" " ```gleam\n" " use <- on.true(True)\n" " // -> execution proceeds, scope must return a Bool\n" " ```\n" "\n" " ### Example 2\n" "\n" " ```gleam\n" " use <- on.true(False)\n" " // -> execution discontinues, scope returns False\n" " ```\n" ). -spec true(boolean(), fun(() -> boolean())) -> boolean(). true(Bool, F2) -> case Bool of false -> false; true -> F2() end. -file("src/on.gleam", 197). ?DOC( " Given a Bool returns True if the bool is True, else\n" " returns a lazily evaluated callback.\n" "\n" " ### Example 1\n" "\n" " ```gleam\n" " use <- on.false(True)\n" " // -> execution discontinues, scope returns True\n" " ```\n" "\n" " ### Example 2\n" "\n" " ```gleam\n" " use <- on.false(False)\n" " // -> execution proceeds, scope must return a Bool\n" " ```\n" ). -spec false(boolean(), fun(() -> boolean())) -> boolean(). false(Bool, F2) -> case Bool of true -> true; false -> F2() end. -file("src/on.gleam", 236). ?DOC( " Given a Bool, a value of type c and a callback f() -> c,\n" " returns the value of type c if the bool is False, else the\n" " evaluation of the callback.\n" "\n" " ### Example 1\n" "\n" " ```gleam\n" " use <- on.false_true(\n" " True,\n" " on_false: \"Joe\",\n" " )\n" " // -> execution proceeds, the scope must return a String to \n" " // match the return value of the on_false argument\n" " ```\n" "\n" " ### Example 2\n" "\n" " ```gleam\n" " use <- on.false_true(\n" " False,\n" " on_false: \"Joe\",\n" " )\n" " // -> execution discontinues, scope returns \"Joe\"\n" " ```\n" ). -spec false_true(boolean(), DUW, fun(() -> DUW)) -> DUW. false_true(Bool, C, F2) -> case Bool of false -> C; true -> F2() end. -file("src/on.gleam", 272). ?DOC( " Given a Bool and two callbacks f() -> c returns the\n" " evaluation of the first callback if the bool is False,\n" " else the second callback.\n" "\n" " ### Example 1\n" "\n" " ```gleam\n" " use <- on.lazy_false_true(\n" " True,\n" " on_false: fn() { \"Joe\" },\n" " )\n" " // -> execution proceeds, the scope must return a String \n" " // to match the return value of the on_false argument\n" " ```\n" "\n" " ### Example 2\n" "\n" " ```gleam\n" " use <- on.lazy_false_true(\n" " False,\n" " on_false: fn() { \"Joe\" },\n" " )\n" " // -> execution discontinues, scope returns \"Joe\"\n" " ```\n" ). -spec lazy_false_true(boolean(), fun(() -> DUX), fun(() -> DUX)) -> DUX. lazy_false_true(Bool, F1, F2) -> case Bool of false -> F1(); true -> F2() end. -file("src/on.gleam", 308). ?DOC( " Given a Bool, a value of type c and a callback f() -> c, \n" " returns the value of type c if the bool is True, else the\n" " evaluation of the callback.\n" "\n" " ### Example 1\n" "\n" " ```gleam\n" " use <- on.true_false(\n" " True,\n" " on_true: \"Joe\",\n" " )\n" " // -> execution discontinues, scope returns \"Joe\"\n" " ```\n" "\n" " ### Example 2\n" " \n" " ```gleam\n" " use <- on.true_false(\n" " False,\n" " on_true: \"Joe\",\n" " )\n" " // -> execution proceeds, the scope must return a String to \n" " // match the return value of the on_true argument\n" " ```\n" ). -spec true_false(boolean(), DUY, fun(() -> DUY)) -> DUY. true_false(Bool, C, F2) -> case Bool of true -> C; false -> F2() end. -file("src/on.gleam", 345). ?DOC( " Given a Bool and two callbacks f() -> c returns the\n" " evaluation of the first callback if the bool is True,\n" " else the second callback.\n" "\n" "\n" " ### Example 1\n" "\n" " ```gleam\n" " use <- on.lazy_true_false(\n" " True,\n" " on_true: fn() { \"Joe\" },\n" " )\n" " // -> execution discontinues, scope returns \"Joe\"\n" " ```\n" "\n" " ### Example 2\n" "\n" " ```gleam\n" " use <- on.lazy_true_false(\n" " False,\n" " on_true: fn() { \"Joe\" },\n" " )\n" " // -> execution proceeds, the scope must return a String to \n" " // match the return value of the on_false argument\n" " ```\n" ). -spec lazy_true_false(boolean(), fun(() -> DUZ), fun(() -> DUZ)) -> DUZ. lazy_true_false(Bool, F1, F2) -> case Bool of true -> F1(); false -> F2() end. -file("src/on.gleam", 383). ?DOC( " Given an Option(a) and a callback f(a) -> Option(c)\n" " applies the callback to the payload a if the option is Some(a),\n" " else returns None.\n" "\n" " Equivalent to:\n" " - on.none_some(_, None, _).\n" " - option.then\n" " \n" " ### Example 1\n" "\n" " ```gleam\n" " use payload <- on.some(Some(3))\n" " // -> execution proceeds, payload == 3; the scope must return\n" " // an Option(c)\n" " ```\n" "\n" " ### Example 2\n" " \n" " ```gleam\n" " use payload <- on.some(None)\n" " // -> execution discontinues, scope returns None\n" " ```\n" ). -spec some(gleam@option:option(DVA), fun((DVA) -> gleam@option:option(DVC))) -> gleam@option:option(DVC). some(Option, F2) -> case Option of none -> none; {some, A} -> F2(A) end. -file("src/on.gleam", 411). ?DOC( " Given an Option(a) and a callback f() -> Option(a), applies\n" " the callback if the option is None, else returns the option\n" " unchanged.\n" "\n" " ### Example 1\n" "\n" " ```gleam\n" " use <- on.none(Some(3))\n" " // -> execution discontinues, scope returns Some(3)\n" " ```\n" "\n" " ### Example 2\n" "\n" " ```gleam\n" " use <- on.none(None)\n" " // -> execution proceeds, the scope must return an Option(a)\n" " ```\n" ). -spec none(gleam@option:option(DVF), fun(() -> gleam@option:option(DVF))) -> gleam@option:option(DVF). none(Option, F2) -> case Option of {some, A} -> {some, A}; none -> F2() end. -file("src/on.gleam", 448). ?DOC( " Given an Option(a), a value of type c and a callback f(a) -> c, \n" " returns the value of type c if the option is None, else\n" " applies the callback to the option's payload.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " use payload <- on.none_some(\n" " Some(3),\n" " on_none: \"Bob\",\n" " )\n" " // -> execution proceeds, payload == 3; the scope must return a\n" " // String to match the return value of the on_none return value\n" " ```\n" "\n" " ```gleam\n" " use payload <- on.none_some(\n" " None,\n" " on_none: \"Bob\",\n" " )\n" " // -> execution discontinues, scope returns \"Bob\"\n" " ```\n" ). -spec none_some(gleam@option:option(DVJ), DVL, fun((DVJ) -> DVL)) -> DVL. none_some(Option, C, F2) -> case Option of none -> C; {some, A} -> F2(A) end. -file("src/on.gleam", 486). ?DOC( " Given an Option(a), a callback f() -> c and a callback\n" " f(a) -> c evaluates the first callback if the option is\n" " None, else evaluates the second callback on the option's\n" " payload.\n" "\n" " ### Example 1\n" "\n" " ```gleam\n" " use payload <- on.lazy_none_some(\n" " Some(3),\n" " on_none: fn() { \"Bob\" },\n" " )\n" " // -> execution proceeds, payload == 3; the scope must return\n" " // a String to match the return value of the on_none return\n" " // value\n" " ```\n" "\n" " ### Example 2\n" " \n" " ```gleam\n" " use payload <- on.lazy_none_some(\n" " None,\n" " on_none: fn() { \"Bob\" },\n" " )\n" " // -> execution discontinues, scope returns \"Bob\"\n" " ```\n" ). -spec lazy_none_some( gleam@option:option(DVM), fun(() -> DVO), fun((DVM) -> DVO) ) -> DVO. lazy_none_some(Option, F1, F2) -> case Option of none -> F1(); {some, A} -> F2(A) end. -file("src/on.gleam", 523). ?DOC( " Given an Option(a), a callback f(a) -> c and a callback\n" " f() -> c, evaluates the first callback on the option's\n" " payload, else evaluates the second callback if the option\n" " is None.\n" "\n" " ### Example 1\n" "\n" " ```gleam\n" " use <- on.some_none(\n" " Some(3),\n" " on_some: fn(x) { x + 1 },\n" " )\n" " // -> execution discontinues, scope returns 4\n" " ```\n" "\n" " ### Example 2\n" "\n" " ```gleam\n" " use <- on.some_none(\n" " None,\n" " on_some: fn(x) { x + 1 },\n" " )\n" " // -> execution proceeds, the scope must return an Int to match\n" " // the return value of the on_some return value\n" " ```\n" ). -spec some_none(gleam@option:option(DVP), fun((DVP) -> DVR), fun(() -> DVR)) -> DVR. some_none(Option, F1, F2) -> case Option of {some, A} -> F1(A); none -> F2() end. -file("src/on.gleam", 559). ?DOC( " Given a List(a) and a callback\n" " f(a, List(a)) -> List(c), returns the empty list if the\n" " list is empty, else evaluates the callback on (first, rest)\n" " where 'first' is the first element and 'tail' is the tail of \n" " the list.\n" " \n" " ### Example 1\n" " \n" " ```gleam\n" " use first, rest <- on.nonempty([1, 4, 7])\n" " // -> execution proceeds, first == 1, rest == [1, 7];\n" " // scope must return a List(c)\n" " ```\n" " \n" " ### Example 2\n" " \n" " ```gleam\n" " use first, rest <- on.nonempty([])\n" " // -> execution discontinues, scope returns []\n" " ```\n" ). -spec nonempty(list(DVS), fun((DVS, list(DVS)) -> list(DVV))) -> list(DVV). nonempty(List, F2) -> case List of [] -> []; [First | Rest] -> F2(First, Rest) end. -file("src/on.gleam", 587). ?DOC( " Given a List(a) and a callback f() -> List(a)\n" " returns the list if the is nonempty, else evaluates\n" " the callback.\n" "\n" " ### Example 1\n" " \n" " ```gleam\n" " use <- on.empty([1, 4, 7])\n" " // -> execution discontinues, scope returns [1, 4, 7]\n" " ```\n" " \n" " ### Example 2\n" " \n" " ```gleam\n" " use <- on.empty([])\n" " // -> execution proceeds, the scope must return a List(c)\n" " ```\n" ). -spec empty(list(DVY), fun(() -> list(DVY))) -> list(DVY). empty(List, F2) -> case List of [_ | _] -> List; [] -> F2() end. -file("src/on.gleam", 628). ?DOC( " Given a List(a), a value of type c, and callback\n" " f(a, List(a)) -> c, returns either the value of type c\n" " if the list is empty or else applies the callback to \n" " the head: a and tail: List(a) of the list.\n" " \n" " ### Example 1\n" " \n" " ```gleam\n" " use first, rest <- on.empty_nonempty(\n" " [1, 4, 7],\n" " on_empty: \"Joe\",\n" " )\n" " // -> execution proceeds, first == 1, rest == [4, 7];\n" " // scope must return a String to match the empty list\n" " // return value\n" " ```\n" " \n" " ### Example 2\n" " \n" " ```gleam\n" " use first, rest <- on.empty_nonempty(\n" " [],\n" " on_empty: \"Joe\",\n" " )\n" " // -> execution discontinues, scope returns \"Joe\"\n" " ```\n" ). -spec empty_nonempty(list(DWC), DWE, fun((DWC, list(DWC)) -> DWE)) -> DWE. empty_nonempty(List, C, F2) -> case List of [] -> C; [First | Rest] -> F2(First, Rest) end. -file("src/on.gleam", 666). ?DOC( " Given a List(a), a callback fn() -> c and a callback\n" " f(a, List(a)) -> c, evaluates the first callback if the\n" " list is empty else applies the second callback to the\n" " head: a and tail: List(a) of the list.\n" " \n" " ### Example 1\n" " \n" " ```gleam\n" " use first, rest <- on.lazy_empty_nonempty(\n" " [1, 4, 7],\n" " on_empty: fn() { \"Joe\" },\n" " )\n" " // -> execution proceeds, first == 1, rest == [4, 7];\n" " // scope must return a String to match the empty list\n" " // callback return value\n" " ```\n" " \n" " ### Example 2\n" " \n" " ```gleam\n" " use first, rest <- on.lazy_empty_nonempty(\n" " [],\n" " on_empty: fn() { \"Joe\" },\n" " )\n" " // -> execution discontinues, scope returns \"Joe\"\n" " ```\n" ). -spec lazy_empty_nonempty( list(DWG), fun(() -> DWI), fun((DWG, list(DWG)) -> DWI) ) -> DWI. lazy_empty_nonempty(List, F1, F2) -> case List of [] -> F1(); [First | Rest] -> F2(First, Rest) end. -file("src/on.gleam", 705). ?DOC( " Given a List(a), a callback f(a, List(a)) -> c, and\n" " a callback f() -> c, returns either the first callback\n" " evaluated on the first element and tail of the list if\n" " the list is nonempty, and otherwise evaluates the \n" " second callback, if the list is empty. \n" " \n" " ### Example 1\n" " \n" " ```gleam\n" " use <- on.nonempty_empty(\n" " [1, 4, 7],\n" " fn(first, _rest) { first + 1 },\n" " )\n" " // -> execution discontinues, scope returns 2\n" " ```\n" " \n" " ### Example 2\n" " \n" " ```gleam\n" " use <- on.nonempty_empty(\n" " [],\n" " fn(first, _rest) { first + 1 },\n" " )\n" " // -> execution proceeds, the scope must return an\n" " // integer to match the return value of the first\n" " // callback\n" " ```\n" ). -spec nonempty_empty(list(DWK), fun((DWK, list(DWK)) -> DWN), fun(() -> DWN)) -> DWN. nonempty_empty(List, F1, F2) -> case List of [First | Rest] -> F1(First, Rest); [] -> F2() end. -file("src/on.gleam", 750). ?DOC( " Given a List(a), a value of type c, and callbacks\n" " f(a) -> c, f(a, a, List(a)) -> c, returns:\n" "\n" " - the value of type c if the list is empty\n" " - the first callback evaluated with argument a1 if the list as the form [a1]\n" " - the second callback evaluated with arguments a1, a2, rest if the list has the form [a1, a2, ..rest]\n" " \n" " ### Example 1\n" " \n" " ```gleam\n" " use first, second, ..rest <- on.empty_singleton_gt1(\n" " [1, 4, 7],\n" " on_empty: 0,\n" " on_singleton: fn(first) { first },\n" " )\n" " // -> execution proceeds, first == 1, second == 4, rest == [7];\n" " // scope must return an Int to match the on_empty, on_singleton callbacks\n" " ```\n" " \n" " ### Example 2\n" " \n" " ```gleam\n" " use first, second, ..rest <- on.empty_singleton_gt1(\n" " [4],\n" " on_empty: 0,\n" " on_singleton: fn(first) { first },\n" " )\n" " // -> execution discontinues, scope resturns 4\n" " ```\n" ). -spec empty_singleton_gt1( list(DWO), DWQ, fun((DWO) -> DWQ), fun((DWO, DWO, list(DWO)) -> DWQ) ) -> DWQ. empty_singleton_gt1(List, C, F2, F3) -> case List of [] -> C; [First] -> F2(First); [First@1, Second | Rest] -> F3(First@1, Second, Rest) end. -file("src/on.gleam", 793). ?DOC( " Given a List(a), and callbacks f() -> c, f(a) -> c,\n" " f(a, a, List(a)) -> c, returns:\n" "\n" " - the evaluation of the first callback if the list is empty\n" " - the second callback evaluated with argument a1 if the list as the form [a1]\n" " - the third callback evaluated with arguments a1, a2, rest if the list has the form [a1, a2, ..rest]\n" " \n" " ### Example 1\n" " \n" " ```gleam\n" " use first, second, ..rest <- on.lazy_empty_singleton_gt1(\n" " [1, 4, 7],\n" " on_empty: 0,\n" " on_singleton: fn(first) { first },\n" " )\n" " // -> execution proceeds, first == 1, second == 4, rest == [7];\n" " // scope must return an Int to match the on_empty, on_singleton callbacks\n" " ```\n" " \n" " ### Example 2\n" " \n" " ```gleam\n" " use first, second, ..rest <- on.lazy_empty_singleton_gt1(\n" " [4],\n" " on_empty: 0,\n" " on_singleton: fn(first) { first },\n" " )\n" " // -> execution discontinues, scope resturns 4\n" " ```\n" ). -spec lazy_empty_singleton_gt1( list(DWS), fun(() -> DWU), fun((DWS) -> DWU), fun((DWS, DWS, list(DWS)) -> DWU) ) -> DWU. lazy_empty_singleton_gt1(List, F1, F2, F3) -> case List of [] -> F1(); [First] -> F2(First); [First@1, Second | Rest] -> F3(First@1, Second, Rest) end. -file("src/on.gleam", 837). ?DOC( " Given a List(a), a value of type c, and callbacks\n" " f(a, a, List(a)) -> c, f(a) -> c, returns:\n" "\n" " - the value of type c if the list is empty\n" " - the first callback evaluated with arguments a1, a2, rest if the list has the form [a1, a2, ..rest]\n" " - the second callback evaluated with argument a1 if the list as the form [a1]\n" " \n" " ### Example 1\n" " \n" " ```gleam\n" " use first <- on.empty_gt1_singleton(\n" " [1, 4, 7],\n" " on_empty: Error(\"empty list\"),\n" " on_gt1: Error(\"> 1 element in list\"),\n" " )\n" " // -> execution discontinues, scope returns Error(\"> 1 element in list\")\n" " ```\n" " \n" " ### Example 2\n" " \n" " ```gleam\n" " use first <- on.empty_gt1_singleton(\n" " [4],\n" " on_empty: Error(\"empty list\"),\n" " on_gt1: Error(\"> 1 element in list\"),\n" " )\n" " // -> execution proceeds, first == 4;\n" " // scope must return a Result(c, String) to match the on_empty \n" " // and on_gt1 callbacks\n" " ```\n" ). -spec empty_gt1_singleton( list(DWW), DWY, fun((DWW, DWW, list(DWW)) -> DWY), fun((DWW) -> DWY) ) -> DWY. empty_gt1_singleton(List, C, F2, F3) -> case List of [] -> C; [First, Second | Rest] -> F2(First, Second, Rest); [First@1] -> F3(First@1) end. -file("src/on.gleam", 881). ?DOC( " Given a List(a) and callbacks f() -> c,\n" " f(a, a, List(a)) -> c, f(a) -> c, returns:\n" "\n" " - the evaluation of the first callback if the list is empty\n" " - the second callback evaluated with arguments a1, a2, rest if the list has the form [a1, a2, ..rest]\n" " - the third callback evaluated with argument a1 if the list as the form [a1]\n" " \n" " ### Example 1\n" " \n" " ```gleam\n" " use first <- on.lazy_empty_gt1_singleton(\n" " [1, 4, 7],\n" " on_empty: Error(\"empty list\"),\n" " on_gt1: fn(_, _, _) {Error(\"> 1 element in list\")},\n" " )\n" " // -> execution discontinues, scope returns Error(\"> 1 element in list\")\n" " ```\n" " \n" " ### Example 2\n" " \n" " ```gleam\n" " use first <- on.lazy_empty_gt1_singleton(\n" " [4],\n" " on_empty: Error(\"empty list\"),\n" " on_gt1: Error(\"> 1 element in list\"),\n" " )\n" " // -> execution proceeds, first == 4;\n" " // scope must return a Result(c, String) to match the on_empty \n" " // and on_gt1 callbacks\n" " ```\n" ). -spec lazy_empty_gt1_singleton( list(DXA), fun(() -> DXC), fun((DXA, DXA, list(DXA)) -> DXC), fun((DXA) -> DXC) ) -> DXC. lazy_empty_gt1_singleton(List, F1, F2, F3) -> case List of [] -> F1(); [First, Second | Rest] -> F2(First, Second, Rest); [First@1] -> F3(First@1) end. -file("src/on.gleam", 925). ?DOC( " Given a List(a) and callbacks f(a) -> c,\n" " f(a, a, List(a)) -> c, f() -> c, returns:\n" "\n" " - the first callback evaluated with argument a1 if the list as the form [a1]\n" " - the second callback evaluated with arguments a1, a2, rest if the list has the form [a1, a2, ..rest]\n" " - the evaluation of the third callback if the list is empty\n" " \n" " ### Example 1\n" " \n" " ```gleam\n" " use <- on.singleton_gt1_empty(\n" " [1, 4, 7],\n" " on_singleton: fn(x) { x + 1 },\n" " on_gt1: fn(first, second, ..rest) { first + second},\n" " )\n" " // -> execution discontinues, scope returns 5 (= 1 + 4)\n" " ```\n" " \n" " ### Example 2\n" " \n" " ```gleam\n" " use first, second, ..rest <- on.singleton_gt1_empty(\n" " [],\n" " on_singleton: fn(x) { x + 1 },\n" " on_gt1: fn(first, second, ..rest) { first + second},\n" " )\n" " // -> execution proceeds, scope must return an Int to \n" " // match the on_singleton, on_gt1 callbacks\n" " \n" " ```\n" ). -spec singleton_gt1_empty( list(DXE), fun((DXE) -> DXG), fun((DXE, DXE, list(DXE)) -> DXG), fun(() -> DXG) ) -> DXG. singleton_gt1_empty(List, F1, F2, F3) -> case List of [First] -> F1(First); [First@1, Second | Rest] -> F2(First@1, Second, Rest); [] -> F3() end. -file("src/on.gleam", 938). -spec main() -> nil. main() -> gleam_stdlib:println(<<"Hello from on!"/utf8>>).