dhall-nix-lib/Number/fromAny.dhall

13 lines
396 B
Text

λ(nix : ../NixPrelude.dhall) →
let Any = ../Any/Type.dhall
let Number = ./Type.dhall
let Any/toTypeUnchecked = ../Any/toTypeUnchecked.dhall nix
let Misc/throw = ../Misc/throw.dhall nix
in λ(v : Any) →
if nix.builtins.isInt v || nix.builtins.isFloat v
then Any/toTypeUnchecked Number v
else Misc/throw Number "Failed to coerce object into Number"