hydra-kernel-0.18.1: hydra-kernel-json/hydra/core/lib/lists.json
{
"name": "hydra.core.lib.lists",
"metadata": {
"description": "Primitives in the hydra.core.lib.lists module.",
"comments": [
"Lists form a monad: singleton is its unit and bind its bind, with map, apply, and compose completing the functor, applicative, and Kleisli structure.",
"The traversal family mapList, mapOptional, and mapSet traverses a container in the list monad, and foldList is the monadic fold.",
"The bare foldl and foldr are the plain, non-monadic folds."],
"seeAlso": [],
"provisions": []},
"dependencies": [
{"module": "hydra.core.lib.logic"},
{"module": "hydra.core.lib.optionals"},
{"module": "hydra.core.lib.pairs"},
{"module": "hydra.core.lib.sets"},
{"module": "hydra.core.model"},
{"module": "hydra.core.packaging"},
{"module": "hydra.core.typing"}],
"definitions": [
{
"primitive": {
"name": "hydra.core.lib.lists.apply",
"metadata": {
"description": "Apply a list of functions to a list of values (applicative style).",
"comments": [
"apply(fs, xs) returns the list of all f x for f in fs and x in xs, in order: for each f in fs (outer loop), for each x in xs (inner loop).",
"Equivalent to the applicative list instance.",
"Total. Corresponds to Haskell's (<*>) :: [a -> b] -> [a] -> [b]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.apply.sequentialComposition",
"kind": "requirement",
"statement": "apply threads the input list through every function in the function list in order, concatenating each function's output."},
{
"name": "hydra.core.lib.lists.apply.identityCases",
"kind": "requirement",
"statement": "apply with an empty function list, or an empty input list, or a single function/input, degrades correctly: zero functions or zero inputs yields an empty result; one of either acts as a direct map."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}],
"parameters": [
{
"name": "fs",
"description": "the list of functions to apply",
"type": {"list": {"function": {"domain": {"variable": "x"}, "codomain": {"variable": "y"}}}},
"isLazy": false},
{
"name": "xs",
"description": "the list of values to apply them to",
"type": {"list": {"variable": "x"}},
"isLazy": false}],
"result": {"type": {"list": {"variable": "y"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.at",
"metadata": {
"description": "Return the element at the given index, or Nothing if out of bounds.",
"comments": [
"at(i, xs) returns Just(xs[i]) if 0 <= i < length(xs), or Nothing otherwise.",
"Total. Wraps the Haskell (!!) operator, which is partial, in maybe to make out-of-bounds total.",
"Renamed from hydra.lib.lists.maybeAt."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": [
{
"name": "hydra.core.lib.lists.at.returnsElementAtIndex",
"kind": "requirement",
"statement": "at returns the element at the given zero-based index, wrapped, for any valid index including the first and last."},
{
"name": "hydra.core.lib.lists.at.noneWhenOutOfRange",
"kind": "requirement",
"statement": "at returns none when the index is negative, at or beyond the list's length, or when the list is empty."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{"name": "i", "description": "the index to look up", "type": {"literal": {"integer": "int32"}}, "isLazy": false},
{"name": "xs", "description": "the list to index into", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"optional": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.bind",
"metadata": {
"description": "Apply a function that returns lists to each element and flatten the results.",
"comments": [
"bind(xs, f) applies f to each element of xs and concatenates the resulting lists in order. Equivalent to concatMap.",
"Total. Corresponds to Haskell's (>>=) :: [a] -> (a -> [b]) -> [b]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.bind.flatMapsOverElements",
"kind": "requirement",
"statement": "bind applies a list-producing function to each element and concatenates the results, in order, including when the function returns duplicate or negative values."},
{
"name": "hydra.core.lib.lists.bind.emptyInput",
"kind": "requirement",
"statement": "bind over an empty list is the empty list, regardless of the function supplied."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}],
"parameters": [
{"name": "xs", "description": "the list to bind over", "type": {"list": {"variable": "x"}}, "isLazy": false},
{
"name": "f",
"description": "the function returning a list for each element",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"list": {"variable": "y"}}}},
"isLazy": false}],
"result": {"type": {"list": {"variable": "y"}}}},
"isPure": true,
"isTotal": true,
"defaultImplementation": {
"lambda": {
"parameter": "xs",
"body": {
"lambda": {
"parameter": "f",
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.foldr"},
"argument": {
"lambda": {
"parameter": "x",
"body": {
"lambda": {
"parameter": "acc",
"body": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.concat2"},
"argument": {"application": {"function": {"variable": "f"}, "argument": {"variable": "x"}}}}},
"argument": {"variable": "acc"}}}}}}}}},
"argument": {"list": []}}},
"argument": {"variable": "xs"}}}}}}}}},
{
"primitive": {
"name": "hydra.core.lib.lists.compose",
"metadata": {
"description": "Compose two functions that return lists (Kleisli composition in the list monad).",
"comments": [
"compose(f, g, x) is bind(f(x), g); this defining equation is the specification. The results of applying g to each element of f(x) are concatenated in order.",
"Total. Corresponds to Kleisli composition (>=>) in the list monad."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": []},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}, {"name": "z", "constraints": []}],
"parameters": [
{
"name": "f",
"description": "the first list-returning function",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"list": {"variable": "y"}}}},
"isLazy": false},
{
"name": "g",
"description": "the second list-returning function",
"type": {"function": {"domain": {"variable": "y"}, "codomain": {"list": {"variable": "z"}}}},
"isLazy": false},
{"name": "x", "description": "the input value", "type": {"variable": "x"}, "isLazy": false}],
"result": {"type": {"list": {"variable": "z"}}}},
"isPure": true,
"isTotal": true,
"defaultImplementation": {
"lambda": {
"parameter": "f",
"body": {
"lambda": {
"parameter": "g",
"body": {
"lambda": {
"parameter": "x",
"body": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.bind"},
"argument": {"application": {"function": {"variable": "f"}, "argument": {"variable": "x"}}}}},
"argument": {"variable": "g"}}}}}}}}}}},
{
"primitive": {
"name": "hydra.core.lib.lists.concat",
"metadata": {
"description": "Concatenate a list of lists.",
"comments": [
"concat(xss) returns the list obtained by appending all the lists in xss in order.",
"Total. Corresponds to Haskell's concat :: [[a]] -> [a]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.concat.flattensPreservingOrder",
"kind": "requirement",
"statement": "concat flattens a list of lists into a single list, preserving element order within and across the constituent lists."},
{
"name": "hydra.core.lib.lists.concat.emptyInputs",
"kind": "requirement",
"statement": "concat of a list of lists in which every list is empty, or of an empty list of lists, is the empty list."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{
"name": "xss",
"description": "the list of lists to concatenate",
"type": {"list": {"list": {"variable": "x"}}},
"isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.concat2",
"metadata": {
"description": "Concatenate two lists.",
"comments": ["concat2(xs, ys) returns xs with ys appended.", "Total. Corresponds to Haskell's (++) :: [a] -> [a] -> [a]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.concat2.appendsPreservingOrder",
"kind": "requirement",
"statement": "concat2 appends its second list argument to its first, preserving the order of both, for both numeric and string element types."},
{
"name": "hydra.core.lib.lists.concat2.identityOnEmpty",
"kind": "requirement",
"statement": "concat2 with either or both arguments empty returns the other argument unchanged (the empty list is the identity element)."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{"name": "xs", "description": "the first list", "type": {"list": {"variable": "x"}}, "isLazy": false},
{"name": "ys", "description": "the list to append", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.cons",
"metadata": {
"description": "Prepend a value to a list.",
"comments": [
"cons(x, xs) returns a list whose head is x and whose tail is xs.",
"Total. Corresponds to Haskell's (:) :: a -> [a] -> [a]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.cons.prependsElement",
"kind": "requirement",
"statement": "cons prepends its first argument to the front of its second argument (the list), for empty and non-empty lists, any element type, and any value including negative numbers."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{"name": "x", "description": "the value to prepend", "type": {"variable": "x"}, "isLazy": false},
{"name": "xs", "description": "the list to prepend to", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.distinct",
"metadata": {
"description": "Remove duplicate elements from a list.",
"comments": [
"distinct(xs) returns the list of distinct elements of xs, in the order of their first occurrence.",
"Requires an 'equality' constraint on the element type.",
"Total. Corresponds to Haskell's Data.List.nub :: Eq a => [a] -> [a].",
"Renamed from hydra.lib.lists.nub."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": [
{
"name": "hydra.core.lib.lists.distinct.removesDuplicatesPreservingFirstOccurrence",
"kind": "requirement",
"statement": "distinct removes repeated elements, keeping only the first occurrence of each distinct value and preserving the relative order of the survivors, for numeric and string element types."},
{
"name": "hydra.core.lib.lists.distinct.emptyInput",
"kind": "requirement",
"statement": "distinct of an empty list is the empty list."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": [{"simple": "equality"}]}],
"parameters": [{"name": "xs", "description": "the list to deduplicate", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.drop",
"metadata": {
"description": "Drop the first n elements from a list.",
"comments": [
"drop(n, xs) returns the suffix of xs after dropping the first n elements; if n is greater than or equal to length(xs) the result is the empty list; if n is non-positive the result is xs unchanged.",
"Total. Corresponds to Haskell's drop :: Int -> [a] -> [a]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.drop.dropsFromFront",
"kind": "requirement",
"statement": "drop n removes the first n elements from the front of the list, or all elements if n is greater than or equal to the list's length."},
{
"name": "hydra.core.lib.lists.drop.nonPositiveIsIdentity",
"kind": "requirement",
"statement": "drop with n equal to zero or negative returns the list unchanged."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{
"name": "n",
"description": "the number of elements to drop",
"type": {"literal": {"integer": "int32"}},
"isLazy": false},
{"name": "xs", "description": "the list to drop from", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.dropWhile",
"metadata": {
"description": "Drop elements from the beginning of a list while the predicate is true.",
"comments": [
"dropWhile(p, xs) returns the suffix of xs starting at the first element for which p returns false. If p is true for every element, the result is the empty list.",
"Total. Corresponds to Haskell's dropWhile :: (a -> Bool) -> [a] -> [a]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.dropWhile.dropsLeadingMatches",
"kind": "requirement",
"statement": "dropWhile removes elements from the front of the list for as long as the predicate holds, stopping at (and keeping) the first element for which it does not; an empty list, a predicate matching no elements, or a predicate matching every element are each handled correctly as boundary cases."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{
"name": "p",
"description": "the predicate to test each element",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"literal": "boolean"}}},
"isLazy": false},
{"name": "xs", "description": "the list to drop from", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true,
"defaultImplementation": {
"lambda": {
"parameter": "p",
"body": {
"lambda": {
"parameter": "xs",
"body": {
"application": {
"function": {"variable": "hydra.core.lib.pairs.second"},
"argument": {
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.lists.span"}, "argument": {"variable": "p"}}},
"argument": {"variable": "xs"}}}}}}}}}}},
{
"primitive": {
"name": "hydra.core.lib.lists.filter",
"metadata": {
"description": "Filter a list by a predicate.",
"comments": [
"filter(p, xs) returns the list of elements x in xs for which p(x) is true, in original order.",
"Total. Corresponds to Haskell's filter :: (a -> Bool) -> [a] -> [a]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.filter.keepsMatchingElements",
"kind": "requirement",
"statement": "filter returns the sublist of elements satisfying the predicate, preserving their relative order, whether the predicate matches some, all, or none of the elements."},
{
"name": "hydra.core.lib.lists.filter.emptyInput",
"kind": "requirement",
"statement": "filter over an empty list is the empty list, regardless of the predicate."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{
"name": "p",
"description": "the predicate to test each element",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"literal": "boolean"}}},
"isLazy": false},
{"name": "xs", "description": "the list to filter", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true,
"defaultImplementation": {
"lambda": {
"parameter": "p",
"body": {
"lambda": {
"parameter": "xs",
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.foldr"},
"argument": {
"lambda": {
"parameter": "x",
"body": {
"lambda": {
"parameter": "acc",
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.logic.ifElse"},
"argument": {"application": {"function": {"variable": "p"}, "argument": {"variable": "x"}}}}},
"argument": {
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.lists.cons"}, "argument": {"variable": "x"}}},
"argument": {"variable": "acc"}}}}},
"argument": {"variable": "acc"}}}}}}}}},
"argument": {"list": []}}},
"argument": {"variable": "xs"}}}}}}}}},
{
"primitive": {
"name": "hydra.core.lib.lists.find",
"metadata": {
"description": "Find the first element matching a predicate.",
"comments": [
"find(p, xs) returns Just(x) where x is the first element of xs for which p(x) is true, or Nothing if no such element exists.",
"Total. Corresponds to Haskell's find :: (a -> Bool) -> [a] -> Maybe a."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.find.returnsFirstMatch",
"kind": "requirement",
"statement": "find returns the first element (wrapped) satisfying the predicate, scanning in list order."},
{
"name": "hydra.core.lib.lists.find.noneWhenNoMatchOrEmpty",
"kind": "requirement",
"statement": "find returns none when no element satisfies the predicate, including when the list is empty."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{
"name": "p",
"description": "the predicate to test each element",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"literal": "boolean"}}},
"isLazy": false},
{"name": "xs", "description": "the list to search", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"optional": {"variable": "x"}}}},
"isPure": true,
"isTotal": true,
"defaultImplementation": {
"lambda": {
"parameter": "p",
"body": {
"lambda": {
"parameter": "xs",
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.foldr"},
"argument": {
"lambda": {
"parameter": "x",
"body": {
"lambda": {
"parameter": "acc",
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.logic.ifElse"},
"argument": {"application": {"function": {"variable": "p"}, "argument": {"variable": "x"}}}}},
"argument": {"optional": {"variable": "x"}}}},
"argument": {"variable": "acc"}}}}}}}}},
"argument": {"optional": null}}},
"argument": {"variable": "xs"}}}}}}}}},
{
"primitive": {
"name": "hydra.core.lib.lists.foldList",
"metadata": {
"description": "Left-fold a list in the list monad (a nondeterministic fold).",
"comments": [
"foldList(f, acc0, xs) folds xs from the left, branching the accumulator over every result of the step function at each element: after each element the set of accumulators is replaced by all results of applying f to each current accumulator and that element.",
"foldList(f, acc0, xs) is foldl(\\macc el -> bind(macc, \\acc -> f(acc, el)), singleton(acc0), xs); this defining equation is the specification. For the empty list the result is singleton(acc0).",
"Total on finite inputs. The list-monad instance of the monadic left fold.",
"For example, if f(acc, x) returns the two-element list containing acc and the sum of acc and x, then foldList(f, 0, xs) computes the sums of all subsets of xs."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": []},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}],
"parameters": [
{
"name": "f",
"description": "the branching step function",
"type": {
"function": {
"domain": {"variable": "x"},
"codomain": {"function": {"domain": {"variable": "y"}, "codomain": {"list": {"variable": "x"}}}}}},
"isLazy": false},
{"name": "acc0", "description": "the initial accumulator", "type": {"variable": "x"}, "isLazy": false},
{"name": "xs", "description": "the list to fold", "type": {"list": {"variable": "y"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true,
"defaultImplementation": {
"lambda": {
"parameter": "f",
"body": {
"lambda": {
"parameter": "acc0",
"body": {
"lambda": {
"parameter": "xs",
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.foldl"},
"argument": {
"lambda": {
"parameter": "macc",
"body": {
"lambda": {
"parameter": "el",
"body": {
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.lists.bind"}, "argument": {"variable": "macc"}}},
"argument": {
"lambda": {
"parameter": "acc",
"body": {
"application": {
"function": {"application": {"function": {"variable": "f"}, "argument": {"variable": "acc"}}},
"argument": {"variable": "el"}}}}}}}}}}}}},
"argument": {"list": [{"variable": "acc0"}]}}},
"argument": {"variable": "xs"}}}}}}}}}}},
{
"primitive": {
"name": "hydra.core.lib.lists.foldl",
"metadata": {
"description": "Left-fold a list with an accumulator.",
"comments": [
"foldl(f, acc0, xs) reduces xs left-associatively: foldl(f, acc0, [x1, x2, ..., xn]) = f(f(f(acc0, x1), x2), ..., xn). For the empty list the result is acc0.",
"Strict in the accumulator on hosts where laziness would otherwise leak space.",
"Total on finite inputs. Corresponds to Haskell's foldl' :: (b -> a -> b) -> b -> [a] -> b."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.foldl.appliesLeftAssociatively",
"kind": "requirement",
"statement": "foldl combines the accumulator with each element left-to-right using the given binary operation, so order-sensitive operations (e.g. subtraction) reflect strict left associativity."},
{
"name": "hydra.core.lib.lists.foldl.emptyListReturnsAccumulator",
"kind": "requirement",
"statement": "foldl over an empty list returns the initial accumulator unchanged."}]},
"signature": {
"typeParameters": [{"name": "y", "constraints": []}, {"name": "x", "constraints": []}],
"parameters": [
{
"name": "f",
"description": "the step function combining accumulator and element",
"type": {
"function": {"domain": {"variable": "y"}, "codomain": {"function": {"domain": {"variable": "x"}, "codomain": {"variable": "y"}}}}},
"isLazy": false},
{"name": "acc0", "description": "the initial accumulator", "type": {"variable": "y"}, "isLazy": false},
{"name": "xs", "description": "the list to fold", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"variable": "y"}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.foldr",
"metadata": {
"description": "Right-fold a list with an accumulator.",
"comments": [
"foldr(f, acc0, xs) reduces xs right-associatively: foldr(f, acc0, [x1, ..., xn]) = f(x1, f(x2, ..., f(xn, acc0))). For the empty list the result is acc0.",
"Total on finite inputs. Corresponds to Haskell's foldr :: (a -> b -> b) -> b -> [a] -> b."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.foldr.appliesRightAssociatively",
"kind": "requirement",
"statement": "foldr combines each element with the accumulator right-to-left using the given binary operation, so order-sensitive operations (e.g. subtraction) reflect strict right associativity, and differ from the equivalent foldl where the operation is non-commutative."},
{
"name": "hydra.core.lib.lists.foldr.emptyListReturnsAccumulator",
"kind": "requirement",
"statement": "foldr over an empty list returns the initial accumulator unchanged."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}],
"parameters": [
{
"name": "f",
"description": "the step function combining element and accumulator",
"type": {
"function": {"domain": {"variable": "x"}, "codomain": {"function": {"domain": {"variable": "y"}, "codomain": {"variable": "y"}}}}},
"isLazy": false},
{"name": "acc0", "description": "the initial accumulator", "type": {"variable": "y"}, "isLazy": false},
{"name": "xs", "description": "the list to fold", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"variable": "y"}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.group",
"metadata": {
"description": "Group consecutive equal elements.",
"comments": [
"group(xs) returns a list of lists obtained by grouping consecutive equal elements of xs together. Each inner list is non-empty and contains equal elements; the concatenation of the result equals xs.",
"Equality is determined by the element type's 'equality' constraint.",
"Total. Corresponds to Haskell's Data.List.group :: Eq a => [a] -> [[a]]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.group.groupsConsecutiveDuplicates",
"kind": "requirement",
"statement": "group partitions the list into maximal runs of consecutive equal elements, preserving overall order; non-adjacent duplicates (e.g. [1,1,2,2,2,3,1]) are not merged into the same run."},
{
"name": "hydra.core.lib.lists.group.emptyInput",
"kind": "requirement",
"statement": "group of an empty list is the empty list."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": [{"simple": "equality"}]}],
"parameters": [{"name": "xs", "description": "the list to group", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"list": {"variable": "x"}}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.head",
"metadata": {
"description": "Return the first element, or Nothing if the list is empty.",
"comments": [
"head(xs) returns Just(x) where x is the first element of xs, or Nothing if xs is empty.",
"Total. Wraps Haskell's partial head in maybe.",
"Renamed from hydra.lib.lists.maybeHead."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": [
{
"name": "hydra.core.lib.lists.head.returnsFirstElement",
"kind": "requirement",
"statement": "head returns the first element of a non-empty list, wrapped, for any element type."},
{
"name": "hydra.core.lib.lists.head.noneWhenEmpty",
"kind": "requirement",
"statement": "head of an empty list is none, for any element type."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [{"name": "xs", "description": "the list to take the head of", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"optional": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.init",
"metadata": {
"description": "Return all elements except the last, or Nothing if the list is empty.",
"comments": [
"init(xs) returns Just(ys) where ys is xs with its last element removed, or Nothing if xs is empty.",
"Total. Wraps Haskell's partial init in maybe.",
"Renamed from hydra.lib.lists.maybeInit."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": [
{
"name": "hydra.core.lib.lists.init.returnsAllButLast",
"kind": "requirement",
"statement": "init returns all elements of a non-empty list except the last, wrapped, including the empty list when the input has exactly one element."},
{
"name": "hydra.core.lib.lists.init.noneWhenEmpty",
"kind": "requirement",
"statement": "init of an empty list is none."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{
"name": "xs",
"description": "the list to take the initial segment of",
"type": {"list": {"variable": "x"}},
"isLazy": false}],
"result": {"type": {"optional": {"list": {"variable": "x"}}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.intersperse",
"metadata": {
"description": "Intersperse a value between consecutive elements of a list.",
"comments": [
"intersperse(sep, xs) returns xs with sep inserted between each pair of adjacent elements; for lists of length 0 or 1 the input is returned unchanged.",
"Total. Corresponds to Haskell's intersperse :: a -> [a] -> [a]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.intersperse.insertsElementBetweenItems",
"kind": "requirement",
"statement": "intersperse inserts a copy of the given element between each pair of adjacent elements of the list (not before the first or after the last), for string and numeric element types."},
{
"name": "hydra.core.lib.lists.intersperse.noInsertionBelowTwoElements",
"kind": "requirement",
"statement": "intersperse on a list of zero or one elements returns the list unchanged -- there are no adjacent pairs to separate."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{"name": "sep", "description": "the separator value to insert", "type": {"variable": "x"}, "isLazy": false},
{"name": "xs", "description": "the list to intersperse into", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.isEmpty",
"metadata": {
"description": "Test whether a list is empty.",
"comments": ["isEmpty(xs) returns true iff xs is the empty list.", "Total. Corresponds to Haskell's null :: [a] -> Bool."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.isEmpty.testsZeroLength",
"kind": "requirement",
"statement": "isEmpty returns true exactly when the list has no elements, for any element type."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [{"name": "xs", "description": "the list to test", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"literal": "boolean"}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.join",
"metadata": {
"description": "Intercalate a list of lists with a separator list between each.",
"comments": [
"join(sep, xss) returns the concatenation of xss with sep inserted between consecutive lists. Equivalent to concat(intersperse(sep, xss)).",
"Total. Corresponds to Haskell's intercalate :: [a] -> [[a]] -> [a].",
"Renamed from hydra.lib.lists.intercalate."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": [
{
"name": "hydra.core.lib.lists.join.insertsSeparatorBetweenLists",
"kind": "requirement",
"statement": "join concatenates a list of lists with a copy of the separator list inserted between each pair of adjacent lists (not before the first or after the last), for separators of any length including empty, and skips the separator insertion where it has no visible effect (a single list, or lists containing empty lists)."},
{
"name": "hydra.core.lib.lists.join.emptyListOfLists",
"kind": "requirement",
"statement": "join of an empty list of lists is the empty list, regardless of the separator."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{"name": "sep", "description": "the separator list to insert", "type": {"list": {"variable": "x"}}, "isLazy": false},
{
"name": "xss",
"description": "the list of lists to join",
"type": {"list": {"list": {"variable": "x"}}},
"isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.last",
"metadata": {
"description": "Return the last element, or Nothing if the list is empty.",
"comments": [
"last(xs) returns Just(x) where x is the last element of xs, or Nothing if xs is empty.",
"Total. Wraps Haskell's partial last in maybe.",
"Renamed from hydra.lib.lists.maybeLast."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": [
{
"name": "hydra.core.lib.lists.last.returnsLastElement",
"kind": "requirement",
"statement": "last returns the final element of a non-empty list, wrapped, for any element type."},
{
"name": "hydra.core.lib.lists.last.noneWhenEmpty",
"kind": "requirement",
"statement": "last of an empty list is none."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{
"name": "xs",
"description": "the list to take the last element of",
"type": {"list": {"variable": "x"}},
"isLazy": false}],
"result": {"type": {"optional": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.length",
"metadata": {
"description": "Return the length of a list.",
"comments": [
"length(xs) returns the number of elements in xs as an int32. Returns 0 for the empty list.",
"Total on finite inputs; the int32 result overflows for lists longer than 2^31-1 elements.",
"Corresponds to Haskell's length :: [a] -> Int (with narrowing to Int32)."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.length.countsElements",
"kind": "requirement",
"statement": "length returns the number of elements in the list, for any element type, including zero for the empty list."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [{"name": "xs", "description": "the list to measure", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"literal": {"integer": "int32"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.map",
"metadata": {
"description": "Map a function over a list.",
"comments": [
"map(f, xs) returns the list of f(x) for each x in xs, in original order.",
"Total. Corresponds to Haskell's map :: (a -> b) -> [a] -> [b] / fmap on lists."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.map.appliesFunctionElementwise",
"kind": "requirement",
"statement": "map applies the given function to each element of the list in place, preserving list order and length, for any element and function."},
{
"name": "hydra.core.lib.lists.map.identityAndEmptyCases",
"kind": "requirement",
"statement": "map with the identity function returns the list unchanged; map over an empty list is the empty list."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}],
"parameters": [
{
"name": "f",
"description": "the function to apply to each element",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"variable": "y"}}},
"isLazy": false},
{"name": "xs", "description": "the list to map over", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "y"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.mapGivens",
"metadata": {
"description": "Map a partial function over a list, keeping only the present results.",
"comments": [
"mapGivens(f, xs) applies f to each element of xs and returns the list of contained values from given results in original order; none results are discarded.",
"Total. Corresponds to Haskell's Data.Maybe.mapMaybe :: (a -> Maybe b) -> [a] -> [b]."],
"seeAlso": [],
"provisions": []},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}],
"parameters": [
{
"name": "f",
"description": "the partial function to apply to each element",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"optional": {"variable": "y"}}}},
"isLazy": false},
{"name": "xs", "description": "the list to map over", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "y"}}}},
"isPure": true,
"isTotal": true,
"defaultImplementation": {
"lambda": {
"parameter": "f",
"body": {
"lambda": {
"parameter": "xs",
"body": {
"application": {
"function": {"variable": "hydra.core.lib.optionals.givens"},
"argument": {
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.lists.map"}, "argument": {"variable": "f"}}},
"argument": {"variable": "xs"}}}}}}}}}}},
{
"primitive": {
"name": "hydra.core.lib.lists.mapList",
"metadata": {
"description": "Traverse a list in the list monad.",
"comments": [
"mapList(f, xs) returns all combinations obtainable by choosing one element from f(x) for each x in xs: each result list has the same length as xs, with its element at each position drawn from the corresponding f(x).",
"Results appear in the lexicographic order of the choices, with the choice for the first element varying slowest. The number of results is the product of the lengths of the lists f(x); if f(x) is empty for any element, the result is the empty list; mapList(f, []) is singleton([]).",
"Total on finite inputs. The list-monad instance of the traversal family."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": []},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}],
"parameters": [
{
"name": "f",
"description": "the list-returning function to apply to each element",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"list": {"variable": "y"}}}},
"isLazy": false},
{"name": "xs", "description": "the list to traverse", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"list": {"variable": "y"}}}}},
"isPure": true,
"isTotal": true,
"defaultImplementation": {
"lambda": {
"parameter": "f",
"body": {
"lambda": {
"parameter": "xs",
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.foldr"},
"argument": {
"lambda": {
"parameter": "x",
"body": {
"lambda": {
"parameter": "acc",
"body": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.bind"},
"argument": {"application": {"function": {"variable": "f"}, "argument": {"variable": "x"}}}}},
"argument": {
"lambda": {
"parameter": "y",
"body": {
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.lists.bind"}, "argument": {"variable": "acc"}}},
"argument": {
"lambda": {
"parameter": "ys",
"body": {
"list": [
{
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.lists.cons"}, "argument": {"variable": "y"}}},
"argument": {"variable": "ys"}}}]}}}}}}}}}}}}}}},
"argument": {"list": [{"list": []}]}}},
"argument": {"variable": "xs"}}}}}}}}},
{
"primitive": {
"name": "hydra.core.lib.lists.mapOptional",
"metadata": {
"description": "Traverse an optional value in the list monad.",
"comments": [
"mapOptional(f, m) returns the single-element list containing none when m is none; for given(x) it returns given(y) for each element y of f(x), in order.",
"Total on finite inputs. The list-monad instance of the traversal family, applied to the optional container."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": []},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}],
"parameters": [
{
"name": "f",
"description": "the list-returning function to apply",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"list": {"variable": "y"}}}},
"isLazy": false},
{"name": "m", "description": "the optional value to traverse", "type": {"optional": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"optional": {"variable": "y"}}}}},
"isPure": true,
"isTotal": true,
"defaultImplementation": {
"lambda": {
"parameter": "f",
"body": {
"lambda": {
"parameter": "m",
"body": {
"application": {
"function": {
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.optionals.match"}, "argument": {"variable": "m"}}},
"argument": {"list": [{"optional": null}]}}},
"argument": {
"lambda": {
"parameter": "x",
"body": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.bind"},
"argument": {"application": {"function": {"variable": "f"}, "argument": {"variable": "x"}}}}},
"argument": {"lambda": {"parameter": "y", "body": {"list": [{"optional": {"variable": "y"}}]}}}}}}}}}}}}}}},
{
"primitive": {
"name": "hydra.core.lib.lists.mapSet",
"metadata": {
"description": "Traverse a set in the list monad.",
"comments": [
"mapSet(f, s) returns all sets obtainable by choosing one element from f(x) for each element x of s. Elements of s are traversed in ascending order, and results appear in the lexicographic order of the choices, with the choice for the least element varying slowest.",
"A result set may have fewer elements than s when distinct choices coincide. If f(x) is empty for any element, the result is the empty list; for the empty set the result is the single-element list containing the empty set.",
"Requires 'ordering' constraints on both element types (the set type contract)."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": []},
"signature": {
"typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}, {"name": "y", "constraints": [{"simple": "ordering"}]}],
"parameters": [
{
"name": "f",
"description": "the list-returning function to apply to each element",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"list": {"variable": "y"}}}},
"isLazy": false},
{"name": "s", "description": "the set to traverse", "type": {"set": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"set": {"variable": "y"}}}}},
"isPure": true,
"isTotal": true,
"defaultImplementation": {
"lambda": {
"parameter": "f",
"body": {
"lambda": {
"parameter": "s",
"body": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.map"},
"argument": {
"lambda": {
"parameter": "ys",
"body": {"application": {"function": {"variable": "hydra.core.lib.sets.fromList"}, "argument": {"variable": "ys"}}}}}}},
"argument": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.foldr"},
"argument": {
"lambda": {
"parameter": "x",
"body": {
"lambda": {
"parameter": "acc",
"body": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.bind"},
"argument": {"application": {"function": {"variable": "f"}, "argument": {"variable": "x"}}}}},
"argument": {
"lambda": {
"parameter": "y",
"body": {
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.lists.bind"}, "argument": {"variable": "acc"}}},
"argument": {
"lambda": {
"parameter": "ys",
"body": {
"list": [
{
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.lists.cons"}, "argument": {"variable": "y"}}},
"argument": {"variable": "ys"}}}]}}}}}}}}}}}}}}},
"argument": {"list": [{"list": []}]}}},
"argument": {"application": {"function": {"variable": "hydra.core.lib.sets.toList"}, "argument": {"variable": "s"}}}}}}}}}}}}},
{
"primitive": {
"name": "hydra.core.lib.lists.member",
"metadata": {
"description": "Test whether an element is in a list.",
"comments": [
"member(x, xs) returns true iff some element of xs is equal to x.",
"Requires an 'equality' constraint on the element type.",
"Total. Corresponds to Haskell's elem :: Eq a => a -> [a] -> Bool.",
"Renamed from hydra.lib.lists.elem."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": [
{
"name": "hydra.core.lib.lists.member.testsSetMembership",
"kind": "requirement",
"statement": "member returns true exactly when the given value occurs at least once in the list, for both numeric and string elements, including lists with duplicates."},
{
"name": "hydra.core.lib.lists.member.falseWhenAbsentOrEmpty",
"kind": "requirement",
"statement": "member returns false when the value does not occur in the list, including when the list is empty."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": [{"simple": "equality"}]}],
"parameters": [
{"name": "x", "description": "the value to look for", "type": {"variable": "x"}, "isLazy": false},
{"name": "xs", "description": "the list to search", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"literal": "boolean"}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.partition",
"metadata": {
"description": "Partition a list into elements that satisfy a predicate and those that do not.",
"comments": [
"partition(p, xs) returns a pair (yes, no) where yes is the list of elements of xs for which p is true and no is the list of elements for which p is false, each preserving original order.",
"Total. Corresponds to Haskell's partition :: (a -> Bool) -> [a] -> ([a], [a])."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.partition.splitsBySatisfaction",
"kind": "requirement",
"statement": "partition returns a pair of (elements satisfying the predicate, elements not satisfying it), each sublist preserving the original relative order of its members."},
{
"name": "hydra.core.lib.lists.partition.boundaryCases",
"kind": "requirement",
"statement": "partition degrades correctly at the boundaries: a predicate matching every element yields (whole list, empty); matching none yields (empty, whole list); an empty input list yields (empty, empty)."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{
"name": "p",
"description": "the predicate to test each element",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"literal": "boolean"}}},
"isLazy": false},
{"name": "xs", "description": "the list to partition", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"pair": {"first": {"list": {"variable": "x"}}, "second": {"list": {"variable": "x"}}}}}},
"isPure": true,
"isTotal": true,
"defaultImplementation": {
"lambda": {
"parameter": "p",
"body": {
"lambda": {
"parameter": "xs",
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.foldr"},
"argument": {
"lambda": {
"parameter": "x",
"body": {
"lambda": {
"parameter": "acc",
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.logic.ifElse"},
"argument": {"application": {"function": {"variable": "p"}, "argument": {"variable": "x"}}}}},
"argument": {
"pair": {
"first": {
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.lists.cons"}, "argument": {"variable": "x"}}},
"argument": {"application": {"function": {"variable": "hydra.core.lib.pairs.first"}, "argument": {"variable": "acc"}}}}},
"second": {"application": {"function": {"variable": "hydra.core.lib.pairs.second"}, "argument": {"variable": "acc"}}}}}}},
"argument": {
"pair": {
"first": {"application": {"function": {"variable": "hydra.core.lib.pairs.first"}, "argument": {"variable": "acc"}}},
"second": {
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.lists.cons"}, "argument": {"variable": "x"}}},
"argument": {"application": {"function": {"variable": "hydra.core.lib.pairs.second"}, "argument": {"variable": "acc"}}}}}}}}}}}}}}},
"argument": {"pair": {"first": {"list": []}, "second": {"list": []}}}}},
"argument": {"variable": "xs"}}}}}}}}},
{
"primitive": {
"name": "hydra.core.lib.lists.replicate",
"metadata": {
"description": "Build a list of n copies of a value.",
"comments": [
"replicate(n, x) returns a list of n copies of x; for n <= 0 the result is the empty list.",
"Total. Corresponds to Haskell's replicate :: Int -> a -> [a]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.replicate.repeatsValueNTimes",
"kind": "requirement",
"statement": "replicate n x returns a list containing n copies of x, including the empty list when n is zero, for numeric and string element types."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{"name": "n", "description": "the number of copies", "type": {"literal": {"integer": "int32"}}, "isLazy": false},
{"name": "x", "description": "the value to replicate", "type": {"variable": "x"}, "isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.reverse",
"metadata": {
"description": "Reverse a list.",
"comments": ["reverse(xs) returns the elements of xs in reverse order.", "Total. Corresponds to Haskell's reverse :: [a] -> [a]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.reverse.reversesElementOrder",
"kind": "requirement",
"statement": "reverse returns the list with its elements in the opposite order, for any element type, including lists of zero or one elements (which are unaffected)."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [{"name": "xs", "description": "the list to reverse", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.singleton",
"metadata": {
"description": "Construct a single-element list.",
"comments": [
"singleton(x) = [x].",
"The constructor for a single-element list; useful point-free (e.g. map singleton xs).",
"Total. Corresponds to Haskell's singleton :: a -> [a]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.singleton.wrapsOneElement",
"kind": "requirement",
"statement": "singleton x returns a one-element list containing exactly x, for any value including negative numbers, zero, and strings."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [{"name": "x", "description": "the value to wrap in a single-element list", "type": {"variable": "x"}, "isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.sort",
"metadata": {
"description": "Sort a list.",
"comments": [
"sort(xs) returns xs sorted in ascending order under the element type's ordering. Sort is stable: equal elements preserve their original relative order.",
"Requires an 'ordering' constraint on the element type.",
"Total. Corresponds to Haskell's Data.List.sort :: Ord a => [a] -> [a]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.sort.ordersAscending",
"kind": "requirement",
"statement": "sort returns the list's elements in ascending order under the type's natural ordering, preserving multiplicity (duplicates are kept), and leaves already-sorted or single-element lists unchanged."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}],
"parameters": [{"name": "xs", "description": "the list to sort", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.sortBy",
"metadata": {
"description": "Sort a list using a key-extraction function.",
"comments": [
"sortBy(f, xs) returns xs sorted in ascending order by f(x) for each element x. Sort is stable: elements with equal keys preserve their original relative order.",
"Requires an 'ordering' constraint on the key type.",
"Total. Corresponds to Haskell's Data.List.sortOn :: Ord b => (a -> b) -> [a] -> [a].",
"Renamed from hydra.lib.lists.sortOn."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": [
{
"name": "hydra.core.lib.lists.sortBy.ordersByKeyFunction",
"kind": "requirement",
"statement": "sortBy returns the list ordered ascending by the natural ordering of the given key function's output, not the elements' own ordering, so the result changes with the key function (e.g. sorting strings by length, or numbers by absolute value, differs from sorting by natural value)."},
{
"name": "hydra.core.lib.lists.sortBy.boundaryInputs",
"kind": "requirement",
"statement": "sortBy on an empty or single-element list returns it unchanged, regardless of the key function."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": [{"simple": "ordering"}]}],
"parameters": [
{
"name": "f",
"description": "the key-extraction function",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"variable": "y"}}},
"isLazy": false},
{"name": "xs", "description": "the list to sort", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.span",
"metadata": {
"description": "Split a list at the first element where the predicate fails.",
"comments": [
"span(p, xs) returns a pair (ys, zs) where ys is the longest prefix of xs whose elements all satisfy p, and zs is the remainder of xs starting at the first element that fails p (or zs is empty if all elements satisfy p).",
"Total. Corresponds to Haskell's span :: (a -> Bool) -> [a] -> ([a], [a])."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.span.splitsAtFirstNonMatch",
"kind": "requirement",
"statement": "span returns a pair of (longest prefix for which the predicate holds, the remaining suffix), degrading correctly when the predicate matches every element (whole list, empty), no elements (empty, whole list), or the input is empty (empty, empty)."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{
"name": "p",
"description": "the predicate to test each element",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"literal": "boolean"}}},
"isLazy": false},
{"name": "xs", "description": "the list to split", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"pair": {"first": {"list": {"variable": "x"}}, "second": {"list": {"variable": "x"}}}}}},
"isPure": true,
"isTotal": true,
"defaultImplementation": {
"lambda": {
"parameter": "p",
"body": {
"lambda": {
"parameter": "xs",
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.foldl"},
"argument": {
"lambda": {
"parameter": "acc",
"body": {
"lambda": {
"parameter": "x",
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.logic.ifElse"},
"argument": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.logic.and"},
"argument": {
"application": {
"function": {"variable": "hydra.core.lib.lists.isEmpty"},
"argument": {"application": {"function": {"variable": "hydra.core.lib.pairs.second"}, "argument": {"variable": "acc"}}}}}}},
"argument": {"application": {"function": {"variable": "p"}, "argument": {"variable": "x"}}}}}}},
"argument": {
"pair": {
"first": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.concat2"},
"argument": {"application": {"function": {"variable": "hydra.core.lib.pairs.first"}, "argument": {"variable": "acc"}}}}},
"argument": {"list": [{"variable": "x"}]}}},
"second": {"application": {"function": {"variable": "hydra.core.lib.pairs.second"}, "argument": {"variable": "acc"}}}}}}},
"argument": {
"pair": {
"first": {"application": {"function": {"variable": "hydra.core.lib.pairs.first"}, "argument": {"variable": "acc"}}},
"second": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.lists.concat2"},
"argument": {"application": {"function": {"variable": "hydra.core.lib.pairs.second"}, "argument": {"variable": "acc"}}}}},
"argument": {"list": [{"variable": "x"}]}}}}}}}}}}}}},
"argument": {"pair": {"first": {"list": []}, "second": {"list": []}}}}},
"argument": {"variable": "xs"}}}}}}}}},
{
"primitive": {
"name": "hydra.core.lib.lists.tail",
"metadata": {
"description": "Return all elements except the first, or Nothing if the list is empty.",
"comments": [
"tail(xs) returns Just(ys) where ys is xs with its first element removed, or Nothing if xs is empty.",
"Total. Wraps Haskell's partial tail in maybe.",
"Renamed from hydra.lib.lists.maybeTail."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": [
{
"name": "hydra.core.lib.lists.tail.returnsAllButFirst",
"kind": "requirement",
"statement": "tail returns all elements of a non-empty list except the first, wrapped, including the empty list when the input has exactly one element."},
{
"name": "hydra.core.lib.lists.tail.noneWhenEmpty",
"kind": "requirement",
"statement": "tail of an empty list is none."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [{"name": "xs", "description": "the list to take the tail of", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"optional": {"list": {"variable": "x"}}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.take",
"metadata": {
"description": "Take the first n elements of a list.",
"comments": [
"take(n, xs) returns the prefix of xs of length min(n, length(xs)); if n is non-positive the result is the empty list.",
"Total. Corresponds to Haskell's take :: Int -> [a] -> [a]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.take.takesFromFront",
"kind": "requirement",
"statement": "take n returns the first n elements of the list, or the whole list if n is greater than or equal to its length."},
{
"name": "hydra.core.lib.lists.take.nonPositiveIsEmpty",
"kind": "requirement",
"statement": "take with n equal to zero or negative returns the empty list."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{
"name": "n",
"description": "the number of elements to take",
"type": {"literal": {"integer": "int32"}},
"isLazy": false},
{"name": "xs", "description": "the list to take from", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.takeWhile",
"metadata": {
"description": "Take elements from the beginning of a list while a predicate holds.",
"comments": [
"takeWhile(p, xs) returns the longest prefix of xs whose elements all satisfy p. If p fails for the first element the result is the empty list; if p holds for every element the result is xs unchanged.",
"dropWhile returns the complementary suffix, and span(p, xs) returns the pair of takeWhile(p, xs) and dropWhile(p, xs).",
"Total. Corresponds to Haskell's takeWhile :: (a -> Bool) -> [a] -> [a]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.17.6"},
"provisions": []},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{
"name": "p",
"description": "the predicate to test each element",
"type": {"function": {"domain": {"variable": "x"}, "codomain": {"literal": "boolean"}}},
"isLazy": false},
{"name": "xs", "description": "the list to take from", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "x"}}}},
"isPure": true,
"isTotal": true,
"defaultImplementation": {
"lambda": {
"parameter": "p",
"body": {
"lambda": {
"parameter": "xs",
"body": {
"application": {
"function": {"variable": "hydra.core.lib.pairs.first"},
"argument": {
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.lists.span"}, "argument": {"variable": "p"}}},
"argument": {"variable": "xs"}}}}}}}}}}},
{
"primitive": {
"name": "hydra.core.lib.lists.transpose",
"metadata": {
"description": "Transpose a list of lists.",
"comments": [
"transpose(xss) returns a list of lists where the i-th inner list contains the i-th element of every inner list of xss that has at least i+1 elements. Inner lists of differing lengths produce a ragged result rather than an error.",
"Total. Corresponds to Haskell's Data.List.transpose :: [[a]] -> [[a]]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.transpose.swapsRowsAndColumns",
"kind": "requirement",
"statement": "transpose converts a list of rows into a list of columns, where column i holds the i-th element of every row that has one; rows need not be the same length (a ragged matrix is handled by omitting absent elements, not by padding or erroring), and an empty list of rows yields the empty list."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [
{
"name": "xss",
"description": "the list of lists to transpose",
"type": {"list": {"list": {"variable": "x"}}},
"isLazy": false}],
"result": {"type": {"list": {"list": {"variable": "x"}}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.uncons",
"metadata": {
"description": "Decompose a list into its head and tail, or Nothing if empty.",
"comments": [
"uncons(xs) returns Just(head, tail) where head is the first element of xs and tail is the remaining list, or Nothing if xs is empty.",
"Total. Corresponds to Haskell's Data.List.uncons :: [a] -> Maybe (a, [a])."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.uncons.splitsHeadAndTail",
"kind": "requirement",
"statement": "uncons on a non-empty list returns (wrapped) the pair of its first element and the remaining list, including when the remaining list is empty."},
{
"name": "hydra.core.lib.lists.uncons.noneWhenEmpty",
"kind": "requirement",
"statement": "uncons of an empty list is none."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}],
"parameters": [{"name": "xs", "description": "the list to decompose", "type": {"list": {"variable": "x"}}, "isLazy": false}],
"result": {"type": {"optional": {"pair": {"first": {"variable": "x"}, "second": {"list": {"variable": "x"}}}}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.zip",
"metadata": {
"description": "Zip two lists element-wise into pairs.",
"comments": [
"zip(xs, ys) returns the list of pairs (xs[i], ys[i]) for i from 0 to min(length(xs), length(ys))-1. The result has length equal to the shorter of the two inputs.",
"Total. Corresponds to Haskell's zip :: [a] -> [b] -> [(a, b)]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.zip.pairsElementwise",
"kind": "requirement",
"statement": "zip combines two lists into a list of pairs by position, truncating to the length of the shorter list when the lengths differ."},
{
"name": "hydra.core.lib.lists.zip.emptyWhenEitherEmpty",
"kind": "requirement",
"statement": "zip is the empty list whenever either input list is empty."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}],
"parameters": [
{"name": "xs", "description": "the first list", "type": {"list": {"variable": "x"}}, "isLazy": false},
{"name": "ys", "description": "the second list", "type": {"list": {"variable": "y"}}, "isLazy": false}],
"result": {"type": {"list": {"pair": {"first": {"variable": "x"}, "second": {"variable": "y"}}}}}},
"isPure": true,
"isTotal": true}},
{
"primitive": {
"name": "hydra.core.lib.lists.zipWith",
"metadata": {
"description": "Zip two lists with a combining function.",
"comments": [
"zipWith(f, xs, ys) returns the list of f(xs[i], ys[i]) for i from 0 to min(length(xs), length(ys))-1. The result has length equal to the shorter of the two inputs.",
"Total. Corresponds to Haskell's zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]."],
"seeAlso": [],
"lifecycle": {"availableSince": "0.15"},
"provisions": [
{
"name": "hydra.core.lib.lists.zipWith.combinesElementwiseByFunction",
"kind": "requirement",
"statement": "zipWith combines two lists position-by-position using the given binary function, truncating to the length of the shorter list when the lengths differ, for numeric and string element/result types."},
{
"name": "hydra.core.lib.lists.zipWith.emptyWhenEitherEmpty",
"kind": "requirement",
"statement": "zipWith is the empty list whenever either input list is empty, regardless of the function."}]},
"signature": {
"typeParameters": [{"name": "x", "constraints": []}, {"name": "y", "constraints": []}, {"name": "z", "constraints": []}],
"parameters": [
{
"name": "f",
"description": "the combining function",
"type": {
"function": {"domain": {"variable": "x"}, "codomain": {"function": {"domain": {"variable": "y"}, "codomain": {"variable": "z"}}}}},
"isLazy": false},
{"name": "xs", "description": "the first list", "type": {"list": {"variable": "x"}}, "isLazy": false},
{"name": "ys", "description": "the second list", "type": {"list": {"variable": "y"}}, "isLazy": false}],
"result": {"type": {"list": {"variable": "z"}}}},
"isPure": true,
"isTotal": true}}]}