"Mr Branding" is a blog based on RSS for everything related to website branding and website design, it collects its posts from many sites in order to facilitate the updating to the latest technology.
To suggest any source, please contact me: Taha.baba@consultant.com
Wednesday, June 7, 2017
Functional Programming with Phunkie: Building a PHP JSON Parser
Phunkie is a library with functional structures for PHP. In this two-part tutorial, Phunkie’s creator Marcello Duarte, head of training at Inviqa, explains how to create Parser combinators using the functional library. This post first appeared on the Inviqa blog, and was republished here with their permission. For an exploration of PHP's "non-exotic" features, we have great paid course.
In the first part of this series we explored parsers and combinators to help you start getting values from functional programming with PHP. We covered the basics using examples, and now we’ll move onto more sequencing and other strategies.
Let’s pick up where we left off!
Sequencing Combinators
Ok, let’s now try a more useful parser. A parser that, given a predicate, keeps the character if it satisfies the predicate and fails otherwise. We will call this parser sat
, from satisfies.
describe("sat", function() {
it("parses one character when it satisfies the predicate", function(){
expect(sat("is_numeric")->run("4L"))->toEqual(ImmList(Pair('4', 'L')));
});
it("returns Nil when the character does not satisfy the predicate", function(){
expect(sat("is_numeric")->run("L4"))->toEqual(Nil());
});
});
The implementation, using the primitive parsers item
, result
and zero
, looks like this:
function sat(callable $predicate): Parser
{
return item()->flatMap(function($x) use ($predicate) {
return $predicate($x) ? result($x) : zero();
});
}
You can see how the building blocks are now put to work. We call the item
parser, flatMap
on its result, and apply the predicate. If the predicate succeeds, we return the result
parser, which basically lifts the $x
into the parser context. Otherwise, zero
will just do the same, but with Nil
instead of any result.
We can quickly capitalize on sat
, by creating a few other sequencing combinators.
context("Sequencing combinators", function() {
describe("char", function() {
it("parses a character", function() {
expect(char('h')->run("hello"))->toEqual(ImmList(Pair('h', "ello")));
});
});
describe("digit", function() {
it("parses a digit", function() {
expect(digit()->run("42"))->toEqual(ImmList(Pair('4', '2')));
});
});
describe("lower", function() {
it("parses a lowercase character", function() {
expect(lower()->run("hello"))->toEqual(ImmList(Pair('h', "ello")));
});
});
describe("upper", function() {
it("parses an upper case character", function() {
expect(upper()->run("Hello"))->toEqual(ImmList(Pair('H', "ello")));
});
});
});
You will laugh at how simple the implementation is!
function char($c): Parser
{
return sat(function($input) use ($c) { return $input === $c; });
}
function digit(): Parser
{
return sat('is_numeric');
}
function lower(): Parser
{
return sat(function($c) { return ctype_lower($c); });
}
function upper(): Parser
{
return sat(function($c) { return ctype_upper($c); });
}
Choice Combinators
In the real world of grammars, if we had to return an empty list as soon as the first parser failed, we would not survive. Parsers have to deal with grammatical choice constructs. A very common scenario is either matching one pattern or another pattern. We do that by adding the plus
combinator to our arsenal of parsers.
Continue reading %Functional Programming with Phunkie: Building a PHP JSON Parser%
by Marcello Duarte via SitePoint
Nova
by Rob Hope via One Page Love
Awesomed
by Rob Hope via One Page Love
Tom Street
by Rob Hope via One Page Love
8 Fresh Design Tools and Resources for Your 2017 Toolbox
This is a hammer. To be more precise, it’s a vintage Estwing Claw Hammer from the late 1960’s. It’s a beautifully-crafted, sturdy piece of workmanship, but also not very different to the hammers Estwing produce to this day. Hammers – and the way they’re used – haven’t changed a lot in 50 years. However, the web design tools and resources that we use, are different.
Look at the tools that you use today and compare them to what you were using 5 years ago. In 2012 you probably used PNGs for icons. Photoshop was ubiquitous. Sketch was a fringe design app and SVG was a weird Inkscape format. Things have changed and that will likely continue. Chances are, your next tool is already out there.
So, what design tools and resources will be in your 2017 toolbox?
That’s what we’re here to help you with today. I’ve questioned, interrogated, poked and prodded every designer and developer I know for the tools they’ve been using lately. Here is the short-list I came up with. There are apps, extensions, online tools and more, check them out and let us know if they fit your workflow!
Illusion.ai
With the emerging trend of conversational UI in 2017, the San Francisco team behind Illusion.ai sets out to create a service that allows you design and apply conversational interfaces into both your web and mobile sites. The idea is to help engage your visitors and customers in conversation about your product or service. With a variety of templates in the collection, you’re able to create a highly customizable experience and interface.
Website: https://illusion.ai/
Category: UI Design
Price: Free (Currently in Alpha)
Bottom Line: Illusion.ai makes customizable and engaging conversational interfaces not only easy to create but also to embed into your sites.
Web Developer Checklist
The Web Developer Checklist is an extension for Chrome instead of a web app. The extension is specifically designed for web developers as it allows them to check their web pages for any errors or violations of common practices.
While the checklist is already impressively extensive, there are plans to include Rails and Python checkers in future. For now, the extension lets developers scout out any potential problems with their site and rectify the issues.
Website: http://ift.tt/Vywq0R
Category: Utilities
Price: Free
Bottom Line: A comprehensive checklist for web developers to catch potential issues in real-time.
Freebiesbug
Created by Pasquale Vitiello, Freebiesbug is a web design blog that styles itself as a one-stop-shop for web and graphic designers who are on the hunt for the latest free resources. Featuring only the best quality, Freebiesbug’s goal is to let designers create with ease and speed by offering a host of resources that are all free including PSD, Illustrator and Sketch files along with fonts, code, and stock photography.
Website: https://freebiesbug.com
Category: Resources
Price: Free
Bottom Line: Freebiesbug is a free curated collection of high quality resources for designers and developers.
Hype 3
Tumult’s Hype 3 is a Mac exclusive tool that was created by two former Apple engineers with the sole purpose of helping you create and animate interactive HTML5 content for your sites. Along with Hype Reflect and HyperEdit, Mac users are able to work with responsive layouts to design everything from e-cards to infographics and animated site elements all without learning code.
Website: http://tumult.com/hype/
Category: Design
Price: Free 14 Day Trial or $49.99 USD
Bottom Line: Tumult’s Hype allows Mac web and graphic designers to create HTML5 content without knowing code.
Continue reading %8 Fresh Design Tools and Resources for Your 2017 Toolbox%
by Gabrielle Gosha via SitePoint
#293: The State of CSS: 5 Things You Don't Need Anymore?
|
by via FrontEnd Focus