import {maybe} from'fox-fantasy';
const {Just, Nothing} = maybe;
constisNumber=n=>typeof n ==='number';
constisNumberMaybe=n=>isNumber(n) ?Just(n) :Nothing();
constresult=isNumberMaybe(5)
//use map or compose
.map(number=> number +5)
//option is to unfold Just or Nothing and return value//it takes one arugment//if it fails, it is gonna return this arugment
.option(0)
//result = 10console.log(result)
import {curry} from'fox-fantasy'constaddNumbers= (a,b,c,d) => a + b + c + d;
constcurryAddNumbers=curry(addNumbers);
//result = 10console.log(
curryAddNumbers(1)(2,3)(4)
)
import {compose,pipe} from'fox-fantasy'conststring='sung'consttoUpper=str=>str.toUpperCase();
constscream=str=>`${str}!`//result = SUNG!constresult=compose(
scream,
toUpper //toUpper will trigger first
)(string)
//result = SUNG!constresult=pipe(
scream, //scream will trigger first
toUpper
)(string)
//safe//succes => Just()//fail => Nothing()const {safe} ='fox-fantasy';
constisNum=n=>typeof n ==='number';
constsafeNumber=safe(isNum, 5)
//result 10
safeNumber
.map(x=> x +5)
.option(0)
const {prop} ='fox-fantasy';
//prop === safe(isnotUndefined, value)constmockData= {
user:'user1',
age:70,
job:'python developer'
}
//checking whether there is age or notconstpropForMockData=prop('age', mockData)
constresult=propForMockData.option('age is not a key')
//result = 70console.log(
result
)
//checking whether there is age or notconstpropForMockData=prop('pet', mockData)
constresult=propForMockData.option('pet is not a key')
//result = 'pet is not a key'console.log(
result
)