Git Product home page Git Product logo

fp-ts-ramda's Introduction

(WIP!) fp-ts-ramda

Some Ramda functions reimplemented using fp-ts.

Since the question "how do I implement x from Ramda in fp-ts" comes up pretty often

Contribution guidelines

Each function should:

  • be API compatible with the original Ramda function (as far as possible, see below)
  • come with a property-based test to verify such compatibility (see other tests as an example)
  • be typesafe (or even improve on the status of @types/ramda, if possible)
  • come with a few typelevel tests (see other tests as an example)
  • be non deprecated in Ramda

More specific notes regarding implementation choices

[TODO] API compatibility with Ramda

For some Ramda functions, 100% API compatibility is easy to obtain. For others (typically the ones relying on instances of some typeclass), it's difficult or nearly impossible without compromising type-safety.

Currying

All Ramda functions are "auto curried". Since an objective is to remain mostly API-compatible, translations must be curried too.

Each function should have a series of TS overloads making all the possible combinations of parameters well-typed, and be implemented using manual currying: see for instance adjust.ts. Manual currying is preferred in order to avoid compromising perf, but might be revisited in the future.

Out of scope

A few things I haven't considered up to now and/or not sure how to handle:

  • the R.__ placeholder
  • "Acts as a transducer if a transformer is given..."
  • "Dispatches to the X method of argument, if present."

fp-ts-ramda's People

Contributors

erjanmx avatar gcanti avatar giogonzo avatar kightlingerh avatar kutyel avatar mfirry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fp-ts-ramda's Issues

Question: allPass

How do you want to go about allPass? I am by no means an expert in fp-ts, but I'm struggling to find a reasonable implementation which makes me tempted to go this route:

function _allPass <T>(funs: Array<Predicate<T>>, val: T): boolean { return funs.every(fun => fun(val)); }

implement ifElse

Hi! now that I'm back to typescript, I'm willing to learn fp-ts but I miss some functions from ramda too much ๐Ÿ˜ญ, how would ifElse be implemented? Thanks!

current status of porting

Here's a list of all the Ramda functions and their current status in this repo.

For each function, I added some notes on how they could be mapped in fp-ts terms taken from https://github.com/gcanti/fp-ts/blob/master/docs/recipes/ramda.md

We could use this issue to coordinate between multiple people on the ongoing effort in porting the entire API (or part of it)

