I wonder if it's nice if there were support for primitive types, namely something like fp-ts/lib/number or fp-ts/lib/string.
Or is it simply out of scope of this project?
boolean.ts exists, only fold function is defined.
Array.ts and Date.ts can also be regarded as JavaScript built-in types.
Having number.ts and/or string.ts
Adding number.ts and/or string.ts with accompanying functions.
Enriching boolean.ts.
All users.
Mark them as out of scope.
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.
| Software | Version(s) |
| ---------- | ---------- |
| fp-ts | 2.5.0 |
| TypeScript | - |
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:
Most helpful comment
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: