aliak00 / ddash Goto Github PK
View Code? Open in Web Editor NEWLodash like utility library for D
License: MIT License
Lodash like utility library for D
License: MIT License
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();
}
"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:
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.
version(unittest)
the equal is publicly imported with import ddash.common
void f(Flag.blah = false) {}
Does not work. You have to do:
void f(Flag.blah = Flag.blah(false)) {}
Which is redundant.
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.
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_
T[] arrayOf(T, Args...)(auto ref Args args) if (allArgsAppendableToArrayOfT) {...}
auto arr = arrayOf!Variant(3, "hello, obj);
I noticed there’s a function named stringifySeperatedBy
. Methinks separate has two A’s
tryCall(
call1(),
call2(),
call3(),
).match!(
(Result1 r1, Result2, r2, Result3 r3) {},
(Exception[] exceptions) {},
);
Or something
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.