def truthy

cswap-bend-cli@0.1.0.0 · setload.bend:16

import cswap-bend-cli@0.1.0.0/setload.bend as Setload
import Base
import cswap-bend-cli@0.1.0.0/json.bend as Json
import cswap-bend-cli@0.1.0.0/settings.bend as Settings

16# Python truthiness of a JSON value.
17def truthy(j: Json.Json) -> Bool:
18  match j:
19    case Json.JNull{}:
20      False{}
21    case Json.JBool{b}:
22      b
23    case Json.JNum{t}:
24      Bool.not(Settings.is_zero(Settings.lit(t)))
25    case Json.JStr{s}:
26      Bool.not(String.is_empty(s))
27    case Json.JArr{items}:
28      truthy.items(items)
29    case Json.JObj{fields}:
30      truthy.items(fields)
31    case _:
32      False{}

Uses (7)

Used by (2)