Skip to content

Instantly share code, notes, and snippets.

@pawndev
Created June 28, 2018 20:58
Show Gist options
  • Save pawndev/4d2b76400c855bc1bf87d16a26d5289e to your computer and use it in GitHub Desktop.
Save pawndev/4d2b76400c855bc1bf87d16a26d5289e to your computer and use it in GitHub Desktop.
test sanctuary
import {create, env, Maybe} from 'sanctuary';
const S = create({
checkTypes: true,
env
});
// PART - I
// const first_arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
// const first_elem = S.head(first_arr);
// console.log(first_elem);
// PART - II
class Job {
name: string;
constructor(name: string) {
this.name = name;
}
}
interface User {
name: string,
age: number,
job:Job
}
const users = [
{
name: "Bob",
age: 18,
job: new Job("Javascript Autist")
},
{
name: "Boulou",
age: 14,
job: new Job("Javascript Fanatic")
},
{
name: "Chris",
age: 22,
job: new Job("Real Developper")
}
];
const getJob = (user: User) => user.job;
const getJobName = (job: Job) => job.name;
const all_job = S.map(getJob)(users);
const all_job_name = S.map(getJobName)(all_job);
console.log(all_job_name);
{
"name": "sancturary",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon -e ts --exec \"npm start\"",
"start": "tsc && node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"sanctuary": "^0.15.0",
"typescript": "^2.9.2"
},
"devDependencies": {
"@types/sanctuary": "^0.14.2",
"nodemon": "^1.17.5",
"ts-node": "^7.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment