Merge branch 'zero-sumtypes' of https://github.com/hellerve/Carp into hellerve-zero-sumtypes

This commit is contained in:
Erik Svedäng 2020-04-30 14:46:35 +02:00
commit 504f63ffb4
3 changed files with 28 additions and 0 deletions

View File

@ -66,4 +66,7 @@ It is the inverse of [`just?`](#just?).")
(if (null? a)
(Nothing)
(Just @(Pointer.to-ref a))))
(doc zero "returns `Nothing`.")
(defn zero [] (Nothing))
)

View File

@ -502,6 +502,26 @@ a value using <code>zero</code> if a <code>Nothing</code> is passed.</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#zero">
<h3 id="zero">
zero
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [] (Maybe a))
</p>
<pre class="args">
(zero)
</pre>
<p class="doc">
<p>returns <code>Nothing</code>.</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#zip">
<h3 id="zip">

View File

@ -63,6 +63,11 @@
(or-zero (the (Maybe Int) (Nothing)))
"or-zero works on Nothing"
)
(assert-equal test
&(Nothing)
&(the (Maybe Int) (zero))
"zero works"
)
(assert-equal test
&(Result.Success 1)
&(to-result (Just 1) @"error")