Function Implemented Owners Notes, mapping in fp-ts
__ out of scope
add โœ… @kightlingerh see fp-ts's Field
addIndex
adjust โœ… @giogonzo
all โœ… @kightlingerh
allPass โœ… @kightlingerh
always โœ… @giogonzo
and โœ… @giogonzo
any โœ… @kightlingerh
anyPass โœ… @kightlingerh
ap At the core it's just fpTsInstance.ap
aperture
append โœ… @giogonzo
apply should map to apply from fp-ts/lib/function
applySpec
applyTo โœ… @giogonzo
ascend should map to Ord.contramap
assoc โœ… @kightlingerh
assocPath
binary
bind
both
call
chain At the core it's just fpTsInstance.chain
clamp โœ… @giogonzo
clone
comparator should map to Ord.fromCompare
complement
compose should map to function.compose
composeWith
concat see fp-ts's Semigroup
cond
construct
constructN
converge
countBy
curry should map to function.curry
curryN
dec should map to function.decrement
defaultTo โœ… @giogonzo
descend see Ord.contramap, Ord.getDualOrd
difference
differenceWith
dissoc see Record.remove
dissocPath
divide see fp-ts's Field
drop should map to Array.drop
dropLast should map to Array.dropEnd
dropLastWhile
dropRepeats
dropRepeatsWith
dropWhile should map to Array.dropWhile
either
empty
endsWith โœ… @mfirry Implemented for arrays only (not strings)
eqBy see Eq.contramap
eqProps
equals โœ… @kightlingerh see Eq
evolve
F should map to function.constFalse
filter see Filterable
find Array.find
findIndex Array.findIndex
findLast Array.findLast
findLastIndex Array.findLastIndex
flatten Array.flatten
flip function.flip
forEach
forEachObjIndexed
fromPairs โœ… @giogonzo
groupBy NonEmptyArray.groupBy
groupWith see NonEmptyArray.group, NonEmptyArray.groupSort
gt Ord.greaterThan
gte Ord.greaterThanOrEq
has Record.member
hasIn
hasPath
head Array.head
identical see Eq
identity function.identity
ifElse
inc function.increment
includes
indexBy see NonEmptyArray.groupBy
indexOf Array.findIndex
init Array.init
innerJoin
insert Array.insertAt
insertAll
intersection
intersperse
into
invert
invertObj
invoker
is
isEmpty
isNil
join
juxt
keys Record.keys
keysIn
last Array.last
lastIndexOf Array.findLastIndex
length
lens should use monocle-ts lib
lensIndex should use monocle-ts lib
lensPath should use monocle-ts lib
lensProp should use monocle-ts lib
lift
liftN
lt Ord.lessThan
lte Ord.lessThanOrEq
map At the core it's just fpTsInstance.map
mapAccum
mapAccumRight
mapObjIndexed
match
mathMod
max Ord.max
maxBy
mean
median
memoizeWith
mergeDeepLeft
mergeDeepRight
mergeDeepWith
mergeDeepWithKey
mergeLeft
mergeRight
mergeWith see Record.getMonoid
mergeWithKey
min Ord.min
minBy
modulo
move
multiply see Field
nAry
negate Ring.negate
none
not
nth Array.index
nthArg
o
objOf โœ… @kightlingerh Record.singleton
of array.of
omit
once
or see Semigroup.semigroupAny
otherwise
over should use monocle-ts lib
pair function.tuple
partial
partialRight
partition see Filterable
path should use monocle-ts lib
pathEq
pathOr
pathSatisfies
pick
pickAll
pickBy
pipe function.pipe
pipeWith
pluck
prepend Array.cons
product see Foldable.product
project
prop โœ… @kightlingerh uses monocle-ts
propEq
propIs
propOr
props
propSatisfies
range Array.range
reduce
reduceBy
reduced
reduceRight
reduceWhile
reject
remove
repeat Array.replicate
replace
reverse Array.reverse
scan Array.scanLeft
sequence see Traversable in fp-ts
set should use monocle-ts lib
slice
sort
sortBy
sortWith
split
splitAt Array.split
splitEvery @mfirry Array.chunksOf
splitWhen
startsWith
subtract see Ring
sum
symmetricDifference
symmetricDifferenceWith
T function.constTrue
tail Array.takeWhile
take Array.take
takeLast โœ… @mfirry, @gcanti Implemented for arrays only (not strings)
takeLastWhile
takeWhile Array.takeWhile
tap
test
then
thunkify
times Array.makeBy
toLower
toPairs โœ… @giogonzo
toPairsIn
toString
toUpper
transduce
transpose
traverse see Traversable
trim
tryCatch IOEither.tryCatch
type
unapply
unary
uncurryN
unfold
union
unionWith
uniq Array.uniq
uniqBy Array.uniq
uniqWith
unless
unnest see Chain.flatten
until
update Array.unsafeUpdateAt
useWith
values see Record.toArray
valuesIn
view should use monocle-ts lib
when
where
whereEq
without
xprod โœ… @giogonzo
zip Array.zip
zipObj
zipWith Array.zipWith

endsWith implementation

I've tried a simple definition along these lines:

import { takeLast } from './takeLast'

export function endsWith<A>(suffix: Array<A>): (list: Array<A>) => boolean;
export function endsWith<A>(suffix: Array<A>, list: Array<A>): boolean;
export function endsWith<A>(suffix: Array<A>, list?: Array<A>): any {
  if (list === undefined) {
    return function(list: Array<A>) {
      return endsWith(suffix, list);
    };
  } else {
    return takeLast(suffix.length, list) === suffix;
  }
}

(also lurking on https://github.com/ramda/ramda/blob/v0.26.1/source/endsWith.js#L27)
But it doesn't seem to work.
Any hint?

License

Any chance you can add a license to the repo?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.