{"size": 711, "ext": "js", "max_stars_repo_path": "JavaScript/Archive/fmap.js", "max_stars_repo_name": "SergeyOcheretenko/PythonLearning", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "JavaScript/Archive/fmap.js", "max_issues_repo_name": "SergeyOcheretenko/PythonLearning", "max_issues_repo_issues_event_min_datetime": "2021-12-27T18:27:57.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-20T15:11:38.000Z", "max_forks_repo_path": "JavaScript/Archive/fmap.js", "max_forks_repo_name": "SergeyOcheretenko/PythonLearning", "max_forks_repo_forks_event_min_datetime": "2022-02-21T18:20:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-21T18:20:54.000Z"}
{"max_stars_count": null, "max_issues_count": 6, "max_forks_count": 1, "avg_line_length": 20.9117647059, "max_line_length": 53, "alphanum_fraction": 0.5879043601}
'use strict';

const sequence = (start = 0, step = 1) => {
	let cache = [start];
	return function(){
		let len = cache.length;
		cache.push(cache[len - 1] + step);
		return cache[len - 1];
	};
}

function fmap(fn, generator){
	if (generator.length === 0){
		return () => fn(generator());
	} else{
		return (...args) => fn(generator.apply(this, args))
	}
}

const square = x => x ** 2;
const add = (a, b) => a + b;

const gen = sequence(1, 1);

const squareGen = fmap(square, gen);

console.log(squareGen()); // 1
console.log(squareGen()); // 4
console.log(squareGen()); // 9

const squareAdd = fmap(square, add);
console.log(squareAdd(1, 2)); // 9 = (1 + 2) ^ 2
console.log(squareAdd(3, 5)); // 64 = (3 + ) ^ 2
