This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Split where | |
import Prelude | |
import Data.Foldable (fold) | |
import Effect (Effect) | |
import Effect.Console(log) | |
import Effect.Unsafe | |
import Type.Proxy | |
import Prim.Symbol as Symbol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module UseConfig where | |
import Data.Symbol (class IsSymbol, reflectSymbol) | |
import Effect (Effect) | |
import Foreign (F, Foreign) | |
import Prelude | |
import Split (class SplitOnPeriodWrap) -- [code here](https://gist.github.com/imsaravana369/bbc01f20bef24b6f4f97a365c6bb0410) | |
import Type.Proxy (Proxy(..)) | |
import Control.Monad.Except (runExcept) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
-- To Try in trypurescript editor : https://shorturl.at/ghqw9 | |
import Prelude | |
import Effect | |
import Effect.Aff.Retry | |
import Effect.Aff | |
import Data.Time.Duration(Seconds(..)) | |
import Data.Newtype(wrap) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Validation.Semigroup | |
type Person = {name :: String, age :: Int, email :: String} | |
validateName :: String -> V (Array String) String | |
validateName name = if null name | |
then invalid ["Name shouldn't be empty"] | |
else pure name | |
validateAge :: Int -> V (Array String) Int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Just a simple example to understand how JS object is decoded to purescript record. | |
// Skipping unwrapSingleArguments, unwrapSingleConstructors, sumEncoding. | |
purescript_obj = { "firstName" : "Saravana", "lastName" : "Murugesan"} | |
foreign_obj = { "first_name" : "Saravana", "last_name" : "Murugesan"} | |
const camelToSnakeCase = str => str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`); | |
function decode(foreign_obj , res,options){ | |
if (typeof res === 'object'){ // just a generalization |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Prelude | |
import Effect (Effect) | |
import Effect.Console (logShow) | |
import Control.Monad.ST.Internal(ST,for,while,foreach,new,run,write,read,modify) | |
import Data.Array((..)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solve(self, A): | |
A.append(0) | |
n = len(A) | |
res = 0 | |
x = 1 | |
for i in range(1,n): | |
res += x*A[i] | |
x+=1 | |
x = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dog{ | |
String name; | |
Dog(this.name); | |
} | |
class Labrador extends Dog{ | |
Labrador(String name):super(name); | |
} | |
class Doberman extends Dog{ | |
Doberman(String name):super(name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
String jsonString = r'{"name":"Saravanan","age":20}'; | |
Map<String,dynamic> jsonMap = json.decode(jsonString); | |
Person p = Person.fromJson(jsonMap); | |
print("${p.name}, ${p.age}"); //prints Saravanan, 20 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
late final String name; | |
late final int age; | |
Person(this.name,this.age); | |
Person.fromJson(Map<String,dynamic> json){ | |
this.name = json['name']; | |
this.age = json['age'] as int; | |
} | |
} |