Dictu 0.22.0!
Tags: showdev, computerscience, programming, opensource
Published: 2021-10-25 18:53:01

## 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.](https://dev.to/jason2605/dictu-a-simple-programming-language-5674)

### 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

```js
const myList = [1, 2, 3, 4, 5];
print(myList.findIndex(def (item) => item == 4)); // 3
```

#### 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).

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

print(DaysOfTheWeek.Monday); // 0
print(DaysOfTheWeek.Saturday); // 6
```

#### 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.

```js
class Test {
    myMethod() {
    
    }

    private myPrivateMethod() {

    }
}

print(Test().methods()); // ["myMethod"]
```

#### 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.

```js
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}
```

#### 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.

```js
import Env;

print(Env.get("this really doesn't exist", "default")); // default
```

#### 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.](https://dictu-lang.com/docs/error-handling/)

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

print(response); // <Result Suc>
```

### 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