Skip to content

Instantly share code, notes, and snippets.

View hesher's full-sized avatar

Ben Katz hesher

  • Facebook
  • Israel
View GitHub Profile
// Helper Functions
const wrapWith = wrapper => obj => key => val => wrapper({...obj, [key]: val});
const wrapWithSiteBuilder = wrapWith(SiteBuilder);
// Expression Builder
function SiteBuilder(value) {
const siteBuilderWrapper = wrapWithSiteBuilder(value);
return {
withSiteName: siteBuilderWrapper('name'),
withDomain: siteBuilderWrapper('domain'),
const SiteBuilder = value => ({
withSiteName: name => SiteBuilder({...value, ...{name}}),
withDomain: domain => SiteBuilder({...value, ...{domain}}),
build: () => value
});
const site = SiteBuilder({})
.withSiteName('hello')
.withDomain('some-domain')
.build();
const withSecurityEnabled = set(lensPath([‘services’, ‘securityEnabled’]))
const withSiteName = set(lensProp('name'));
const withDomain = set(lensProp('domain'));
const site = pipe(withSiteName('a Site'), withDomain('domain'));
site({}); // site is the function that returns the value
class SiteBuilder {
private site: any;
withSiteName(name: string) {
this.site.name = name;
return this;
}
withDomain(domain: string) {
this.site.domain = domain;
return this;
const theSite = new SiteBuilder()
.withSiteName('a Site')
.withDomain('www.some-domain.com')
.build();
@hesher
hesher / expect.js
Last active June 7, 2017 06:25
Fluent Code Samples
expect(someValue).to.equal(expectedValue)