ऊंचा Oncha
A modular exalted javascript monadic library & functional fun. fantasy-land compliant.
Install
yarn add oncha
Types
Name | Apply | Applicative | Setoid | Semigroup | Foldable | Functor | Monad | Chain |
---|---|---|---|---|---|---|---|---|
Either | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ✔︎ | |
Future | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ✔︎ | |||
Identity | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ✔︎ | |
Maybe | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ✔︎ | |
List | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ✔︎ |
- There is a divergence form fantasy land where
reduce
is namedfold
for some types.
All
These functions are available on all types.
ap
chain :: (a -> b) -> b
//=> Id(5) // You can use chain to join the monads.//=> Id(5)
equals
equals :: Id -> Boolean
//=> true //=> false === //=> false
chain
chain :: (a -> b) -> b
//=> Id(5) // You can use chain to join the monads.//=> Id(5)
map
map :: (a -> b) -> Id of b
//=> Id(14)
of
of :: a -> Id of a
//=> Id(6) //=> Id(Id(6))
inspect
inspect :: () -> String
//=> Id(5)
Id
Identity monad.
//=> 34
fold
fold :: (a -> b) -> b
//=> 5 //=> 6
Maybe
Maybe monad.
// Maybe of a string//=> 'HELLO EXALTED ONE!'// Maybe of nothing//=> 'Maybe received a null'
else
Sets the value to fold on.
else :: Any -> Nothing of Any
//=> 1 //=> 5
fold
fold :: (a -> b) -> b
//=> 5 //=> 6
Either
An Either monad includes cond, fromCond, fromNullable, Left, Right.
const Left Right fromNullable = EitherEither // this will return a Right('Hello')//=> 'Hello world!'Either // this will return a Left(null)//=> 'Oops'const extractEmail = objemail ? :
cond
A -> B -> C -> Any
Evaluates A when truly calls C if it is a function or return C, when falsely calls B if it is a function or returns B.
cond :: (() -> Boolean) -> (() -> c) -> (() -> d) -> c | d
cond :: (() -> Boolean) -> c -> d -> c | d
cond :: Boolean -> b -> c -> b | c
Either01//=> 1 Either01//=> 1 Either 0 1//=> 1 Either 01//=> 1
fromCond
A -> B -> C -> Either
Evaluates A when truly return Right of C or Left or B.
fromCond :: (() -> Boolean) -> a -> b -> Either
fromCond :: Boolean -> a -> b -> Either
Either01//=> Right(1) Either01//=> Right(1) Either 0 1//=> Right(1) Either 01//=> Right(1)
fold
Foldable - Folds on the first function for Left
and the second for Right
.
fold :: (a -> a, b -> b) -> a | b
//=> 7 //=> 6
List
List Monad.
//=> [8, 12]
head
tail
nth
concat
lenght
every
filter
includes
indexOf
inspect
join
lastIndexOf
map
reduce
reduceRight
reverse
slice
some
Future
A Future monad for async computation.
// Basic usage//=> 'YAY'// Handle promisesFuture//=> 'Cat of the day: Garfield'// Chain http callsFuture//=> 'Facts for cat of the day: Garfield is awesome.'
all
Forks all the futures.
all :: ([Futures]) -> b
Futureall Future Future
fold
fold :: (a -> b) -> b
Future//=> 5 Future//=> 6
fork
Executes the Future
returning a Future
of the resuts.
fork :: (a -> a, b -> b) -> Future of a | b
//=> Future of 5 //=> Future of Error
Higher Order
Compose
Compose takes n functions as arguments and return a function.
const transform =const logTransform =//=> 'HELLO EXALTED ONE!'// supports miltiple arguments'./exalted' '/one'//=> './exalted/one'
Curry
Creates a partially applicable function.
const curried =6//=> 181 2 3//=> 6
Fork
Fork as partial application and first class.
const fut = Futurebfut//=> 'EXALTED!'
Map
Map as partial application and first class with arity support.
1 2 3//=> [4, 7, 10]