DEV Community

Cover image for Dictu 0.22.0!
Jason_000
Jason_000

Posted on

Dictu 0.22.0!

Dictu 0.22.0

A new release of Dictu is here! For those of you who do now yet know what Dictu is, please see my introductory post about it here.

Whats changed

list.findIndex()

This is very similar to .find() that is already in the language, or for those of you more versed in a language like JavaScript, has the same outcome as that. It allows you to provide a callback and find the index of an item within a list once the callback evaluates to true

const myList = [1, 2, 3, 4, 5];
print(myList.findIndex(def (item) => item == 4)); // 3
Enter fullscreen mode Exit fullscreen mode

Enums

Previously in Dictu you had to provide a value to an enum when defining it, with 0.22.0 you no longer have to provide a value and instead it's value will take the index within the enum (0-based).

enum DaysOfTheWeek {
  Monday,
  Tuesday,
  Wednesday,
  Thursday,
  Friday,
  Saturday,
  Sunday
}

print(DaysOfTheWeek.Monday); // 0
print(DaysOfTheWeek.Saturday); // 6
Enter fullscreen mode Exit fullscreen mode

System Module

This is a breaking change; the System module now requires an import as previously it was the only module in the standard library that did not require an import.

obj.methods()

This is a new method on all instantiated objects which returns a list of all the methods defined on the object that are marked as public. This will allow us to cleverly call methods at runtime.

class Test {
    myMethod() {

    }

    private myPrivateMethod() {

    }
}

print(Test().methods()); // ["myMethod"]
Enter fullscreen mode Exit fullscreen mode

obj.getAttribute()

A bug-fix was applied to getAttribute, previously if this was used on an object to attempt to return a bound method it was returning a function object (which had no notion of the object it was bound to), instead this has been fixed so that it correctly returns a bound method.

dict.merge()

This new method allows us to merge two dictionaries into a single dictionary.

const dictOne = {"key": 1, "key1": 2, "key2": 3};
const dictTwo = {"key3": 4,"key1": 0};

print(dictOne.merge(dictTwo)); // {"key2": 3, "key": 1, "key3": 4, "key1": 0}
Enter fullscreen mode Exit fullscreen mode

Env.get()

Dictu already had Env.get() through the Env module, however, this has been extended so that if the env variable is not found a suitable default value (which must be a string) is returned instead.

import Env;

print(Env.get("this really doesn't exist", "default")); // default
Enter fullscreen mode Exit fullscreen mode

Result.matchUnwrap()

This is a new method that allows us to match on a result type but then immediately re-wrap the value back up that is returned from the callback. If you do not know about Dictu's method for error handling, see here first.

var response = HTTP.get("https://some/endpoint").matchWrap(
    def (data) => JSON.parse(data).unwrap(),
    def (error) => error
);

print(response); // <Result Suc>
Enter fullscreen mode Exit fullscreen mode

Summary

That about sums up the 0.22.0 release in a brief overview, but there are more exciting things in the work already for the next release! Notably there has been an internal overhaul of how the standard library modules are created, and now allows for Dictu code to be ran - this will mean that parts of the standard library can (will) be written in Dictu! This is what is happening with the UnitTest library that will eventually make its way into Dictu's standard library.

For more information on Dictu see either of the below links.
Site: https://dictu-lang.com/
GitHub: https://github.com/dictu-lang/Dictu

Top comments (0)