All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.basking2.sdsai.itrex.packages.DictPackage Maven / Gradle / Ivy

There is a newer version: 1.1.23
Show newest version
package com.github.basking2.sdsai.itrex.packages;

import com.github.basking2.sdsai.itrex.functions.DictFunction;
import com.github.basking2.sdsai.itrex.functions.FunctionInterface;

import java.util.Map;

public class DictPackage {

    public static final String __package = "dict";

    public static final FunctionInterface> mk = new DictFunction();
    public static final FunctionInterface get = (args, ctx) -> {
        @SuppressWarnings("unchecked")
        final Map m = (Map)args.next();

        final Object key = args.next();

        if (m.containsKey(key)) {
            return m.get(key);
        }
        else if (args.hasNext()) {
            return args.next();
        }
        else {
            return null;
        }
    };
    public static final FunctionInterface> put = (args, ctx) -> {
        @SuppressWarnings("unchecked")
        final Map m = (Map)args.next();
        final Object key = args.next();
        final Object val = args.next();
        m.put(key, val);
        return m;
    };
}