Skip to content

Instantly share code, notes, and snippets.

View gvergnaud's full-sized avatar
🚀

Gabriel Vergnaud gvergnaud

🚀
View GitHub Profile
import { compose, curry, map } from 'ramda'
import Const, { getConst } from './functors/Const'
import Identity, { runIdentity } from './functors/Identity'
import K from './functors/K'
/* ----------------------------------------- *
Lenses définition
* ----------------------------------------- */
export default class Const {
constructor(v) {
this.value = v
}
static of(v) {
return new Const(v)
}
export default class Identity {
constructor(v) {
this.value = v
}
static of(v) {
return new Identity(v)
}
/* ----------------------------------------- *
Learning Machin Learning
* ----------------------------------------- */
// gradientDescent for the square error function and a Theta of Two parameter (a, b)
// Theta :: [Number, Number]
// sum :: (a -> Int) -> List a -> Int
const sum = (transformer, list) =>
list.reduce((acc, item) => acc + transformer(item), 0)
/* ----------------------------------------- *
Learning Machin Learning
* ----------------------------------------- */
import { compose, map, chain, range } from 'ramda'
// Result = { a :: Int, b :: Int, cost :: Number }
// Data = [Int, Int]
// Tupple = [Int, Int]
// findBestResult :: [Result] -> Result
/* ----------------------------------------- *
Learning Machin Learning
* ----------------------------------------- */
// gradientDescent of the square error function for a Theta of any number of
// parameters
// multiplyVectors :: List number -> List number -> number
const multiplyVectors = (xs, ys) =>
xs.reduce((acc, x, i) => acc + x * ys[i], 0)
/* ------------------------------------------------------------------------- *
Async / Await simple implementation with generators and promises
* -------------------------------------------------------------------------- */
const wrap = generator => (...args) => {
const iterator = generator(...args)
const loop = ({ value: promise, done }) => {
if (!done) {
promise.then(
x => loop(iterator.next(x)),

Prez React

récuperer le react transform boilerplate. => workflow hot swaping trop cool ;)

git clone https://github.com/gvergnaud/prez-react.git TutoReact
npm install
npm start

déclarer un Composant React :

import React, { Component } from 'react'
import isEqual from 'lodash/fp/isEqual'
// let you inject local state to you component
const stateful = (mapPropsToInitialState = () => ({})) => Child => {
return class StateFul extends Component {
static displayName = `StateFul(${Child.displayName || Child.name})`
/* ----------------------------------------- *
Sum
* ----------------------------------------- */
const Sum = x => ({
x,
concat: ({ x: y }) => Sum(x + y),
inspect: () => `Sum(${x})`,
})