Open ryota-ka opened 4 years ago
I second this. I've worked a little bit with Ramda before but the TypeScript support is not ideal. I moved to fp-ts and I'm missing a few functions, for example, dropLeft<string>(n: number)(s: string)
to remove the first n
chars from string s
.
I'll keep an eye here so I can help with pull-requests, since I've written a few of these modules for my personal use already.
Looks like there's a strong consecutive demand from the community for some standard lib. AFAIK a standard place for the helpers is fp-ts-contrib
but it doesn't follow any structure.
At the moment I'm definitely against of including such stdlib into fp-ts
core (I may be wrong though) because it blurs the boundaries and bloats API.
@gcanti Looks like we need a centralised and consistent solution.
related #1138 #1136
@filipekiss - I see your second and raise you a third.
A number of stdlib methods either throw errors, perform i/o, or have "invalid" type states (think InvalidDate, NaN etc).
I suggest we look at global types, and define fp-ts typeclasses like Ord, Eq, etc for them, then add well typed, functional methods based on their prototype (ie: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) for each.
// String.ts
export type Character = string & { length: 1 }
export const ordString = ...
export const eqString = ...
export const string = { ... }
export const charAt = (x: number): Option<Character> => ...
@christianbradley that would be an amazing improvement!
If a verdict is reached as to where a module like this would go, be in fp-ts or somewhere else, I'll be happy to do some of this.
I've created this repo: https://github.com/samhh/fp-ts-std
The idea is that it'll be something in-between Ramda for fp-ts and a wrapper around unsafe JS APIs.
Contributions welcome! :slightly_smiling_face:
🚀 Feature request
I wonder if it's nice if there were support for primitive types, namely something like
fp-ts/lib/number
orfp-ts/lib/string
. Or is it simply out of scope of this project?Current Behavior
boolean.ts
exists, onlyfold
function is defined.Array.ts
andDate.ts
can also be regarded as JavaScript built-in types.Desired Behavior
Having
number.ts
and/orstring.ts
Suggested Solution
Adding
number.ts
and/orstring.ts
with accompanying functions. Enrichingboolean.ts
.Who does this impact? Who is this for?
All users.
Describe alternatives you've considered
Mark them as out of scope.
Additional context
Nowadays it's believed that it's a bad manners to extend prototypes. Providing compositional (pipeable) utility functions from this package can be a great benefit for all FPers.
Your environment