toStructValue method

dynamic toStructValue(
  1. dynamic value
)

Implementation

dynamic toStructValue(dynamic value) {
  if (value is Iterable) {
    final list = [];
    for (final item in value) {
      final result = toStructValue(item);
      list.add(result);
    }
    return list;
  } else if (value is Map) {
    final HTStruct prototype = rootStruct ??
        globalNamespace.memberGet(_lexicon.globalPrototypeId,
            isRecursive: true);
    final struct =
        HTStruct(this, prototype: prototype, closure: currentNamespace);
    for (final key in value.keys) {
      final fieldKey = key.toString();
      final fieldValue = toStructValue(value[key]);
      struct.define(fieldKey, fieldValue);
    }
    return struct;
  } else if (value is HTStruct) {
    return value.clone();
  } else {
    return value;
  }
}