question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Defining dynamic but consistent types

See original GitHub issue

The FooByUser object is a simple structure representing the amount of foo performed by each user, setting each property’s key & value to the username & recorded foo respectively.

The collection of keys composing the object may vary between objects representing different periods. For example if new user3 records foo in April then the March and April objects will differ in keys : {user1: 100, user2: 3} vs {user1: 87, user2: 5, user3: 30 }.

From a code documentation perspective I want to define FooByUser as having a set of property keys of known origin & type (if such a word can be used), but which cannot be predetermined for each particular instance.

Could we have a syntax something like the following?

interface FooByUser {
  *<username>: Number
}
def username {
  desc:    "The username of a user",
  source: {type: "database", location: "users.id"} 
}

Where the <> demonstrate that that we are using a def rather than a static key and the * represents that there may be more than one of these keys.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Mouvediacommented, Jul 3, 2016

We either should declare and hold to our “different syntax path”, or use existing JS practices and hold to “JS ecosystem syntax path”.

Whenever we can we will provide something that is familiar.

Concerning the declared intents, I am not inclined to edit these: Eric is the one who knows what he envisioned originally. You can do a PR though.

0reactions
ericelliottcommented, Mar 26, 2017

It sounds like what you really want is a generic collection, where we don’t care about the names of the keys at all. You could implement such a collection that shares some convenience methods from Arrays using #120:

typeclass Foldable {
  reduce (this: Foldable[a], (accumulator: b, item: a) => b, initial?: a) => b
};

typeclass Semigroup {
  concat (this: Semigroup[a], ...args: [...Semigroup[Any]]) => Semigroup[Any]
};

typeclass Functor {
  map (this: Functor[a], a => b) => Functor[b]
};

typeclass Collection: Foldable & Semigroup & Functor;

interface User {
  name: String,
  number: Number
};

interface UserCollection: Collection[User] & {
  byName (this, name: String) => Number
}

Would that work for your usecase?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic inconsistency - Wikipedia
In economics, dynamic inconsistency or time inconsistency is a situation in which a decision-maker's preferences change over time in such a way that...
Read more >
Introduction to Data Types: Static, Dynamic, Strong & Weak
Dynamic defines how a language expects you to declare data types. ... A strict language will ensure consistency and reduce the amount of ......
Read more >
What is Dynamic and Static? Definition from TechTarget.com
In general, dynamic means "energetic or forceful," while static means "stationary." In computer terminology, however, dynamic usually means "capable of action ...
Read more >
Dynamic Characters vs. Static Characters - Masterclass
Dynamic characters are the opposite of static characters ; while dynamic characters change throughout a story, static characters stay the same.
Read more >
The true and false result expressions must have consistent ...
The true and false result expressions must have consistent types. The 'true' value is set of dynamic, but the 'false' value is object....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found