dhall-nix-lib/Natural/fromAny.dhall

17 lines
593 B
Text

λ(nix : ../NixPrelude.dhall) →
let Any = ../Any/Type.dhall
let Integer/nonNegative =
https://raw.githubusercontent.com/dhall-lang/dhall-lang/v22.0.0/Prelude/Integer/nonNegative.dhall
sha256:b463373f070df6b1c8c7082051e0810fee38b360bab35256187c8c2b6af5c663
let Misc/throw = ../Misc/throw.dhall nix
let Integer/fromAny = ../Integer/fromAny.dhall nix
in λ(v : Any) →
let int = Integer/fromAny v
in if Integer/nonNegative int
then Integer/clamp int
else Misc/throw Natural "Failed to coerce object into Natural"