百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

sanctuary-maybe

> 编程语言
开源

:rainbow: 符合 Fantasy Land 的可能类型

100 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

:rainbow: 符合 Fantasy Land 的可能类型

sanctuary-maybe

The Maybe type represents optional values: a value of type Maybe a is either Nothing (the empty value) or a Just whose value is of type a.

Maybe a satisfies the following Fantasy Land specifications:

…

Maybe :: TypeRep Maybe

Maybe type representative.

Maybe.Nothing :: Maybe a

The empty value of type Maybe a.

javascript
> Nothing
Nothing

Maybe.Just :: a -⁠> Maybe a

Constructs a value of type Maybe a from a value of type a.

javascript
> Just (42)
Just (42)

Maybe.fantasy-land/empty :: () -⁠> Maybe a

  • empty (Maybe) is equivalent to Nothing
javascript
> S.empty (Maybe)
Nothing

Maybe.fantasy-land/of :: a -⁠> Maybe a

  • of (Maybe) (x) is equivalent to Just (x)
javascript
> S.of (Maybe) (42)
Just (42)

Maybe.fantasy-land/chainRec :: ((a -⁠> c, b -⁠> c, a) -⁠> Maybe c, a) -⁠> Maybe b

javascript
> Z.chainRec (
.   Maybe,
.   (next, done, x) =>
.     x = 1000 ? done (x) : next (x * x)),
.   1
. )
Nothing

> Z.chainRec (
.   Maybe,
.   (next, done, x) =>
.     x = 1000 ? done (x) : next (x * x)),
.   2
. )
Just (65536)

Maybe.fantasy-land/zero :: () -⁠> Maybe a

  • zero (Maybe) is equivalent to Nothing
javascript
> S.zero (Maybe)
Nothing

Maybe#@@show :: Showable a => Maybe a ~> () -⁠> String

  • show (Nothing) is equivalent to 'Nothing'
  • show (Just (x)) is equivalent to 'Just (' + show (x) + ')'
javascript
> show (Nothing)
'Nothing'

> show (Just (['foo', 'bar', 'baz']))
'Just (["foo", "bar", "baz"])'

Maybe#fantasy-land/equals :: Setoid a => Maybe a ~> Maybe a -⁠> Boolean

  • Nothing is equal to Nothing
  • Just (x) is equal to Just (y) iff x is equal to y according to Z.equals
  • Nothing is never equal to Just (x)
javascript
> S.equals (Nothing) (Nothing)
true

> S.equals (Just ([1, 2, 3])) (Just ([1, 2, 3]))
true

> S.equals (Just ([1, 2, 3])) (Just ([3, 2, 1]))
false

> S.equals (Just ([1, 2, 3])) (Nothing)
false

Maybe#fantasy-land/lte :: Ord a => Maybe a ~> Maybe a -⁠> Boolean

  • Nothing is (less than or) equal to Nothing
  • Just (x) is less than or equal to Just (y) iff x is less than or equal to y according to Z.lte
  • Nothing is always less than Just (x)
javascript
> S.filter (S.lte (Nothing)) ([Nothing, Just (0), Just (1), Just (2)])
[Nothing]

> S.filter (S.lte (Just (1))) ([Nothing, Just (0), Just (1), Just (2)])
[Nothing, Just (0), Just (1)]

Maybe#fantasy-land/concat :: Semigroup a => Maybe a ~> Maybe a -⁠> Maybe a

  • concat (Nothing) (Nothing) is equivalent to Nothing
  • concat (Just (x)) (Just (y)) is equivalent to Just (concat (x) (y))
  • concat (Nothing) (Just (x)) is equivalent to Just (x)
  • concat (Just (x)) (Nothing) is equivalent to Just (x)
javascript
> S.concat (Nothing) (Nothing)
Nothing

> S.concat (Just ([1, 2, 3])) (Just ([4, 5, 6]))
Just ([1, 2, 3, 4, 5, 6])

> S.concat (Nothing) (Just ([1, 2, 3]))
Just ([1, 2, 3])

> S.concat (Just ([1, 2, 3])) (Nothing)
Just ([1, 2, 3])

