Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Do notation pipes for functions which easy to mock

NotificationsYou must be signed in to change notification settings

darky/klubok-gleam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Package VersionHex DocsErlang-compatibleJavaScript-compatible

logo

Do notation pipes for functions which easy to mock
Inspired by fp-ts/Effect bind Do-notation, but much more small and simple
Primarly created for easy mocking of functions, which allows to write tons of unit tests

gleam add klubok_gleam
importgleam/option.{None,Some}importgleam/setimportklubok_gleam.{use_klubok2,eff}typeCat{Cat(name:String,age:Int)}fncat_birthday(mock,only){// Make this function pipable// Need to use correct arity by count of `eff` usage, 2 in this exampleuse<-use_klubok2(mock,only)// This function mockableusecat<-eff(fn(){// some IO implementation which fetching catCat("Barsik",5)})// This function mockableuseaged_cat<-eff(fn(){Cat(..cat,age:cat.age+1)})aged_cat}pubfnmain(){// Pass Option.None to mock and only// Should be used on production codecat_birthday(None,None)// Cat("Barsik", 6)// Mock first `eff` with another hardcoded cat// Should be used in unit testscat_birthday(#(fn(){Cat("Marfa",10)}|>Some,None)|>Some,None)// Cat("Marfa", 11)// Call only second `eff` and first IO ignored// Also our birthday fn is mocked and our cat is kiten again//❗`only` is type unsafe and can lead to runtime errors when `Nil` passed instead of actual `eff` valuecat_birthday(#(None,fn(){Cat("Barsik",1)}|>Some)|>Some,set.from_list([1])|>Some)// Cat("Barsik", 1)}

Further documentation can be found athttps://hexdocs.pm/klubok_gleam.

Development

gleam run# Run the projectgleamtest# Run the tests

See also

  • Klubok - TS implementation of Klubok

About

Do notation pipes for functions which easy to mock

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp