Code Monkey home page Code Monkey logo

ddash's People

Contributors

aliak00 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ddash's Issues

functional.cond: cannt access frame of function

Hi, I have been using your library for a while, especially the cond function that is quite handy.
I have been blocked by this error many times already
I have a struct like with some private members and a function resolve, that contains a nested function parseUrl that uses the cond template:

    this(const string content, const string root) @safe
    {
        assert(root.endsWith("/"), root);
        m_content = content;
        m_rooturl = root[0 .. $-1];
    }

    Event[] resolve()
    {
        mixin(scopeInvariant);

        Tuple!(string, string) parseUrl(const string url){
            string src, dst;
            src = url.cond!(
                u => u.startsWith("/"),  {return m_rooturl ~ url;},                     // same error if  u=> m_rooturl ~ u                                                                             
                u => u
    	);

            return tuple!(src, dst);
        }
    // rest of the function

I get:

/home/user/.dub/packages/ddash-0.0.6/ddash/functional/source/ddash/functional/cond.d(99,25): Error: static function app.ParseEvent.resolve.parseUrl.resolve!(delegate () => this.m_rooturl ~ url).resolve!string.resolve cannot access frame of function app.ParseEvent.resolve.parseUrl
/home/user/.dub/packages/ddash-0.0.6/ddash/functional/source/ddash/functional/cond.d(119,55): Error: template instance `app.ParseEvent.resolve.parseUrl.resolve!(delegate () => this.m_rooturl ~ url).resolve!string` error instantiating
/home/user/git_mio/scarpa/source/app.d(89,22):        instantiated from here: cond!string
/opt/dmd-2.081/import/std/typecons.d(2003,13): Error: static assert:  "Insufficient number of names given."
/home/user/git_mio/scarpa/source/app.d(101,20):        instantiated from here: tuple!()
/usr/bin/dmd failed with exit code 1.

This is a more compact test that should avoid that scenario:

unittest {
    import std.string;
    struct S{
        string a;
        this(string src){
            a = src;
        }

        void f(){
            auto res = "string".cond!(
                (s) => (s == a), a.startsWith("s"),
                false);                                                                          
    	    assert(res);
        }
    }
    S s = S("string");
    s.f();
}

Add destructoring

"Destructuring" is a visually concise way of extracting fields from a data structure.
https://reasonml.github.io/docs/en/destructuring.html

There are already utilities libraries that add destructuring (let/tie):
https://github.com/valmat/vest#tie
https://github.com/SirTony/dext/blob/master/src/dext/let.d

But I think there would be value in having a @safe-capable destructoring template in ddash given that ddash is a bigger utility library than the other two and that there situations in which you want to be conservative with dependecies.

I see that ddash already has destructInto but it does not support:

  • associative arrays
  • tuples (at least as I understand from the example)
  • POD

algorithm.equal - aliases don't allow generation of proper docs

The params section of the ddoc can't be used because the aliases to the implementation of equal in the common sub package don't have any params.

Look in to how to make them have parameters. Initial conversion to actual functions resulted in a number of compiler errors.

  • The common subpackage has publicly importable equal function
  • With version(unittest) the equal is publicly imported with import ddash.common

add pattern match function

It would be nice to see abstract the match function in the functional.try_ to be a more generic match function to work on every type or even do full blown pattern matching.

try_ : cannot use local __lambda5 as parameter to non-global template match

I have the following function:

Event requestUrl(const string url, const string projdir) 
{
    import requests;
    import std.utf : UTFException;

    auto rawdata = () @trusted { return getContent(url).data; } ();

    Event ev = try_!(assumeUTF)(rawdata)
        .match!(
            (string content) => ParseEvent(content, url, projdir),
            (UTFException e) => ToFileEvent(rawdata, url, projdir));                             
    return ev;
}

and I get:

/home/user/git_mio/scarpa/source/parse.d(66,9): Error: template instance `match!(delegate (string content) => ParseEvent(null, null, null, false).this(content, url, projdir), delegate (UTFException e) => ToFileEvent(null, null, null, false).this(rawdata, url, projdir))` cannot use local __lambda4 as parameter to non-global template match(handlers...)()
/home/user/git_mio/scarpa/source/parse.d(66,9): Error: template instance `match!(delegate (string content) => ParseEvent(null, null, null, false).this(content, url, projdir), delegate (UTFException e) => ToFileEvent(null, null, null, false).this(rawdata, url, projdir))` cannot use local __lambda5 as parameter to non-global template match(handlers...)()

I know that this is mainly because more than one context when passing a lambda, but I wonder if a workaround is possible. That would greatly increase the usefulness of try_

Make variantArray generic

T[] arrayOf(T, Args...)(auto ref Args args) if (allArgsAppendableToArrayOfT) {...}
auto arr = arrayOf!Variant(3, "hello, obj);

Typo in function name

I noticed there’s a function named stringifySeperatedBy. Methinks separate has two A’s

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.