Current section
Files
Jump to
Current section
Files
gen/docs/validator/option/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>validator/option - validator</title>
<link rel="stylesheet" href="../../index.css" type="text/css" />
</head>
<body>
<header class="page-header">
<h2>
validator<!-- - -->
</h2>
</header>
<div class="page">
<nav class="sidebar">
<a class="sidebar-toggle" href="#">
<svg
aria-hidden="true"
focusable="false"
data-prefix="fas"
data-icon="bars"
class="svg-inline--fa fa-bars fa-w-14"
role="img"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 448 512"
>
<path
fill="#fff"
d="M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"
></path>
</svg>
</a>
<h2>Pages</h2>
<ul>
<li><a href="../../index.html">README</a></li>
</ul>
<h2>Modules</h2>
<ul>
<li><a href="../../validator/">validator</a></li>
<li><a href="../../validator/common/">validator/common</a></li>
<li><a href="../../validator/int/">validator/int</a></li>
<li><a href="../../validator/list/">validator/list</a></li>
<li><a href="../../validator/option/">validator/option</a></li>
<li><a href="../../validator/string/">validator/string</a></li>
</ul>
<h2>Functions</h2>
<ul>
<li><a href="#is_some">is_some</a></li>
<li><a href="#optional">optional</a></li>
</ul>
</nav>
<div class="content">
<h1 class="module-name">validator/option</h1>
<section class="module-members">
<a href="#module-functions">
<h1 id="module-functions" class="module-member-kind">Functions</h1>
</a>
<div class="member">
<a href="#is_some">
<h2 id="is_some" class="member-name">
is_some
</h2>
</a>
<pre>pub fn is_some(
error: a,
) -> fn(Option(b)) -> Result(b, tuple(a, List(a)))</pre>
<div class="rendered-markdown"><p>Validate that a value is not None.
Returns the value if Some.</p>
<h2>Example</h2>
<pre><code>type PersonInput { PersonInput(name: Option(String)) }
type PersonValid { PersonValid(name: String) }
let validator = fn(person) {
v.build1(PersonValid)
|> v.validate(person.name, option.is_some("Name is null"))
}
</code></pre>
</div>
</div>
<div class="member">
<a href="#optional">
<h2 id="optional" class="member-name">
optional
</h2>
</a>
<pre>pub fn optional(
validator: fn(a) -> Result(a, tuple(b, List(b))),
) -> fn(Option(a)) -> Result(Option(a), tuple(b, List(b)))</pre>
<div class="rendered-markdown"><p>Validate an optional value.</p>
<p>Run the validator only if the value is Some.
If the value is None then just return None back.</p>
<h2>Example</h2>
<pre><code>let validator = fn(person) {
v.build1(PersonValid)
|> v.validate(
person.name,
option.optional(string.min_length("Short", 3))
)
}
</code></pre>
</div>
</div>
</section>
</div>
</div>
<footer class="pride" onclick="document.querySelector('.pride').classList.toggle('show')">
<div class="blue">Lucy</div>
<div class="pink">says</div>
<div class="white">trans</div>
<div class="pink">rights</div>
<div class="blue">✨</div>
<a>✨</a>
</footer>
</body>
</html>