Maybe#fantasy-land/filter :: Maybe a ~> (a -⁠> Boolean) -⁠> Maybe a

  • filter (p) (Nothing) is equivalent to Nothing
  • filter (p) (Just (x)) is equivalent to p (x) ? Just (x) : Nothing
javascript
> S.filter (isFinite) (Nothing)
Nothing

> S.filter (isFinite) (Just (Infinity))
Nothing

> S.filter (isFinite) (Just (Number.MAX_SAFE_INTEGER))
Just (9007199254740991)

Maybe#fantasy-land/map :: Maybe a ~> (a -⁠> b) -⁠> Maybe b

  • map (f) (Nothing) is equivalent to Nothing
  • map (f) (Just (x)) is equivalent to Just (f (x))
javascript
> S.map (Math.sqrt) (Nothing)
Nothing

> S.map (Math.sqrt) (Just (9))
Just (3)

Maybe#fantasy-land/ap :: Maybe a ~> Maybe (a -⁠> b) -⁠> Maybe b

  • ap (Nothing) (Nothing) is equivalent to Nothing
  • ap (Nothing) (Just (x)) is equivalent to Nothing
  • ap (Just (f)) (Nothing) is equivalent to Nothing
  • ap (Just (f)) (Just (x)) is equivalent to Just (f (x))
javascript
> S.ap (Nothing) (Nothing)
Nothing

> S.ap (Nothing) (Just (9))
Nothing

> S.ap (Just (Math.sqrt)) (Nothing)
Nothing

> S.ap (Just (Math.sqrt)) (Just (9))
Just (3)

Maybe#fantasy-land/chain :: Maybe a ~> (a -⁠> Maybe b) -⁠> Maybe b

  • chain (f) (Nothing) is equivalent to Nothing
  • chain (f) (Just (x)) is equivalent to f (x)
javascript
> const head = xs => xs.length === 0 ? Nothing : Just (xs[0])

> S.chain (head) (Nothing)
Nothing

> S.chain (head) (Just ([]))
Nothing

> S.chain (head) (Just (['foo', 'bar', 'baz']))
Just ('foo')

Maybe#fantasy-land/alt :: Maybe a ~> Maybe a -⁠> Maybe a

  • alt (Nothing) (Nothing) is equivalent to Nothing
  • alt (Just (x)) (Nothing) is equivalent to Just (x)
  • alt (Nothing) (Just (x)) is equivalent to Just (x)
  • alt (Just (y)) (Just (x)) is equivalent to Just (x)
javascript
> S.alt (Nothing) (Nothing)
Nothing

> S.alt (Just (1)) (Nothing)
Just (1)

> S.alt (Nothing) (Just (2))
Just (2)

> S.alt (Just (4)) (Just (3))
Just (3)

Maybe#fantasy-land/reduce :: Maybe a ~> ((b, a) -⁠> b, b) -⁠> b

  • reduce (f) (x) (Nothing) is equivalent to x
  • reduce (f) (x) (Just (y)) is equivalent to f (x) (y)
javascript
> S.reduce (S.concat) ('abc') (Nothing)
'abc'

> S.reduce (S.concat) ('abc') (Just ('xyz'))
'abcxyz'

Maybe#fantasy-land/traverse :: Applicative f => Maybe a ~> (TypeRep f, a -⁠> f b) -⁠> f (Maybe b)

  • traverse (A) (f) (Nothing) is equivalent to of (A) (Nothing)
  • traverse (A) (f) (Just (x)) is equivalent to map (Just) (f (x))
javascript
> S.traverse (Array) (S.words) (Nothing)
[Nothing]

> S.traverse (Array) (S.words) (Just ('foo bar baz'))
[Just ('foo'), Just ('bar'), Just ('baz')]

Maybe#fantasy-land/extend :: Maybe a ~> (Maybe a -⁠> b) -⁠> Maybe b

  • extend (f) (Nothing) is equivalent to Nothing
  • extend (f) (Just (x)) is equivalent to Just (f (Just (x)))
javascript
> S.extend (S.reduce (S.add) (1)) (Nothing)
Nothing

> S.extend (S.reduce (S.add) (1)) (Just (99))
Just (100)

Issues· 1 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptfantasy-landsanctuary

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言