Skip to content

Instantly share code, notes, and snippets.

Nicolas Carlo nicoespeon

Block or report user

Report or block nicoespeon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nicoespeon
nicoespeon / lead-time-lodash-refactored.js
Last active Apr 14, 2016
Blog - Achieving point-free JavaScript - lodash refactored
View lead-time-lodash-refactored.js
import {pipe, pluck, over, head, last, spread} from 'lodash/fp';
import {daysSpent} from './utils/dates';
// leadTime : [{date: Date}] -> Number
const leadTime = pipe(
pluck( 'date' ), // first convert input into [Date]
over( [ head, last ] ), // then turns them to our arguments array [ FirstDate, LastDate ]
spread( daysSpent ) // finally spread arguments to the function
);
@nicoespeon
nicoespeon / lead-time-ramda-refactored.js
Last active Apr 12, 2016
Blog - Achieving point-free JavaScript - ramda refactored
View lead-time-ramda-refactored.js
import {pipe, pluck, converge, head, last} from 'ramda';
import {daysSpent} from './utils/dates';
// leadTime : [{date: Date}] -> Number
const leadTime = pipe(
pluck('date'), // first convert input into [Date]
converge( daysSpent, [ head, last ] ) // then pick proper ones for calculation
);
@nicoespeon
nicoespeon / lead-time-ramda.js
Last active Apr 12, 2016
Blog - Achieving point-free JavaScript - ramda
View lead-time-ramda.js
import {converge, pipe, prop, head, last} from 'ramda';
import {daysSpent} from './utils/dates';
// leadTime : [{date: Date}] -> Number
const leadTime = converge(
daysSpent,
[ pipe( head, prop('date') ), pipe( last, prop('date') ) ]
);
@nicoespeon
nicoespeon / achieving-point-free.js
Created Apr 11, 2016
Blog - Achieving point-free JavaScript - achieving point-free
View achieving-point-free.js
// What I ended up with
const getX = ( input ) => getY( parseA( input ), parseB( input ) );
// What I was trying to achieve, some sort of:
const getX = anyFunction( getY( parseA, parseB ) );
@nicoespeon
nicoespeon / lead-time-naive.js
Last active Apr 12, 2016
Blog - Achieving point-free JavaScript - naive solution
View lead-time-naive.js
import {pipe, prop, head, last} from 'ramda';
import {daysSpent} from './utils/dates';
// leadTime : [{date: Date}] -> Number
const leadTime = (items) => daysSpent(
pipe( head, prop('date') )(items),
pipe( last, prop('date') )(items)
);
@nicoespeon
nicoespeon / dates.json
Last active Apr 11, 2016
Blog - Achieving point-free JavaScript - dates
View dates.json
[
{ "list": "Backlog", "date": "2016-04-01" },
{ "list": "Card Preparation [2]", "date": "2016-04-01" },
{ "list": "Production [3]", "date": "2016-04-02" },
{ "list": "Tests QA [2]", "date": "2016-04-05" },
{ "list": "Mise en live [1]", "date": "2016-04-05" },
{ "list": "In Production", "date": "2016-04-06" },
{ "list": "Live (April 2016)", "date": "2016-04-08" }
]
@nicoespeon
nicoespeon / introducing-point-free-style.js
Last active Apr 11, 2016
Blog - Achieving point-free JavaScript - introducing point-free style programming
View introducing-point-free-style.js
// From https://github.com/MostlyAdequate/mostly-adequate-guide/blob/master/ch5.md#pointfree
// Not point-free because we mention the data: name
let initials = (name) => name.split(' ').map(compose(toUpperCase, head)).join('. ');
// Point-free style
let initials = compose(
join('. '),
map(compose(toUpperCase, head)),
split(' ')
@nicoespeon
nicoespeon / behavior-test.js
Created Mar 23, 2016
Blog - Testing Marionette.js Behaviors - behavior test factory with context
View behavior-test.js
function addOnClickTests ( context ) {
let model, view, behavior, options;
beforeEach( () => {
model = new context.ModelClass();
view = new context.ViewClass( { model: model } );
// Retrieve instantiated behavior and its actual options under this context.
behavior = _.findWhere( view._behaviors, { id: "addOnClick" } );
@nicoespeon
nicoespeon / view-test.js
Created Mar 23, 2016
Blog - Testing Marionette.js Behaviors - use behavior test factory
View view-test.js
describe( "Like View", () => {
const View = LikeView.extend( { template: _.template( "" ) } );
describe( "AddOnClick Behavior", () => {
addOnClickTests( { ViewClass: View, ModelClass: LikeModel } );
} );
@nicoespeon
nicoespeon / behavior-test.js
Created Mar 23, 2016
Blog - Testing Marionette.js Behaviors - behavior test factory
View behavior-test.js
function addOnClickTests ( context ) {
let model, view;
beforeEach( () => {
model = new context.ModelClass();
view = new context.ViewClass( { model: model } );
} );
it( "should increase the model size by 1 when we click on the view", () => {
You can’t perform that action at this time.