Re: construct range from tuple?

2016-09-18 Thread Lutger via Digitalmars-d-learn

On Sunday, 18 September 2016 at 09:36:13 UTC, e-y-e wrote:

On Sunday, 18 September 2016 at 08:06:54 UTC, Lutger wrote:

[...]


Use std.range's 'only' function [1], it takes variadic 
arguments of the same type and constructs a range consisting of 
them.


Example:

import std.meta : AliasSeq;
import std.range : only;
import std.algorithm.comparison : equal;

alias names = AliasSeq!("Alice", "Bob");

auto range = only(names, "Chuck");
assert(range.equal(["Alice", "Bob", "Chuck"]));


That's *exactly* what I was looking for, thanx!


Re: Can vibe d leverage existing web technologies?

2016-09-18 Thread Lutger via Digitalmars-d-learn
On Thursday, 15 September 2016 at 20:56:19 UTC, Intersteller 
wrote:
On Thursday, 15 September 2016 at 14:31:28 UTC, Martin 
Tschierschke wrote:
On Tuesday, 13 September 2016 at 23:45:18 UTC, Intersteller 
wrote:
vibe.d does not have much lateral support as the most commons 
web technologies do.  Can vibe.d leverage pre-existing techs 
such as php, ruby/rails, etc? Starting from scratch and 
having to build a robust and secure framework is really not 
the way to go.


A good way to mix different technologies is to use a Apache or 
nginx proxy on the same server, so you can start using vibe.d 
for some parts and keep the rest at its place.


Regards mt.


How is this done? How can it be done smoothly? I'm not sure how 
to partition the work load. While, say, some pages might be 
served from php, and others from vibe2, etc, it seems like it 
would be nightmare to maintain consistency and interactivity.


True. It is easier to maintain if you do a 'vertical split'. So 
each subsystem maintains a strict boundary. You have to be clear 
about the dependencies between subsystems and any data exchange 
should happen via an explicit api. So there is no shared database 
between the D part and the php part for example. Communication 
with json over http is common and well supported by vibe.d. See: 
http://martinfowler.com/articles/microservices.html


This a more coarse grained approach which reduces coupling 
between the different parts.


For example, you could write a small api with vibe.d which does 
image processing, or collects and manipulates data from third 
party apis, or whatever. The rails app handles authentication and 
ui, making use of the services that your vibe.d api provides.


Another example: if you have a reasonably standalone part of a 
webapplication such as administrative pages or whatever, you 
could program that in vibe.d and let an nginx server route 
everything /admin/* to that part. The rails app exposes an api to 
modify its data which the admin app build in vibe.d makes use of.


construct range from tuple?

2016-09-18 Thread Lutger via Digitalmars-d-learn

I have a tuple of strings generated at compile time, for example:

  alias names = AliasSeq!("Alice", "Bob");

How is it possible to construct a range of strings from this, in 
order to use it at runtime with other range algorithms?


For example, this

  chain(names, ["Chuck"])

doesn't work as intended because it expands to

  chain("Alice", "Bob", ["Chuck"])

I want some function makeRange that works like this:

assert(chain(makeRange(names), ["Chuck"]).fold!( (x,y) => x ~ " " 
~ y) ==

   "Alice Bob Chuck");

What would be a good way to do that?







Equivalent of FirstOrDefault with ranges

2016-09-02 Thread Lutger via Digitalmars-d-learn
I was looking for something like FirstOrDefault* from .NET in 
phobos. For example, I have this piece of code:


string findBobOrReturnNull(string[] names)
{
auto r = names.find("bob");
if(r.empty) return null;
return r.front;
}

assert(findBobOrReturnNull(["alice", "bob"]) == "bob");
assert(findBobOrReturnNull(["alice"]) is null);

How can I turn that into something like this, or is there another 
idiomatic way to write it as a single expression?


string findBobOrReturnNull(string[] names)
{
return names.find("bob").firstOrDefault;
}

* 
https://msdn.microsoft.com/en-us/library/bb340482%28v=vs.110%29.aspx