question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

S.apFirst and S.apSecond

See original GitHub issue

Does it make sense to provide the following two functions?

S.maybeFirst returns the first Maybe value only if both arguments are Just, otherwise return Nothing.

S.maybeFirst :: Maybe a -> Maybe b -> Maybe a
> S.maybeFirst(S.Nothing(), S.Nothing())
Nothing()

> S.maybeFirst(S.Just(1), S.Nothing())
Nothing()

> S.maybeFirst(S.Just(1), S.Just('2'))
Just(1)

S.maybeSecond returns the second Maybe value only if both arguments are Just, otherwise return Nothing.

S.maybeSecond :: Maybe a -> Maybe b -> Maybe b
> S.maybeSecond(S.Nothing(), S.Nothing())
Nothing()

> S.maybeSecond(S.Just(1), S.Nothing())
Nothing()

> S.maybeSecond(S.Just(1), S.Just('2'))
Just('2')

Or the above functions can be made by composing existing sanctuary functions? Please advice 😃

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
safarelicommented, Nov 1, 2016

something like this shuold do the trick

const maybeFirst = first = lift2(a => _ => a)
const maybeSecond = second = lift2(_ => a => a)
2reactions
safarelicommented, Nov 3, 2016

apFirst apSecond sounds good, we could also add same for ‘>>’ and ‘<<’ as chain… Maybe they could be decleared in s-type-classes?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the parser-ts.parser.apFirst function in parser-ts | Snyk
To help you get started, we've selected a few parser-ts.parser.apFirst examples, based on popular ways it is used in public projects.
Read more >
StateReaderObservableEither.ts - fp-ts-rxjs
Apply a function to an argument under a type constructor. Signature. export declare const ap: <S, ...
Read more >
tree-shaking-test fp-ts build output · GitHub
s = function(n) {. return "function" == typeof n.promap;. } ... S.alt,. S.ap,. S.apFirst,. S.apSecond,. S.chain,. S.chainFirst,. S.duplicate,. S.extend,.
Read more >
fp-ts - UNPKG
32, export interface StateReaderTaskEither<S, R, E, A> {. 33, (s: S): ... R, E, (a: A) => B>) => StateReaderTaskEither<S, R, E, B>,...
Read more >
Arithmetic Progression (AP) - Formula, nth Term, Sum, Examples
The sum of first n terms of an arithmetic progression when the n th term is NOT known is S ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found