Skip to content

Commit

Permalink
Add Tuple support: _1, _2
Browse files Browse the repository at this point in the history
  • Loading branch information
toastal committed Dec 17, 2021
1 parent 9bd7fa6 commit db63fcc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
**Note**: Gaps between patch versions are faulty/broken releases. **Note**: A feature tagged as Experimental is in a
high state of flux, you're at risk of it changing without notice.

# 2.4.0

- **New Feature**
- `Tuple`
- add `_1` constructor (@toastal)
- add `_2` constructor (@toastal)

# 2.3.11

- **Bug Fix**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monocle-ts",
"version": "2.3.11",
"version": "2.4.0",
"description": "A porting of scala monocle library to TypeScript",
"main": "lib/index.js",
"module": "es6/index.js",
Expand Down
23 changes: 23 additions & 0 deletions src/Tuple.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @since 2.4.0
*/
import { fst, snd, map, mapLeft } from 'fp-ts/lib/Tuple'
import { Lens } from '.'

// TODO on fp-ts upgrade: mapLeft → mapFst
const one = new Lens<[any, any], any>(fst, (x) => mapLeft(() => x))

/**
* @category constructor
* @since 2.4.0
*/
export const _1 = <A, B>(): Lens<[A, B], A> => one

// TODO on fp-ts upgrade: map → mapSnd
const two = new Lens<[any, any], any>(snd, (y) => map(() => y))

/**
* @category constructor
* @since 2.4.0
*/
export const _2 = <A, B>(): Lens<[A, B], B> => two

0 comments on commit db63fcc

Please sign in to comment.