Never edit the WP core files; things can easily get broken and will be overwritten with any updates.
With just a few lines of code we can get up and running with a child theme.
WordPress looks for files in the child theme folder first, anything it can't find, it defaults back to the parent theme.
Child themes are a safe option because if you break anything it can be undone or deleted without effecting functionality of the site.
/*
Theme Name: Your theme name here
Theme URI: url for the theme, if you have one
Description: A description for your theme.
Author: Your name here
Author URI: Your website here
Template: folder name of parent theme (can find this by looking at wp-content folder)
Version: version number, start with 1 then goes up with points, i.e.1.1
*/
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array('parent-style')
);
}
?>
A screen shot should be 880px by 660px and be named “screenshot.png”
Use your theme from last week or start fresh with one of the WordPress default themes, twentyfourteen, twentythirteen, etc.
Sometimes you might want to change other parts of a themes functionality, this can be done by copying the template files of the parent theme and overwriting in the child theme.
Modify the footer.php file and remove “Powered by WordPress”
<?php
/*
Template Name: *template name goes here*
*/
?>
<?php get_header(); ?>
<?php get_footer(); ?>
Side note: WP adds classes to your body tag; this can be used to style pages
Include tags execute the HTML & PHP found in another template
Functions defined for use in WordPress Themes
Copyright © <?php echo date('Y'); ?> <a href="<?php echo home_url( '/' ); ?>"><?php bloginfo( 'name' ); ?>
Displays content based on page and conditions it matches.
<?php
if(is_front_page()){
echo "
*This will only show up on the home page*
";
}
?>
<?php if (is_page() ) {?>

*this will only show up on pages, not posts*

<?php } ?>
Let's use some template tags to customize our themes even more.
Use at least one include tag, one function tag and one conditional tag
This is how WordPress determines which files to use on individual pages
Child themes can also be created via a plugin which can be handy if you don't have ftp access.
Let's install a child theme plugin to see the difference.
Starter themes are not meant to be used like parent themes. The developers have created these themes so you can hack them and make it your own.
Download a starter theme of your choice (doesn't have to be one of the 3 mentioned) and update the screenshot along with some CSS.
After clicking on a tag link, a user is taken to a page listing those posts. There are many different ways to display these posts, controlled by the tag templates.
Used to create a custom search page.
Similarly to tags, you may want to display categories differently.


--- layout: default body_class: about ---
Vowpal Wabbit is an open, fast, and efficient online learning system that empowers you to explore, test, and research solutions for a real world impact. Through online learning and community collaboration, you can apply real data sets for meaningful results.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.  Donec sit amet imperdiet felis. Vestibulum lorem justo, placerat ut placerat ut, pharetra eget lorem. Sed eu nisl vitae lacus molestie eleifend at accumsan ligula.
Vowpal Wabbit is structured around the principle of reducing problems to known solutions. When you can structure your problem as a class of problem that has been solved before then you can leverage existing technology. This is how you think about using VW to solve your problems, but it is also how VW works internally. Each reduction reduces to something that has been solved before and in this way we can reuse efficient algorithms that have stood the test of time.
With a flexible input format, feature hashing, sample efficient algorithms and collection of reductions VW is able to solve many real world problems.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sit amet imperdiet felis. Vestibulum lorem justo, placerat ut placerat ut, pharetra eget lorem. Sed eu nisl vitae lacus molestie eleifend at accumsan ligula.
{{ user.description }}
As an open technology hosted on GitHub, contributors to Vowpal Wabbit code and research sit all over the world.


We monetize cats!
- grow granular portals
- syndicate granular e-tailers
- synergize B2C supply-chains
- deploy killer e-services
- synthesize ubiquitous networks
- empower mission-critical convergence
- exploit frictionless mindshare
- disintermediate rich convergence
- strategize web-enabled bandwidth
- synergize holistic solutions
- maximize wireless e-business
- morph plug-and-play communities
- exploit turn-key initiatives


{{> topics}}
| # | Title | Poster | Location |
|---|---|---|---|
| {{rank}} | {{title}} | {{poster}} | {{#if location}} enabled! {{else}} anonymous {{/if}} |
| # | Title | Poster | Location |
|---|---|---|---|
| {{rank}} | {{title}} | {{poster}} | {{#if location}} enabled! {{else}} anonymous {{/if}} |
| # | Title | Poster | Location |
|---|---|---|---|
| {{rank}} | {{title}} | {{poster}} | {{#if location}} enabled! {{else}} anonymous {{/if}} |
| # | Title | Poster | Location |
|---|---|---|---|
| {{rank}} | {{title}} | {{poster}} | {{#if location}} enabled! {{else}} anonymous {{/if}} |
| Status | Topic | Number of posts | |
|---|---|---|---|
| {{{admin}}} | {{name}} | {{posts}} |
Preview:
Submitted by {{username}}Start typing to see a preview of your post
| # | Title | Poster | Location |
|---|---|---|---|
| {{rank}} | {{title}} | {{poster}} | {{#if location}} enabled! {{else}} anonymous {{/if}} |
{{post.post}}
There was a problem displaying the markdown{{this.reply}}
There was a problem displaying the markdown


---
layout: archive
title: Lean Prover Zulip Chat Archive
permalink: 116395maths/45571generalizingpadicval.html
---
The archive URL format has changed. Please find this page at:
https://leanprover-community.github.io/archive/stream/116395-maths/topic/generalizing.20padic_val.html


Here you will find samples of my work. Due to the confidentiality of the designs and software produced through my professional activity, these samples mainly consist of academic or independent projects. Please refer to my online resume for additional information until this section is populated.
Through my proficiency in both mechanical engineering and software, I have developed custom-designed simulations to model physical systems and estimate desired variables both as part of small teams, and on personal projects.
A few examples of my aerospace projects, including personal projects and my experience co-founding Washington University's AIAA Design/Build/Fly competion team.
3D design is the cornerstone of most of my projects and the main building block for FEA, CFD, and thermal analysis.
As a trained mechanical engineer, I have had the chance to use many of the tools currently used in industry to both design and fabricate my projects from the ground up.


Rachel is a very complicated character, but she can be described as an ESFP.  She cares about trends and her appearance in the minds of others, which leads her to be constantly aware of her surroundings. She works in the fashion industry so it’s only natural for her to act this way. Rachel thinks with her heart, which, like Ross, means that she easily gets hurt when it comes to relationships. She cares deeply for her friends and pays attention to their emotions. After Rachel leaves Barry at the altar, her life becomes extremely spontaneously and out of control because she has to learn how to survive without her dad’s money. She begins to gain some order when she achieves a steady job at Bloomingdales and then Ralph Lauren.
Rachel has a somewhat low conscientiousness because she is easily distracted and tends to leave things around or forget things. Monica specifically will not let her borrow anything because she knows that Rachel will lose it. Towards the end of the series, Rachel becomes more conscientious, however, when she gives birth to Emma and must become more organized and reliable in order to take care of her daughter.
Monica can be characterized as an ESTJ. She definitely draws her energy from others and her constant desire to control and manage her friends’ actions. Rachel even puts her in charge of her love life, which Monica happily takes on because of her personal belief that she knows more about Rachel than Rachel herself does. Details define everything for Monica, and this causes her to make most of her decisions with her head through logic and reason. As a head chef, she is very in control and detail-oriented. More than anything, Monica thrives on order and schedules; you will never see the apartment out of order or dirty while she is there.  Organizing projects comes very naturally to her, and you can bet that she will get the best results in the most efficient way, even if it means through force.
Monica is highly conscientiousness because she is incredibly organized and persistent. She will do whatever it takes to achieve top marks for anything she takes on. (Her competitive side definitely comes out during the Geller Family Thanksgiving Football Game.) You can always count on Monica to get the job done.
Phoebe is a great example of an ENFP. Phoebe is one of those people who could talk to anyone
about anything. She gets her energy through talking and singing about the abstract ideas and
theories she comes up with.  Like Chandler, she is very spontaneous in all aspects of her
lifestyle. While she doesn’t have a stable job or love life, it seems to work well for her because she’s
more interested in living impulsively than by an ordered routine.Phoebe has an incredibly high openness
to experience because her creativity and curiousness drive her actions and way of life. She’s interested
in adventure and trying new things even if they may be unusual. Her high openness to experience has helped
her overcome her homelessness, find her father and, eventually, find love and marriage with Mike.
In terms of his personality type Chandler can be described as an ENTP.  He always seems to have some unusual ideas brewing in his mind that stem from external factors and he likes to focus on what the future holds, choosing to avoid his past and family life. Chandler is smart (he works for a large corporation doing statistical analysis and data reconfiguration, whatever that is) so he tends to make decisions based on logic or reason. He is probably one of the most spontaneous characters out of the group because he seems to get bored with order and routine. He constantly jumps around with his relationships and jobs. His relationship with Janice is on and off throughout most of the seasons of the show.
He has relatively low emotional stability because of his mother’s and father’s occupations.  His parents have left him emotionally scarred and immature when it comes to developing his own relationships. (They told him they were getting divorced on Thanksgiving…) When nervous in social situations, Chandler turns to humor to avoid dealing with real emotions because he is so insecure.
Ross exemplifies an ISFJ. As the only introverted character, Ross is somewhat shy and keeps to himself- especially during his college years when interacting with Rachel, his secret crush. He is thorough and remembers specifics about certain individuals because he values loyalty. He tends to make decisions with his heart, which leads to emotional pain and heartache most of the time (just review his three failed marriages and his relationship rollercoaster with Rachel.) He likes to have an orderly and harmonious environment because of his dislike for conflict.
Thus, it is no surprise that Ross is highly agreeable, as demonstrated by his compassion, trust and generosity. He is very willing to compromise his own personal interests for those of others. In fact, Monica sometimes criticizes him for being their parents’ favorite child because he always tried to please them with his highly agreeable tendencies.
Joey can be described by his personality label of ENFP. He could not be a more extroverted individual. He constantly thrusts himself into new social situations because of his occupation as an actor. He is very comfortable with talking to others, even though what he says may not make any sense. This is probably due his tendency to prefer abstract and theoretical way of processing information. Emotions definitely drive Joey’s actions and he dislikes conflict, especially within his friend group. (Remember when he wrote a script for Chandler and Ross to read aloud to quell their fight concerning how to help Joey get his creative writing juices flowing?) Joey is the epitome of spontaneity. Simply put, there is no order in Joey’s life whatsoever.
Joey is highly extroverted because he thrives on human interaction, whether it’s on stage or in Central Perk.


Intro_userstats.Rmd
This function allows Twitter users to search the website by username, allowing the user to search multiple usernames at one time, specify which year they would like summary information for, specify the number of tweets they would like to analyze (with a maximum output allowed of 3,200 tweets), customize the background color of output tables, and customize the text color of the output with the assumption of knowledge of HTML color codes.
library(tweetstats)
userstats <- function(user, n=1000, bg_col = "white", txt_col = "#1A5276", year=2019, x=10){
if(!is.numeric(n))
stop("n must be numeric number no more than 3200", call. = FALSE)
if(n>3200)
stop("n should not exceed 3200", call. = FALSE)
user <- deparse(substitute(user))
n <- deparse(substitute(n))
year <- deparse(substitute(year))
x <- deparse(substitute(x))
# read in the template and modify it
report <- readLines("inst/userstatsTemplate.txt")
report <- gsub("xxxbg", bg_col, report, fixed = TRUE)
report <- gsub("xxxnum", n, report, fixed = TRUE)
report <- gsub("xxxusers", user, report, fixed = TRUE)
report <- gsub("xxxcol", txt_col, report, fixed = TRUE)
report <- gsub("xxxyr", year, report, fixed = TRUE)
report <- gsub("xxxtwt", x, report, fixed = TRUE)
# write out template
tf <- tempfile(fileext = ".Rmd")
to <- tempfile(fileext = ".Html")
writeLines(report, tf)
# render R markdown and display
library(rmarkdown)
render(input = tf,
output_format = "html_document",
output_file = to)
file.show(to)
invisible(to)
}


Your first connection to Lucidchart requires an Internet connection.
Please ensure you are connected to the Internet and click the button below.


TORCH SONG TRILOGY A film review by Jeff Meyer Copyright 1989 Jeff Meyer
When considering a film that centers on the life of an individual character over a period of time, the question is, do you find the character interesting enough to continue watching the picture through it's length? Despite a slow opener, the answer is a definite yes for Harvey Fierstein's character in TORCH SONG TRILOGY. The film adapts Fierstein's Broadway play, which details the life of his character from the early 1970s to the early 1980s, and his relationships with his family (in particular, his mother, played by Anne Bancroft) and his lovers (played by Brian Kerwin and Matthew Broderick). Fierstein by himself is witty and wry (and has the theatrical habit of talking to the audience), but once the supporting characters begin to share some screen time, the drama picks up and the film becomes very involving. The interaction of the characters (particularly Fierstein & Broderick and Fierstein & Bancroft) make the film, and you end up caring for them and the particular crosses they have to bear.
I note that many reviewers describe TORCH SONG TRILOGY as a film about "gay life," which is inappropriate; rather, it's a character study of a man who is gay. The film succeeds or fails on Fierstein's character; it deals with personalities, not issues, and it works because the personalities on-screen hold one's interest.
Moriarty, aka Jeff Meyer INTERNET<EMAIL_ADDRESS>Manual UUCP: {uw-beaver, sun, hplsla, thebes, microsoft}!fluke!moriarty
The review above was posted to the
rec.arts.movies.reviews newsgroup (de.rec.film.kritiken for German reviews).
The Internet Movie Database accepts no responsibility for the contents of the
review and has no editorial control. Unless stated otherwise, the copyright
belongs to the author.
Please direct comments/criticisms of the review to relevant newsgroups.
Broken URLs inthe reviews are the responsibility of the author.
The formatting of the review is likely to differ from the original due
to ASCII to HTML conversion.
Related links: index of all rec.arts.movies.reviews reviews


Reports: AC Milan offer Ibrahimovic six-month deal
MILAN, Nov 21 — Sweden star Zlatan Ibrahimovic has been offered a six-month deal to come to the aid of struggling former Italian giants AC Milan, according to reports in Italy today.
The 38-year-old striker confirmed his departure from Los Angeles Galaxy last week following the club’s elimination from the Major League Soccer playoffs.
Gazzetta dello Sport and Sky Sports Italia reported that the former seven-time European champions have now made contact with the player’s agent Mino Raiola.
The US-owned club want the former Swedish international for six months and are prepared to pay him €6 million (RM27.7 million) if he remains for 18 months in total, Gazzetta claimed.
Milan finished fifth last season, missing out on a return to Champions League football by just a point to city rivals Inter.
They have had a poor start to this campaign and are 14th after 12 games before they host last year’s runners-up Napoli on Saturday in the San Siro.
Ibrahimovic played for two seasons between 2010 and 2012 with AC Milan, helping them to their last Serie A title, and scoring 42 goals in 61 league appearances.
He also won three league titles with Inter Milan, and two with Juventus, which were both revoked following the ‘Calciopoli’ match-fixing scandal. — AFP


Hi, I'm Raghavprasanna Rajagopalan, and I'm a student at Northeastern University. I'm pursuing a combined major in Computer Science and Biology with a minor in Mathematics.
Worked on the Java Frameworks Team.
Worked on the Proven Program Team.
Major: Computer Science and Biology
Minor: Mathematics
Relevant Info and Coursework
Relevant Info and Coursework


--- layout: post title: "An applicative reservation validation example in C#" description: "How to return all relevant error messages in a composable way." date: 2022-07-25 6:56 UTC tags: [Functional Programming, Software Design] --- {% include JB/setup %}
{{ page.description }}
I've previously suggested that I consider validation a solved problem. I still do, until someone disproves me with a counterexample. Here's a fairly straightforward applicative validation example in C#.
After corresponding and speaking with readers of Code That Fits in Your Head I've learned that some readers have objections to the following lines of code:
Reservation? reservation = dto.Validate(id); if (reservation is null) return new BadRequestResult();
This code snippet demonstrates how to parse, not validate, an incoming Data Transfer Object (DTO). This code base uses C#'s nullable reference types feature to distinguish between null and non-null objects. Other languages (and earlier versions of C#) can instead use the Maybe monad. Nothing in this article or the book hinges on the nullable reference types feature.
If the Validate
method (which I really should have called TryParse
instead) returns a null value, the Controller from which this code snippet is taken returns a 400 Bad Request
response.
The Validate
method is an instance method on the DTO class:
internal Reservation? Validate(Guid id) { if (!DateTime.TryParse(At, out var d)) return null; if (Email is null) return null; if (Quantity < 1) return null; return new Reservation( id, d, new Email(Email), new Name(Name ?? ""), Quantity); }
What irks some readers is the loss of information. While Validate
'knows' why it's rejecting a candidate, that information is lost and no error message is communicated to unfortunate HTTP clients.
One email from a reader went on about this for quite some time and I got the impression that the sender considered this such a grave flaw that it invalidates the entire book.
That's not the case.
When I wrote the code like above, I was fully aware of trade-offs and priorities. I understood that this particular design would mean that clients get no information about why a particular reservation JSON document is rejected - only that it is.
This was a simplification that I explicitly decided to make for educational reasons.
The above design is based on something as simple as a null check. I expect all my readers to be able to follow that code. As hinted above, you could also model a method like Validate
with the Maybe monad, but while Maybe preserves success cases, it throws away all information about errors. In a production system, this is rarely acceptable, but I found it acceptable for the example code in the book, since this isn't the main topic.
Instead of basing the design on nullable reference types or the Maybe monad, you can instead base parsing on applicative validation. In order to explain that, I'd first need to explain functors, applicative functors, and applicative validation. It might also prove helpful to the reader to explain Church encodings, bifunctors, and semigroups. That's quite a rabbit hole to fall into, and I felt that it would be such a big digression from the themes of the book that I decided not to go there.
On this blog, however, I have all the space and time I'd like. I can digress as much as I'd like. Most of that digression has already happened. Those articles are already on the blog. I'm going to assume that you've read all of the articles I just linked, or that you understand these concepts.
In this article, I'm going to rewrite the DTO parser to also return error messages. It's an entirely local change that breaks no existing tests.
Most functional programmers are already aware of the Either monad. They often reach for it when they need to expand the Maybe monad with an error track.
The problem with the Either monad is, however, that it short-circuits error handling. It's like throwing exceptions. As soon as an Either composition hits the first error, it stops processing the rest of the data. As a caller, you only get one error message, even if there's more than one thing wrong with your input value.
In a distributed system where a client posts a document to a service, you'd like to respond with a collection of errors.
You can do this with a data type that's isomorphic with Either, but behaves differently as an applicative functor. Instead of short-circuiting on the first error, it collects them. This, however, turns out to be incompatible to the Either monad's short-circuiting behaviour, so this data structure is usually not given monadic features.
This data type is usually called Validation
, but when I translated that to C# various static code analysis rules lit up, claiming that there was already a referenced namespace called Validation
. Instead, I decided to call the type Validated<F, S>
, which I like better anyway.
The type arguments are F
for failure and S
for success. I've put F
before S
because by convention that's how Either works.
I'm using an encapsulated variation of a Church encoding and a series of Apply
overloads as described in the article An applicative password list. There's quite a bit of boilerplate, so I'll just dump the entire contents of the file here instead of tiring you with a detailed walk-through:
public sealed class Validated<F, S> { private interface IValidation { T Match<T>(Func<F, T> onFailure, Func<S, T> onSuccess); } private readonly IValidation imp; private Validated(IValidation imp) { this.imp = imp; } internal static Validated<F, S> Succeed(S success) { return new Validated<F, S>(new Success(success)); } internal static Validated<F, S> Fail(F failure) { return new Validated<F, S>(new Failure(failure)); } public T Match<T>(Func<F, T> onFailure, Func<S, T> onSuccess) { return imp.Match(onFailure, onSuccess); } public Validated<F1, S1> SelectBoth<F1, S1>( Func<F, F1> selectFailure, Func<S, S1> selectSuccess) { return Match( f => Validated.Fail<F1, S1>(selectFailure(f)), s => Validated.Succeed<F1, S1>(selectSuccess(s))); } public Validated<F1, S> SelectFailure<F1>( Func<F, F1> selectFailure) { return SelectBoth(selectFailure, s => s); } public Validated<F, S1> SelectSuccess<S1>( Func<S, S1> selectSuccess) { return SelectBoth(f => f, selectSuccess); } public Validated<F, S1> Select<S1>( Func<S, S1> selector) { return SelectSuccess(selector); } private sealed class Success : IValidation { private readonly S success; public Success(S success) { this.success = success; } public T Match<T>( Func<F, T> onFailure, Func<S, T> onSuccess) { return onSuccess(success); } } private sealed class Failure : IValidation { private readonly F failure; public Failure(F failure) { this.failure = failure; } public T Match<T>( Func<F, T> onFailure, Func<S, T> onSuccess) { return onFailure(failure); } } } public static class Validated { public static Validated<F, S> Succeed<F, S>( S success) { return Validated<F, S>.Succeed(success); } public static Validated<F, S> Fail<F, S>( F failure) { return Validated<F, S>.Fail(failure); } public static Validated<F, S> Apply<F, T, S>( this Validated<F, Func<T, S>> selector, Validated<F, T> source, Func<F, F, F> combine) { if (selector is null) throw new ArgumentNullException(nameof(selector)); return selector.Match( f1 => source.Match( f2 => Fail<F, S>(combine(f1, f2)), _ => Fail<F, S>(f1)), map => source.Match( f2 => Fail<F, S>(f2), x => Succeed<F, S>(map(x)))); } public static Validated<F, Func<T2, S>> Apply<F, T1, T2, S>( this Validated<F, Func<T1, T2, S>> selector, Validated<F, T1> source, Func<F, F, F> combine) { if (selector is null) throw new ArgumentNullException(nameof(selector)); return selector.Match( f1 => source.Match( f2 => Fail<F, Func<T2, S>>(combine(f1, f2)), _ => Fail<F, Func<T2, S>>(f1)), map => source.Match( f2 => Fail<F, Func<T2, S>>(f2), x => Succeed<F, Func<T2, S>>(y => map(x, y)))); } public static Validated<F, Func<T2, T3, S>> Apply<F, T1, T2, T3, S>( this Validated<F, Func<T1, T2, T3, S>> selector, Validated<F, T1> source, Func<F, F, F> combine) { if (selector is null) throw new ArgumentNullException(nameof(selector)); return selector.Match( f1 => source.Match( f2 => Fail<F, Func<T2, T3, S>>(combine(f1, f2)), _ => Fail<F, Func<T2, T3, S>>(f1)), map => source.Match( f2 => Fail<F, Func<T2, T3, S>>(f2), x => Succeed<F, Func<T2, T3, S>>((y, z) => map(x, y, z)))); } public static Validated<F, Func<T2, T3, S>> Apply<F, T1, T2, T3, S>( this Func<T1, T2, T3, S> map, Validated<F, T1> source, Func<F, F, F> combine) { return Apply( Succeed<F, Func<T1, T2, T3, S>>((x, y, z) => map(x, y, z)), source, combine); } }
I only added the Apply
overloads that I needed for the following demo code. As stated above, I'm not going to launch into a detailed walk-through, since the code follows the concepts lined out in the various articles I've already mentioned. If there's something that you'd like me to explain then please leave a comment.
Notice that Validated<F, S>
has no SelectMany
method. It's deliberately not a monad, because monadic bind (SelectMany
) would conflict with the applicative functor implementation.
An essential quality of applicative validation is that it's composable. This means that you can compose a larger, more complex parser from smaller ones. Parsing a ReservationDto
object, for example, involves parsing the date and time of the reservation, the email address, and the quantity. Here's how to parse the date and time:
private Validated<string, DateTime> TryParseAt() { if (!DateTime.TryParse(At, out var d)) return Validated.Fail<string, DateTime>($"Invalid date or time: {At}."); return Validated.Succeed<string, DateTime>(d); }
In order to keep things simple I'm going to use strings for error messages. You could instead decide to encode error conditions as a sum type or other polymorphic type. This would be appropriate if you also need to be able to make programmatic decisions based on individual error conditions, or if you need to translate the error messages to more than one language.
The TryParseAt
function only attempts to parse the At
property to a DateTime
value. If parsing fails, it returns a Failure
value with a helpful error message; otherwise, it wraps the parsed date and time in a Success
value.
Parsing the email address is similar:
private Validated<string, Email> TryParseEmail() { if (Email is null) return Validated.Fail<string, Email>($"Email address is missing."); return Validated.Succeed<string, Email>(new Email(Email)); }
As is parsing the quantity:
private Validated<string, int> TryParseQuantity() { if (Quantity < 1) return Validated.Fail<string, int>( $"Quantity must be a positive integer, but was: {Quantity}."); return Validated.Succeed<string, int>(Quantity); }
There's no reason to create a parser for the reservation name, because if the name doesn't exist, instead use the empty string. That operation can't fail.
You can now use applicative composition to reuse those individual parsers in a more complex parser:
internal Validated<string, Reservation> TryParse(Guid id) { Func<DateTime, Email, int, Reservation> createReservation = (at, email, quantity) => new Reservation(id, at, email, new Name(Name ?? ""), quantity); Func<string, string, string> combine = (x, y) => string.Join(Environment.NewLine, x, y); return createReservation .Apply(TryParseAt(), combine) .Apply(TryParseEmail(), combine) .Apply(TryParseQuantity(), combine); }
createReservation
is a local function that closes over id
and Name
. Specifically, it uses the null coalescing operator (??
) to turn a null name into the empty string. On the other hand, it takes at
, email
, and quantity
as inputs, since these are the values that must first be parsed.
A type like Validated<F, S>
is only an applicative functor when the failure dimension (F
) gives rise to a semigroup. The way I've modelled it here is as a binary operation that you need to pass as a parameter to each Apply
overload. This seems awkward, but is good enough for a proof of concept.
The combine
function joins two strings together, separated by a line break.
The TryParse
function composes createReservation
with TryParseAt
, TryParseEmail
, and TryParseQuantity
using the various Apply
overloads. The combination is a Validated
value that's either a failure string or a properly encapsulated Reservation
object.
Client code can now invoke the TryParse
function on the DTO. Here is the code inside the Post
method on the ReservationsController
class:
[HttpPost("restaurants/{restaurantId}/reservations")] public Task<ActionResult> Post(int restaurantId, ReservationDto dto) { if (dto is null) throw new ArgumentNullException(nameof(dto)); var id = dto.ParseId() ?? Guid.NewGuid(); var parseResult = dto.TryParse(id); return parseResult.Match( msgs => Task.FromResult<ActionResult>(new BadRequestObjectResult(msgs)), reservation => TryCreate(restaurantId, reservation)); }
When the parseResult
matches a failure, it returns a new BadRequestObjectResult
with all collected error messages. When, on the other hand, it matches a success, it invokes the TryCreate
helper method with the parsed reservation
.
A client will now receive all relevant error messages if it posts a malformed reservation:
POST /restaurants/1/reservations?sig=1WiLlS5705bfsffPzaFYLwntrS4FCjE5CLdaeYTHxxg%3D HTTP/1.1 Content-Type: application/json { "at": "large", "name": "Kerry Onn", "quantity": -1 } HTTP/1.1 400 Bad Request Invalid date or time: large. Email address is missing. Quantity must be a positive integer, but was: -1.
Of course, if only a single element is wrong, only that error message will appear.
The changes described in this article were entirely local to the two involved types: ReservationsController
and ReservationDto
. Once I'd expanded ReservationDto
with the TryParse
function and its helper functions, and changed ReservationsController
accordingly, the rest of the code base compiled and all tests passed. The point is that this isn't a big change, and that's why I believe that the original design (returning null or non-null) doesn't invalidate anything else I had to say in the book.
The change did, however, take quite a bit of boilerplate code, as witnessed by the Validated
code dump. That API is, on the other hand, completely reusable, and you can find packages on the internet that already implement this functionality. It's not much of a burden in terms of extra code, but it would have taken a couple of extra chapters to explain in the book. It could easily have been double the size if I had to include material about functors, applicative functors, semigroups, Church encoding, etcetera.
To fix two lines of code, I didn't think that was warranted. After all, it's not a major blocker. On the contrary, validation is a solved problem.


A design element idea for a textual element on a site which is connected to a live data feed and continuously refreshes itself.
The reloading is indicated by a stripe shifting across the text similar to how an indeterminate progress indicator element might appear:
Here's an example where you can control whether the element appears to be reloading or not:
A live value
In this next example, the element displays the current time as if it was coming from the server and updated sporadically. It updates for between one and two seconds and then stays still for between one and five seconds and this process repeats infinitely.
Loading…


1.seattle
- location:Washington (state)
- hours open: 6am-8pm
- contact information
2.tokyo
- location:Japan
- hours open: 6am-8pm
- contact information
3.dubai
- location:United Arab Emirates
- hours open: 6am-8pm
- contact information
4.paris
- location:France
- hours open: 6am-8pm
- contact information
5.lima
- location:Peru
- hours open: 6am-8pm
- contact information


Buttons 'Step Into', 'Step Over', 'Step Out', 'One Instr', 'Continue'
Use these buttons in the debug mode to execute pieces of code. All these buttons change all four output windows.
Check Box
If it is checked all functions will be executed natively. Breakpoints will not work. Use it to step over the timely functions.
Exceptions field
Number of exceptions to be captured by the catch blocks. Set it to 0 if you want to supress the catch blocks.
Text area
You may enter some code in it. Note that its capacity is limited.
Exec button
Executes 'Text Area' (selected) content in the debugged process. Output is printed to Output window. Use it to evaluate simple Q expressions.
Run button
Runs 'Text Area' (selected) content in the debug mode. It will stop on exceptions, breakpoints or return the result. See Output window for the result of the operation.
Prepare button
Uses 'Text Area' (selected) content to initialize the debugger. You may then use the debug buttons.
Show Fn button
Enter an expression that evaluates to the user function into 'Text Area' or select it and press this button. It will print this function to Code window. You then may add/remove breakpoints to/from this function.
Show Bps button
Prints all breakpoints to Output window.
Clear Bps button
Removes all breakpoints.
Refresh buttton
Reloads the default content of all windows. Use it restore the current debug status.
Help and About buttons
Prints help and about messages.
Stack window
Contains the current debug status, information about the current function and the top stack entries. You may double click on the function stack entry, the function body will be printed to Code window and its parameters and local variables to Variables window.
Variables window
Parameters and local variables of the current function are printed in this window. Changed vars are marked.
Code window
Function bodies are printed in this window. Different background is used for breakpoints and the current line. You may click on some value and it will be printed in Output window (qparse.q required). You may double click on some line to add/remove a breakpoint.
Output window
The result of all operations is printed in this window. If it contains breakpoints you may click on them to see the underlying function and add/remove them. Otherwise you may click on some variable to see its value after most operations.
Click to close