Dec. 30th, 2023

juan_gandhi: (Default)

 Тут во Франции с 1 января запретят въезд имамов-иноагентов (т.е. тех, кому государства типа Марокко и Алжир платят за пропаганду). Хотите имама на рамадан? Платите сами.

Смешно, конечно. Если б кто меня спрашивал, я б вообще...

 

 

juan_gandhi: (Default)
// Definitions for Boolean Logic
const True = x => y => x
const False = x => y => y
const Bool = b => b ? True : False

// Definitions for pair and projection
const p1 = x => y => x // did you notice? It's True
const p2 = x => y => y // did you notice? It's False
const Pair = x => y => f => f(x)(y)

// Option constructors and operations
const None = Pair(True)("None")
const Some = x => Pair(False)(x)
const isEmpty = x => x(p1)
const FlatMap = x => f => isEmpty(x) (None) ( f(x(p2)))
const Map = x => f => isEmpty(x) (None) (Some(f(x(p2))))
const Filter = x => p => isEmpty(x) (None) (p(x(p2)) (x) (None))

// visualizer
const show = text => xOpt => {
Map(xOpt)(x => println(text + x))
}

// samples
show("Expecting Some ")(Some(42))
show("Expecting None ")(None)

const isPositive = x => Bool(x > 0)
show("0 positive? ")(Filter(Some(0))(isPositive))
show("2 positive? ")(Filter(Some(2))(isPositive))

const dec = n => n > 10 ? Some(n-10) : None

show("expecting None from None: ")(FlatMap( None)(dec))
show("expecting None from 5: ") (FlatMap(Some(5) )(dec))
show("expecting 32 from 42: ") (FlatMap(Some(42))(dec))

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

September 2025

S M T W T F S
 1 2345 6
78 9 10 111213
14 151617 181920
212223 24252627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 29th, 2025 04:14 am
Powered by Dreamwidth Studios